Example usage for org.openqa.selenium StaleElementReferenceException StaleElementReferenceException

List of usage examples for org.openqa.selenium StaleElementReferenceException StaleElementReferenceException

Introduction

In this page you can find the example usage for org.openqa.selenium StaleElementReferenceException StaleElementReferenceException.

Prototype

public StaleElementReferenceException(String message) 

Source Link

Usage

From source file:com.cognifide.qa.bb.scope.CurrentScopeHelperTest.java

License:Apache License

@Test
public void shouldReturnFalseWhenCurrentScopeIsStale() {
    //given//from   w ww.  j  av a 2 s  .  c o  m
    pageObjectWithCurrentScope = new PageObjectWithCurrentScope(webElement);
    when(webElement.isDisplayed()).thenThrow(new StaleElementReferenceException("Expected exception"));

    //when
    boolean actual = testedObject.isCurrentScopeVisible(pageObjectWithCurrentScope);

    //then
    verifyIsDisplayedCalledOnce();
    assertFalse(actual);
}

From source file:com.cognifide.qa.bb.scope.CurrentScopeHelperTest.java

License:Apache License

@Test
public void shouldReturnFalseWhenCurrentScopeIsNotPresent() {
    //given/* w  ww . jav a2 s .  c om*/
    pageObjectWithCurrentScope = new PageObjectWithCurrentScope(webElement);
    when(webElement.isDisplayed()).thenThrow(new StaleElementReferenceException("Expected exception"));

    //when
    boolean actual = testedObject.isCurrentScopeVisible(pageObjectWithCurrentScope);

    //then
    verifyIsDisplayedCalledOnce();
    assertFalse(actual);
}

From source file:com.easytox.automation.steps.LabClientImpl.java

@Then("^New lab client is added successfully and newly added lab client is listed in the Lab Client List screen$")
public void check_added_lab_client() throws InterruptedException {
    if (count == 0) {
        WebElement el = MyWebDriverUtils.findElement(driver, DROP_DOWN_SELECT_LOCATOR, LocatorType.CSS);
        if (el != null) {
            new Select(el).selectByVisibleText(DROP_DOWN_ALL_VALUE);
        }/*w ww  .ja  v  a2s.  c o m*/

    }

    try {
        count++;
        final WebElement table = MyWebDriverUtils.findElement(driver, TABLE_LOCATOR, LocatorType.ID);
        if (table != null) {

            List<WebElement> listRows = MyWebDriverUtils.findElements(driver, ROWS_LOCATOR, LocatorType.TAG,
                    table);
            if (listRows != null) {
                int size = listRows.size();
                List<WebElement> listCells = MyWebDriverUtils.findElements(driver, CELL_LOCATOR,
                        LocatorType.TAG, listRows.get(size - 1));

                if (listCells != null && listCells.size() == 9) {
                    Assert.assertEquals(listCells.get(2).getText(), CITY_VALUE);
                    Assert.assertEquals(listCells.get(3).getText(), STATE_VALUE);
                    Assert.assertEquals(listCells.get(4).getText(), ZIP_VALUE);
                    Assert.assertEquals(listCells.get(5).getText(), CONTACT_PERSON_VALUE);
                    Assert.assertEquals(listCells.get(6).getText(), CONTACT_NUMBER_REAL_VALUE);
                    Assert.assertEquals(listCells.get(7).getText(), CONTACT_EMAIL_VALUE);
                } else {
                    throw new StaleElementReferenceException("listCells size is not equal 9");
                }

            } else {
                Assert.fail("listRows is null!");
            }
        } else {
            Assert.fail("table is null!");
        }
    } catch (StaleElementReferenceException ex) {
        check_added_lab_client();
    }
    WebElement el = MyWebDriverUtils.findPresenceElement(driver, SUCCESS_LOCATOR, LocatorType.CSS);
    if (el != null) {
        String elValue = el.getText();
        Assert.assertEquals(elValue, SUCCESS_VALUE);
        count = 0;
    } else {
        Assert.fail("el is false!");
    }
}

From source file:com.easytox.automation.steps.LabClientImpl.java

