Example usage for org.openqa.selenium WebElement isDisplayed

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

Introduction

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

Prototype

boolean isDisplayed();

Source Link

Document

Is this element displayed or not?

Usage

From source file:com.moodle.testmanager.pageObjectModel.PassFailAssertions.java

License:GNU General Public License

/**
 * Asserts that an element does not appear onscreen when located by css selector. The selector is passed from the page object.
 * @param cssSelector The CSS locator which is passed by the page object.
 * @param exceptionMessage The Exception Message which is passed by the page object.
 * @throws Exception Throws an exception with the text from the Exception Message parameter.
 *//* ww w . ja va 2  s. c o m*/
public void assertItemNotOnscreenByCSSSelector(String cssSelector, String exceptionMessage, int timeToWait)
        throws Exception {
    boolean itemVisible = false;
    try {
        driver.manage().timeouts().implicitlyWait(timeToWait, TimeUnit.SECONDS);
        WebElement onscreenElement = driver.findElement(By.cssSelector(cssSelector));
        itemVisible = onscreenElement.isDisplayed();
    } catch (NoSuchElementException ex) {
    }
    if (itemVisible) {
        throw new Exception(exceptionMessage);
    }
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}

From source file:com.moodle.testmanager.pageObjectModel.PassFailAssertions.java

License:GNU General Public License

/**
 * Asserts that an element is present onscreen by xpath
 * @param forumName The name of the forum, the value of which is passed from the page object.
 * @param exceptionMessage The text to appear in the exception message, the value of which is passed from the forum.
 * @throws Exception Throws an exception with the text from the Exception Message parameter.
 *//*from  www .j  a v  a 2s .  c  o m*/
