Example usage for org.openqa.selenium WebElement getText

List of usage examples for org.openqa.selenium WebElement getText

Introduction

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

Prototype

String getText();

Source Link

Document

Get the visible (i.e.

Usage

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);
        }/* w ww. j a va2  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 List page should be displayed$")
public void lab_location_list_page_should_be_displayed() {
    String currentUrl = driver.getCurrentUrl();
    Assert.assertEquals(currentUrl, LAB_LOCATION_LIST_URL);

    WebElement widget = MyWebDriverUtils.findPresenceElement(driver, WIDGET_LAB_LOCATION_LIST_ANOTHER_LOCATOR,
            LocatorType.CSS);/* w ww.  j av  a 2 s. co  m*/
    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("^Update Lab location page should be displayed$")
public void update_lab_location_page_should_be_displayed() {
    String currentUrl = driver.getCurrentUrl();
    Assert.assertEquals(currentUrl, EDIT_LAB_LOCATION_LIST_URL);

    WebElement widget = MyWebDriverUtils.findPresenceElement(driver, WIDGET_UPDATE_LOCATION_LOCATOR,
            LocatorType.CSS);/*w w w  .  j av  a2s  .  c o  m*/
    if (widget != null) {
        String title = widget.getText();
        Assert.assertEquals(title, WIDGET_UPDATE_LOCATION_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 {//  w ww  .  ja va  2 s.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("^Add Lab Client User page should be displayed$")
public void add_lab_client_user_page_should_be_displayed() {
    String currentUrl = driver.getCurrentUrl();
    Assert.assertEquals(currentUrl, ADD_LAB_CLIENT_USER_URL);

    WebElement widget = MyWebDriverUtils.findPresenceElement(driver, WIDGET_ADD_LOCATOR, LocatorType.CSS);
    if (widget != null) {
        String title = widget.getText();
        Assert.assertEquals(title, WIDGET_ADD_LAB_CLIENT_USER_VALUE);
    }//w  w  w. ja v a  2s.  c  om
}

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 {/*  ww w .j a v  a  2 s  .c  o 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();
    }
}

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

@Then("^User List page should be displayed$")
public void user_list_page_should_be_displayed() {
    String currentUrl = driver.getCurrentUrl();
    Assert.assertEquals(currentUrl, USER_LIST_PAGE_URL);

    WebElement el = MyWebDriverUtils.findPresenceElement(driver, WIDGET_USER_LIST_LOCATOR, LocatorType.CSS);
    if (el != null) {
        String title = el.getText();
        Assert.assertEquals(title, WIDGET_USER_LIST_VALUE);
    }//from   www .  ja  v a 2s  .  co  m
}

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

@Then("^Update Lab User page should be displayed$")
public void update_lab_user_page_should_be_displayed() {
    String currentUrl = driver.getCurrentUrl();
    Assert.assertEquals(currentUrl, UPDATE_LAB_USER_PAGE_URL);

    WebElement el = MyWebDriverUtils.findPresenceElement(driver, WIDGET_UPDATE_LOCATOR, LocatorType.CSS);
    if (el != null) {
        String title = el.getText();
        Assert.assertEquals(title, WIDGET_UPDATE_LAB_USER_VALUE);
    }/*  ww  w. j av a  2  s  .  co m*/
}

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

@Then("^Changes made to personal information should be saved successfully$")
public void changes_made_to_personal_information_should_be_saved_successfully() {
    try {/*from ww  w.j  a v 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(1));

                if (listCells != null && listCells.size() == 8) {
                    Assert.assertEquals(listCells.get(1).getText(), CLIENT_USER_NAME);
                    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_USERS_LIST_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 8");
                }

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

}

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

@Then("^Following values should be populated with updated information: Modified By Modified Date\\(with Timestamp\\)$")
public void values_should_be_populated_with_updated_information() {
    try {/*ww w  . j a 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) {
                List<WebElement> listCells = MyWebDriverUtils.findElements(driver, CELL_LOCATOR,
                        LocatorType.TAG, listRows.get(4));
                String dataCreated;
                String dataModified;

                if (listCells != null && listCells.size() == 2) {
                    WebElement dataCell = listCells.get(1);
                    dataCreated = dataCell.getText();
                    Assert.assertNotNull(dataCreated);

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

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

                if (lstCells != null && lstCells.size() == 2) {
                    WebElement dataCell = lstCells.get(1);
                    dataModified = dataCell.getText();
                    Assert.assertNotNull(dataModified);
                } else {
                    throw new StaleElementReferenceException("addressCells size is not equal 2");
                }

                Assert.assertTrue(dataModified.compareTo(dataCreated) > 0);

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