@When("^Click '\\+' icon against newly created lab client$")
public void click_plus_icon_against_newly_created_lab_clients() {
    try {//from  w  w  w  . ja v a  2 s .com
        final WebElement table = MyWebDriverUtils.findElement(driver, TABLE_LOCATOR, LocatorType.ID);
        if (table != null) {

            List<WebElement> listRows = MyWebDriverUtils.findElements(driver, ROWS_LOCATOR, LocatorType.TAG,
                    table);
            if (listRows != null) {
                int size = listRows.size();
                List<WebElement> listCells = MyWebDriverUtils.findElements(driver, CELL_LOCATOR,
                        LocatorType.TAG, listRows.get(size - 1));

                if (listCells != null && listCells.size() == 9) {
                    WebElement el = listCells.get(0);
                    WebDriverWait wait = new WebDriverWait(driver, TIME_OUT_IN_SECONDS);

                    boolean flag = MyWebDriverUtils.waitInvisibilityOfElement(wait, CONTAINER_LOCATOR,
                            LocatorType.ID);
                    if (flag) {
                        checkAndClick(el);
                    } else {
                        Assert.fail("flag is false!");
                    }
                } else {
                    throw new StaleElementReferenceException("listCells size is not equal 9");
                }

            } else {
                Assert.fail("listRows is null!");
            }
        } else {
            Assert.fail("table is null!");
        }
    } catch (StaleElementReferenceException ex) {
        click_plus_icon_against_newly_created_lab_clients();
    }
}

From source file:com.easytox.automation.steps.LabClientImpl.java

@Then("^Following values should be populated: Address - it should populate entered Address lines 1 and 2 Lab - it should populate Lab name$")
public void check_populate_fields() {
    try {/*from  w  ww. ja va2 s  . c o m*/
        final WebElement table = MyWebDriverUtils.findElement(driver, TABLE_LOCATOR, LocatorType.ID);
        if (table != null) {
            List<WebElement> listRows = MyWebDriverUtils.findElements(driver, ROWS_LOCATOR, LocatorType.TAG,
                    table);
            if (listRows != null) {
                int size = listRows.size();
                List<WebElement> listCells = MyWebDriverUtils.findElements(driver, CELL_LOCATOR,
                        LocatorType.TAG, listRows.get(size - 1));

                if (listCells != null && listCells.size() == 2) {
                    WebElement labCell = listCells.get(1);
                    Assert.assertEquals(labCell.getText(), LAB_CLIENT_VALUE);

                } else {
                    throw new StaleElementReferenceException("listCells size is not equal 2");
                }

                List<WebElement> addressCells = MyWebDriverUtils.findElements(driver, CELL_LOCATOR,
                        LocatorType.TAG, listRows.get(size - 2));

                if (addressCells != null && addressCells.size() == 2) {
                    WebElement addressCell = addressCells.get(1);
                    String[] address = addressCell.getText().split(REGEX);
                    Assert.assertEquals(address[0], ADDRESS_1_VALUE);
                    Assert.assertEquals(address[1], ADDRESS_2_VALUE);

                } else {
                    throw new StaleElementReferenceException("addressCells size is not equal 2");
                }

            } else {
                Assert.fail("listRows is null!");
            }
        } else {
            Assert.fail("table is null!");
        }
    } catch (StaleElementReferenceException ex) {
        check_populate_fields();
    }
}

From source file:com.easytox.automation.steps.LabClientImpl.java

@When("^Click '\\+' icon against updated lab client$")
public void click_plus_icon_against_updated_lab_client() {
    final WebElement table = MyWebDriverUtils.findElement(driver, TABLE_LOCATOR, LocatorType.ID);
    if (table != null) {

        List<WebElement> listRows = MyWebDriverUtils.findElements(driver, ROWS_LOCATOR, LocatorType.TAG, table);
        if (listRows != null) {
            List<WebElement> listCells = MyWebDriverUtils.findElements(driver, CELL_LOCATOR, LocatorType.TAG,
                    listRows.get(1));/*from  ww w .  j a  v  a2 s  .  co  m*/

            if (listCells != null && listCells.size() == 9) {
                WebElement el = listCells.get(0);
                WebDriverWait wait = new WebDriverWait(driver, TIME_OUT_IN_SECONDS);

                boolean flag = MyWebDriverUtils.waitInvisibilityOfElement(wait, CONTAINER_LOCATOR,
                        LocatorType.ID);
                if (flag) {
                    checkAndClick(el);
                } else {
                    Assert.fail("flag is false!");
                }
            } else {
                throw new StaleElementReferenceException("listCells size is not equal 9");
            }

        } else {
            Assert.fail("listRows is null!");
        }
    } else {
        Assert.fail("table is null!");
    }
}

From source file:com.easytox.automation.steps.LabClientImpl.java