public void assertElementIsPresentByXpath(String xpathLocator, String exceptionMessage, int timeToWait)
        throws Exception {
    boolean itemVisible = false;
    try {
        driver.manage().timeouts().implicitlyWait(timeToWait, TimeUnit.SECONDS);
        WebElement onscreenElement = driver.findElement(By.xpath(xpathLocator));
        itemVisible = onscreenElement.isDisplayed();
    } catch (NoSuchElementException ex) {
    }
    if (itemVisible) {
    } else {
        throw new Exception(exceptionMessage);
    }
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

From source file:com.moodle.testmanager.pageObjectModel.PassFailAssertions.java

License:GNU General Public License

/**
 * Asserts that an element, located by Xpath, is not present onscreen.
 * @param xpath A valid xpath to the locator
 * @param exceptionMessage The exception message that is thrown when the element is present on the screen.
 * @param timeToWait The number of seconds that you want to wait for the element to be displayed onscreen. A higher value can be useful if the page loading times are long or another page is temporarily displayed first.
 * @throws Exception Throws an exception if the xpath element can be located.
 *//*w ww. j a  va  2 s  . c  o  m*/
public void assertElementIsNotPresentByXpath(String xpath, String exceptionMessage, int timeToWait)
        throws Exception {
    boolean itemVisible = false;
    try {
        driver.manage().timeouts().implicitlyWait(timeToWait, TimeUnit.SECONDS);
        WebElement onscreenElement = driver.findElement(By.xpath(xpath));
        itemVisible = onscreenElement.isDisplayed();
    } catch (NoSuchElementException ex) {
    }
    if (itemVisible) {
        throw new Exception(exceptionMessage);
    }
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}

From source file:com.moodle.testmanager.pageObjectModel.PluginsManageEditors.java

License:GNU General Public License

/**
 * Clicks Disable if it is enabled and vice versa.
 * @param locName The value for name from each table row that you want to interact with.
 *///from   w w w.  jav a  2  s.com
private void clickEnableDisable(String locName) {
    boolean itemVisible = false;
    try {
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
        WebElement e = driver.findElementByXPath(".//tr[contains(.,'" + locName + "')]/*/a/img[@alt='"
                + this.properties.get("locDisable") + "']");
        itemVisible = e.isDisplayed();
    } catch (NoSuchElementException ex) {
    }
    ;
    if (itemVisible) {
        WebElement e = driver.findElementByXPath(".//tr[contains(.,'" + locName + "')]/*/a/img[@alt='"
                + this.properties.get("locDisable") + "']");
        e.click();
    } else {
        WebElement e = driver.findElementByXPath(".//tr[contains(.,'" + locName + "')]/*/a/img[@alt='"
                + this.properties.get("locEnable") + "']");
        e.click();
    }
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

From source file:com.moodle.testmanager.pageObjectModel.UsersEnrolled.java

License:GNU General Public License

/**
 * Click the enrol button adjacent to the user to enrol based upon a concatenation of the First Name and Surname.
 * @param userToEnrolFirstName The text value for the users first name, the value is passed from the test.
 * @param userToEnrolSurname The text value for the users surname, the value is passed from the test.
 *//* www  . ja v a  2 s.com*/
public void selectUserToEnrol(String userToEnrolFirstName, String userToEnrolSurname) {
    boolean itemVisible = false;
    try {
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
        WebElement e = driver.findElement(By.xpath("//div[contains(.,'" + userToEnrolFirstName + " "
                + userToEnrolSurname + "')]/*/input[@value='" + this.properties.get("buttonEnrol") + "']"));
        itemVisible = e.isDisplayed();
    } catch (NoSuchElementException ex) {
    }
    if (itemVisible) {
        WebElement enrolButtonUserContext = driver
                .findElement(By.xpath("//div[contains(.,'" + userToEnrolFirstName + " " + userToEnrolSurname
                        + "')]/*/input[@value='" + this.properties.get("buttonEnrol") + "']"));
        enrolButtonUserContext.click();
    } else {
        WebElement potentialUser = driver
                .findElement(By.xpath(".//*[@id='addselect']/optgroup/option[contains(.,'"
                        + userToEnrolFirstName + " " + userToEnrolSurname + "')]"));
        potentialUser.click();
    }
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}

From source file:com.moodle.testmanager.pageObjectModel.UsersEnrolled.java

License:GNU General Public License

/**
 * Clicks the finish enrolling button.//w  ww .j  av  a2 s.  c  o  m
 */
public void clickFinishEnrollingButton() {
    boolean itemVisible = false;
    try {
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
        WebElement finishEnrollingUsersButton = driver
                .findElement(By.cssSelector("input[value='Finish enrolling users']"));
        itemVisible = finishEnrollingUsersButton.isDisplayed();
    } catch (NoSuchElementException ex) {
    }
    if (itemVisible) {
        WebElement finishEnrollingUsersButton = driver
                .findElement(By.cssSelector("input[value='Finish enrolling users']"));
        finishEnrollingUsersButton.click();
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    } else {
        WebElement addButton = driver.findElement(By.id("add"));
        addButton.click();
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    }
}

From source file:com.novartis.opensource.yada.test.YADAAdminTest.java

License:Apache License

/**
 * Tests splash screen//from  w  ww  . jav  a 2  s.  co m
 */
@Test(priority = 0)
public void testLandingPage() {
    WebDriver d = getDriver();
    for (WebElement e : d.findElement(By.tagName("nav")).findElements(By.cssSelector("li a"))) {
        try {
            e.click();
        } catch (WebDriverException e1) {
            l.debug("Navbar unclickable as expected.");
        }
    }
    WebElement e = d.findElement(By.id("app-mgr"));
    Assert.assertFalse(e.isDisplayed());
    e = d.findElement(By.id("query-table"));
    Assert.assertFalse(e.isDisplayed());
    e = d.findElement(By.id("qname-copy"));
    Assert.assertFalse(e.isDisplayed());
    e = d.findElement(By.id("migration-target-selector"));
    Assert.assertFalse(e.isDisplayed());
    e = d.findElement(By.id("query-editor-container"));
    Assert.assertFalse(e.isDisplayed());
    e = d.findElement(By.id("compare"));
    Assert.assertFalse(e.isDisplayed());
    new WebDriverWait(d, 300)
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#login .modal-dialog")));
    Assert.assertFalse(d.findElement(By.id("login-btn")).isEnabled());
}

From source file:com.novartis.opensource.yada.test.YADAAdminTest.java

License:Apache License

/**
 * Test App Manager new app creation/*from   w w  w  .  j  a  va 2 s .co m*/
 * @throws InterruptedException if any thread has interrupted the current thread
 */
@Test(dependsOnMethods = { "testLoginSuccess" })
public void testAppCreation() throws InterruptedException {
    String t = new String(Long.valueOf(new Date().getTime()).toString());
    this.app = "FOO" + t.substring(t.length() < 17 ? 0 : t.length() - 17);
    WebDriver d = getDriver();
    d.findElement(By.id("app-hdr-new")).click();
    Thread.sleep(100);
    Assert.assertTrue(d.findElement(By.id("app-new")).isDisplayed());
    d.findElement(By.id("app-code-new")).sendKeys(this.app);
    d.findElement(By.id("app-active-new")).click();
    d.findElement(By.id("app-name-new")).sendKeys(this.app);
    d.findElement(By.id("app-desc-new")).sendKeys("This is a test of new app functions using app " + this.app);
    StringBuilder conf = new StringBuilder();
    conf.append("jdbcUrl=");
    conf.append(this.dbUrl);
    conf.append("\nusername=");
    conf.append(this.dbUser);
    conf.append("\npassword=");
    conf.append(this.dbPw);
    conf.append("\ndriverClassName=");
    conf.append(this.dbDriver);
    conf.append("\nautoCommit=false");
    conf.append("\nconnectionTimeout=300000");
    conf.append("\nidleTimeout=600000");
    conf.append("\nmaxLifetime=1800000");
    conf.append("\nminimumIdle=5");
    conf.append("\nmaximumPoolSize=100");
    WebElement e = d.findElement(By.id("app-conf-new"));
    e.clear();
    e.sendKeys(conf.toString());
    d.findElement(By.id("app-submit-new")).click();
    e = new WebDriverWait(d, 20)
            .until(ExpectedConditions.presenceOfElementLocated(By.id("app-hdr-" + this.app)));
    Assert.assertTrue(e.isDisplayed());
}

From source file:com.novartis.opensource.yada.test.YADAAdminTest.java

License:Apache License

/**
 * Test App Manager new query for new app (prep only)
 * @throws InterruptedException if any thread has interrupted the current thread
 *///from  w w  w .j av a2  s.c o m
@Test(dependsOnMethods = { "testNewQueryForNewAppCancel" })
public void testNewQueryForNewAppSave() throws InterruptedException {
    String qname = "Test Save";
    this.createQueryForNewApp(qname, "save");
    WebDriver d = getDriver();

    // validate ui
    WebElement e = new WebDriverWait(d, 20)
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".alert-success")));
    String expected = "Hooray! Query " + this.app + " " + qname + " was saved successfully.";
    Assert.assertEquals(e.getText(), expected);
    WebElement save = d.findElement(By.id("button-save"));
    Assert.assertFalse(save.isDisplayed());

    // close dialog
    d.findElement(By.id("button-cancel")).click();
    Thread.sleep(3000);

    // validate query table has rows
    Assert.assertEquals(d.findElements(By.cssSelector("#query-table tbody td.dataTables_empty")).size(), 0);
    List<WebElement> rows = d.findElements(By.cssSelector("#query-table tbody tr[role=\"row\"]"));
    Assert.assertNotEquals(Integer.valueOf(rows.size()), Integer.valueOf(0));

    // validate content of query table
    List<WebElement> cells = d.findElements(By.cssSelector("#query-table tbody tr[role=\"row\"] td"));
    String expectedQname = this.app + " " + qname;
    String expectedComments = "Testing comments".substring(0, 12) + "";
    boolean qnameMatches = false;
    boolean commentsMatches = false;
    for (WebElement cell : cells) {

        if (cell.getText().equals(expectedQname)) {
            qnameMatches = true;
            break;
        }
    }
    for (WebElement cell : cells) {
        if (cell.getText().equals(expectedComments)) {
            commentsMatches = true;
            break;
        }
    }
    Assert.assertTrue(qnameMatches && commentsMatches);
}