@Then("^Following values should be updated with changed data: Address - it should populate entered Address lines 1 and 2 Lab - it should populate Lab name$")
public void check_updated_data() {
    try {//from   ww  w .  jav a2  s.c  o  m
        final WebElement table = MyWebDriverUtils.findElement(driver, TABLE_LOCATOR, LocatorType.ID);
        if (table != null) {
            List<WebElement> listRows = MyWebDriverUtils.findElements(driver, ROWS_LOCATOR, LocatorType.TAG,
                    table);
            if (listRows != null) {
                List<WebElement> listCells = MyWebDriverUtils.findElements(driver, CELL_LOCATOR,
                        LocatorType.TAG, listRows.get(4));

                if (listCells != null && listCells.size() == 2) {
                    WebElement labCell = listCells.get(1);
                    Assert.assertEquals(labCell.getText(), LAB_CLIENT_VALUE);

                } else {
                    throw new StaleElementReferenceException("listCells size is not equal 2");
                }

                List<WebElement> addressCells = MyWebDriverUtils.findElements(driver, CELL_LOCATOR,
                        LocatorType.TAG, listRows.get(3));

                if (addressCells != null && addressCells.size() == 2) {
                    WebElement addressCell = addressCells.get(1);
                    String[] address = addressCell.getText().split(REGEX);
                    Assert.assertEquals(address[0], ADDRESS_1_VALUE);
                    Assert.assertEquals(address[1], ADDRESS_2_VALUE);

                } else {
                    throw new StaleElementReferenceException("addressCells size is not equal 2");
                }

            } else {
                Assert.fail("listRows is null!");
            }
        } else {
            Assert.fail("table is null!");
        }
    } catch (StaleElementReferenceException ex) {
        check_updated_data();
    }
}

From source file:com.easytox.automation.steps.LabClientImpl.java

@Then("^Added location should be added to the Location list$")
public void added_location_should_be_added_to_the_location_list() {
    if (count == 0) {
        WebElement el = MyWebDriverUtils.findElement(driver, DROP_DOWN_SELECT_LOCATOR, LocatorType.CSS);
        if (el != null) {
            new Select(el).selectByVisibleText(DROP_DOWN_ALL_VALUE);
        }/*from ww w  . j a v  a2  s  . co  m*/
    }

    try {
        count++;
        final WebElement table = MyWebDriverUtils.findElement(driver, TABLE_LOCATOR, LocatorType.ID);
        if (table != null) {

            List<WebElement> listRows = MyWebDriverUtils.findElements(driver, ROWS_LOCATOR, LocatorType.TAG,
                    table);
            if (listRows != null) {
                int size = listRows.size();
                List<WebElement> listCells = MyWebDriverUtils.findElements(driver, CELL_LOCATOR,
                        LocatorType.TAG, listRows.get(size - 1));

                if (listCells != null && listCells.size() == 5) {
                    Assert.assertEquals(listCells.get(0).getText(), LAB_LOCATION_NAME_VALUE);
                    Assert.assertEquals(listCells.get(1).getText(), LAB_LOCATION_ADDRESS_VALUE);
                    Assert.assertEquals(listCells.get(2).getText(), LAB_LOCATION_DEPARTMENT_VALUE);
                    Assert.assertEquals(listCells.get(3).getText(), LAB_CLIENT_ANOTHER_VALUE);
                } else {
                    throw new StaleElementReferenceException("listCells size is not equal 5");
                }

            } else {
                Assert.fail("listRows is null!");
            }
        } else {
            Assert.fail("table is null!");
        }
    } catch (StaleElementReferenceException ex) {
        added_location_should_be_added_to_the_location_list();
    }
    WebElement el = MyWebDriverUtils.findPresenceElement(driver, SUCCESS_LOCATOR, LocatorType.CSS);
    if (el != null) {
        String elValue = el.getText();
        Assert.assertEquals(elValue, SUCCESS_VALUE);
        count = 0;
    } else {
        Assert.fail("el is false!");
    }

    String currentUrl = driver.getCurrentUrl();
    Assert.assertEquals(currentUrl, SAVE_LOCATION_URL);

    WebElement success = MyWebDriverUtils.findPresenceElement(driver, SUCCESS_LOCATOR, LocatorType.CSS);
    if (success != null) {
        String elValue = success.getText();
        Assert.assertEquals(elValue, SUCCESS_VALUE);
    } else {
        Assert.fail("el is false!");
    }

    WebElement widget = MyWebDriverUtils.findPresenceElement(driver, WIDGET_LAB_LOCATION_LIST_LOCATOR,
            LocatorType.CSS);
    if (widget != null) {
        String title = widget.getText();
        Assert.assertEquals(title, WIDGET_LAB_LOCATION_LIST_VALUE);
    }

}

From source file:com.easytox.automation.steps.LabClientImpl.java

@Then("^Lab location should be updated successfully$")
public void lab_location_should_be_updated_successfully() {
    try {// ww  w  . j  a  v  a 2s.  co m
        final WebElement table = MyWebDriverUtils.findElement(driver, TABLE_LOCATOR, LocatorType.ID);
        if (table != null) {

            List<WebElement> listRows = MyWebDriverUtils.findElements(driver, ROWS_LOCATOR, LocatorType.TAG,
                    table);
            if (listRows != null) {
                int size = listRows.size();
                List<WebElement> listCells = MyWebDriverUtils.findElements(driver, CELL_LOCATOR,
                        LocatorType.TAG, listRows.get(size - 1));

                if (listCells != null && listCells.size() == 5) {
                    Assert.assertEquals(listCells.get(0).getText(), LAB_LOCATION_NAME_VALUE);
                    Assert.assertEquals(listCells.get(1).getText(), LAB_LOCATION_ADDRESS_VALUE);
                    Assert.assertEquals(listCells.get(2).getText(), LAB_LOCATION_DEPARTMENT_VALUE);

                    String currentUrl = driver.getCurrentUrl();
                    Assert.assertEquals(currentUrl, UPDATE_SUCCESS_URL);

                    WebElement widget = MyWebDriverUtils.findPresenceElement(driver, SUCCESS_LOCATOR,
                            LocatorType.CSS);
                    if (widget != null) {
                        String title = widget.getText();
                        Assert.assertEquals(title, SUCCESS_VALUE);
                    }
                } else {
                    throw new StaleElementReferenceException("listCells size is not equal 5");
                }

            } else {
                Assert.fail("listRows is null!");
            }
        } else {
            Assert.fail("table is null!");
        }
    } catch (StaleElementReferenceException ex) {
        lab_location_should_be_updated_successfully();
    }

}

From source file:com.easytox.automation.steps.LabClientImpl.java

@Then("^Added user should be added to the Lab Client User list$")
public void added_user_should_be_added_to_the_lab_client_user_list() {
    if (count == 0) {
        WebElement el = MyWebDriverUtils.findPresenceElement(driver, DROP_DOWN_SELECT_LOCATOR, LocatorType.CSS);
        if (el != null) {
            new Select(el).selectByVisibleText(DROP_DOWN_ALL_VALUE);
        } else {/*from  w  w  w  .ja  va  2  s.  co m*/
            Assert.fail("el is null!");
        }

    }

    try {
        count++;
        final WebElement table = MyWebDriverUtils.findElement(driver, TABLE_LOCATOR, LocatorType.ID);
        if (table != null) {

            List<WebElement> listRows = MyWebDriverUtils.findElements(driver, ROWS_LOCATOR, LocatorType.TAG,
                    table);
            if (listRows != null) {
                int size = listRows.size();
                List<WebElement> listCells = MyWebDriverUtils.findElements(driver, CELL_LOCATOR,
                        LocatorType.TAG, listRows.get(size - 1));

                if (listCells != null && listCells.size() == 8) {
                    Assert.assertEquals(listCells.get(1).getText(), userNameValue);
                    Assert.assertEquals(listCells.get(2).getText(),
                            USER_FIRST_NAME_VALUE + " " + USER_LAST_NAME_VALUE);
                    Assert.assertEquals(listCells.get(3).getText(), USER_CONTACT);
                    Assert.assertEquals(listCells.get(4).getText(), USER_EMAIL_VALUE);
                    Assert.assertEquals(listCells.get(5).getText(), ROLE);
                    Assert.assertEquals(listCells.get(6).getText(), LAB_CLIENT_ANOTHER_VALUE);

                    String currentUrl = driver.getCurrentUrl();
                    Assert.assertEquals(currentUrl, CLIENT_USER_LIST_URL);

                    WebElement widget = MyWebDriverUtils.findPresenceElement(driver, SUCCESS_LOCATOR,
                            LocatorType.CSS);
                    if (widget != null) {
                        String title = widget.getText();
                        Assert.assertEquals(title, SUCCESS_VALUE);
                    }
                    count = 0;
                } else {
                    throw new StaleElementReferenceException("listCells size is not equal 8");
                }

            } else {
                Assert.fail("listRows is null!");
            }
        } else {
            Assert.fail("table is null!");
        }
    } catch (StaleElementReferenceException ex) {
        added_user_should_be_added_to_the_lab_client_user_list();
    }
}