From source file:com.novartis.opensource.yada.test.YADAAdminTest.java

License:Apache License

/**
 * Makes assertions about default state of query editor modal
 *///from www  . j  av a 2  s  .c om
private void validateQueryEditor() {
    WebDriver d = getDriver();
    WebElement e = d.findElement(By.id("query-editor-container"));
    Assert.assertTrue(e.isDisplayed());
    List<WebElement> list = d.findElements(By.xpath("//div[contains(@class,\"panel \")]"));
    Assert.assertEquals(list.size(), 3);
    list = d.findElements(By.xpath("//div[contains(@class,\"panel \") and @style=\"display: none;\"]"));
    Assert.assertEquals(list.size(), 2);
    new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.id("collapseOne")));
    Assert.assertTrue(d.findElement(By.id("collapseOne")).isDisplayed()); // comments
    Assert.assertFalse(d.findElement(By.id("collapseTwo")).isDisplayed()); // security
    Assert.assertFalse(d.findElement(By.id("collapseThree")).isDisplayed()); // params

    // validate buttons in footer
    list = d.findElements(
            By.xpath("//div[@id=\"query-editor-container\"]//div[contains(@class,\"modal-footer\")]/button"));
    Assert.assertEquals(list.size(), 5);
    list = d.findElements(By.xpath(
            "//div[@id=\"query-editor-container\"]//div[contains(@class,\"modal-footer\")]/button[@style=\"display: none;\"]"));
    Assert.assertEquals(list.size(), 3);
    Assert.assertTrue(d.findElement(By.id("button-save")).isDisplayed());
    Assert.assertTrue(d.findElement(By.id("button-cancel")).isDisplayed());
    Assert.assertFalse(d.findElement(By.id("button-rename")).isDisplayed());
    Assert.assertFalse(d.findElement(By.id("button-copy")).isDisplayed());
    Assert.assertFalse(d.findElement(By.id("button-delete")).isDisplayed());
}