Example usage for org.openqa.selenium.support.ui ExpectedConditions presenceOfElementLocated

List of usage examples for org.openqa.selenium.support.ui ExpectedConditions presenceOfElementLocated

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui ExpectedConditions presenceOfElementLocated.

Prototype

public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator) 

Source Link

Document

An expectation for checking that an element is present on the DOM of a page.

Usage

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

License:Apache License

/**
 * <ol>//from ww  w .  java  2  s. c o  m
 * <li>Opens the query editor</li>
 * <li>Validates all the buttons are present</li>
 * <li>Opens the security panel</li>
 * <li>Sets URL validation policy</li>
 * <li>Sets TokenValidation policy</li>
 * <li>Sets ExecutionPolicy</li>
 * <li>Sets ContentPolicy</li>
 * </ol>
 * @throws InterruptedException if any thread has interrupted the current thread
 * @throws IOException when the test URL can't be accessed 
 */
@Test(dependsOnMethods = { "testNewQueryForNewAppSave" })
public void testSecurityConfigForQuery() throws InterruptedException, IOException {
    WebDriver d = getDriver();
    String protector = this.app + " Test Protector";
    this.createQueryForNewApp(" Test Protector", "SELECT 1 AS COL1", "save");
    WebElement save = d.findElement(By.id("button-save"));

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

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

    // restore app-mgr
    d.findElement(By.id("app")).click();
    new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.id("app-mgr")));
    Thread.sleep(3000);

    // nav to queries
    d.findElement(By.id("app-qname-" + this.app)).click();
    Thread.sleep(3000);

    // open query for edit
    String qname = this.app + " Test Save";
    d.findElement(By.xpath("//*[text()[contains(.,\"" + qname + "\")]]")).click();
    this.switchToActiveElement(d, 3000);
    new WebDriverWait(d, 20)
            .until(ExpectedConditions.presenceOfElementLocated(By.id("query-editor-container")));

    // validate buttons
    List<WebElement> list = d.findElements(By.cssSelector("#query-editor-container .modal-footer button"));
    Assert.assertEquals(list.size(), 5);
    for (WebElement b : list) {
        Assert.assertTrue(b.isDisplayed() && b.isEnabled());
    }

    // open security panel
    d.findElement(By.id("headingTwo")).click();
    Thread.sleep(3000);

    // Confirm query result
    String result = getUrl(qname);
    l.debug("EXPECT NORMAL RESULT:\n" + result);
    Assert.assertTrue(result.contains(qname) && result.toUpperCase().contains("\"ROWS\":[{\"COL1\":\"1\"}]"));

    // "Mark this query as secure" and confirm "unauth"
    d.findElement(By.id("secure-query-ckbx")).click();
    d.findElement(By.id("button-save")).click();
    Thread.sleep(3000);
    result = getUrl(qname);
    l.debug("EXPECT UNAUTHORIZED RESULT:\n" + result);
    //   should be rejected at this point due to checkbox + lack of plugin
    Assert.assertFalse(result.contains(qname) && result.toUpperCase().contains("\"ROWS\":[{\"COL1\":\"1\"}]"));
    Assert.assertTrue(result.contains("Server returned HTTP response code: 403"));
    d.findElement(By.id("button-cancel")).click(); // back to app-mgr
    Thread.sleep(3000);

    // open query for edit
    e = new WebDriverWait(d, 20).until(ExpectedConditions
            .presenceOfElementLocated(By.xpath("//*[text()[contains(.,\"" + qname + "\")]]")));
    e.click();
    this.switchToActiveElement(d, 3000);
    new WebDriverWait(d, 20)
            .until(ExpectedConditions.presenceOfElementLocated(By.id("query-editor-container")));

    if (!d.findElement(By.id("secure-query-ckbx")).isDisplayed()) {
        d.findElement(By.id("headingTwo")).click();
        Thread.sleep(3000);
    }

    // confirm "Mark this query as not secure"
    d.findElement(By.id("secure-query-ckbx")).click();
    d.findElement(By.id("button-save")).click();
    Thread.sleep(3000);
    result = getUrl(qname);
    l.debug("EXPECT NORMAL RESULT:\n" + result);
    //   should be accepted, as box is unchecked
    Assert.assertTrue(result.contains(qname) && result.toUpperCase().contains("\"ROWS\":[{\"COL1\":\"1\"}]"));
    d.findElement(By.id("button-cancel")).click();
    Thread.sleep(3000);

    // open query for edit
    e = new WebDriverWait(d, 20).until(ExpectedConditions
            .presenceOfElementLocated(By.xpath("//*[text()[contains(.,\"" + qname + "\")]]")));
    e.click();
    this.switchToActiveElement(d, 3000);
    new WebDriverWait(d, 20)
            .until(ExpectedConditions.presenceOfElementLocated(By.id("query-editor-container")));

    if (!d.findElement(By.id("secure-query-ckbx")).isDisplayed()) {
        d.findElement(By.id("headingTwo")).click();
    }
    //    l.debug("Sleeping for 2 minutes to enable manual investigation");
    Thread.sleep(3000);
    // validate all components
    //   what is there before any data entry?

    WebElement plugin = d.findElement(By.className("policy-plugin"));
    WebElement policyArg = d.findElement(By.className("policy-arg"));
    WebElement argString = d.findElement(By.className("arg-string"));

    Assert.assertTrue(d.findElement(By.className("policy-group")).isDisplayed());
    Assert.assertTrue(plugin.isDisplayed());
    Assert.assertTrue(d.findElement(By.className("policy-action")).isDisplayed());
    Assert.assertTrue(argString.isDisplayed());
    Assert.assertTrue(d.findElement(By.className("policy-type")).isDisplayed());
    Assert.assertTrue(policyArg.isDisplayed());
    Assert.assertTrue(d.findElement(By.className("remove-policy")).isDisplayed());

    // enter policies

    //   what is there after each policy entry  
    plugin.sendKeys("Gatekeeper");
    Select policyType = new Select(d.findElement(By.className("policy-type")));
    policyType.selectByVisibleText("URL Pattern Matching");
    policyArg.clear();
    policyArg.sendKeys("auth.path.rx=^(https?://)?localhost:8080/.+$");
    Assert.assertEquals(argString.getText(), "auth.path.rx=^(https?://)?localhost:8080/.+$");

    Select policyAction = new Select(d.findElement(By.className("policy-action")));
    policyAction.selectByValue("save");
    Thread.sleep(2000);
    policyAction.selectByValue("add-same");
    //Thread.sleep(3000);

    String xpath = "//div[contains(@class,\"security-options\")][2]";
    e = new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath)));

    List<WebElement> policies = d.findElements(By.className("security-options"));
    List<WebElement> policyTypes = d.findElements(By.className("policy-type"));
    List<WebElement> policyArgs = d.findElements(By.className("policy-arg"));

    policyType = new Select(policyTypes.get(1));
    policyType.selectByVisibleText("Execution Policy (Indices)");
    policyArgs.get(1).clear();
    policyArgs.get(1).sendKeys("execution.policy.indices=0:getToken()");
    Assert.assertTrue(d.findElement(By.className("policy-protector")).isDisplayed());
    d.findElement(By.className("policy-protector")).sendKeys(protector);

    policyAction.selectByValue("save");
    Thread.sleep(3000);
    policyAction.selectByValue("add-same");
    //Thread.sleep(3000);

    xpath = "//div[contains(@class,\"security-options\")][3]";
    e = new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath)));

    policies = d.findElements(By.className("security-options"));
    policyTypes = d.findElements(By.className("policy-type"));
    policyArgs = d.findElements(By.className("policy-arg"));
    List<WebElement> policyProtectors = d.findElements(By.className("policy-protector"));

    policyType = new Select(policyTypes.get(2));
    policyType.selectByVisibleText("Execution Policy (Columns)");
    policyArgs.get(2).clear();
    policyArgs.get(2).sendKeys("execution.policy.columns=0:getToken()");

    Assert.assertEquals(policyProtectors.size(), 2);
    policyProtectors.get(1).sendKeys(protector);

    policyAction.selectByValue("save");
    Thread.sleep(2000);
    policyAction.selectByValue("add-same");

    xpath = "(//input[contains(@class,\"security-options\")])[3]";
    e = new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath)));

    policies = d.findElements(By.className("security-options"));
    policyTypes = d.findElements(By.className("policy-type"));
    policyArgs = d.findElements(By.className("policy-arg"));
    policyProtectors = d.findElements(By.className("policy-protector"));

    policyType = new Select(policyTypes.get(3));
    policyType.selectByVisibleText("Content Policy");
    policyArgs.get(3).clear();
    policyArgs.get(3).sendKeys("content.policy.predicate=x=y");

    expected = "auth.path.rx=^(https?://)?localhost:8080.+$,execution.policy.indices=0:getToken(),execution.policy.columns=token:getToken(),content.policy.predicate=x=y";
    Assert.assertEquals(argString.getText(), expected);

    // save 
    //   multiple ways to save? (not yet)
    policyAction.selectByValue("save");

    // TODO validate data is in db
    // TODO validate security works? or is this just for a standard integration test?
    // TODO alert user when security setting is invalid or unsavable for any reason
    // TODO alert user to save security settings (this may enable safety net after all)
    // TODO parse security param into UI when appropriate (it currently doesn't) 

    d.findElement(By.id("button-save")).click();
    Thread.sleep(3000);

    d.findElement(By.id("app")).click();
    new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.id("app-mgr")));
    Thread.sleep(3000);

    // nav to queries
    d.findElement(By.id("app-qname-" + this.app)).click();
    Thread.sleep(3000);

    // open query for edit
    d.findElement(By.xpath("//*[text()[contains(.,\"" + qname + "\")]]")).click();
    this.switchToActiveElement(d, 3000);
    new WebDriverWait(d, 20)
            .until(ExpectedConditions.presenceOfElementLocated(By.id("query-editor-container")));

    d.findElement(By.id("headingThree")).click();
    Thread.sleep(3000);
    String actual = d.findElement(By.cssSelector("$('#default-params tbody tr:eq(0) td input:eq(1)')"))
            .getAttribute("value");
    Assert.assertEquals(actual, expected);

}

From source file:com.nowsprinting.hellotesting.appiumtest.appium.page.PreviewPage.java

License:Apache License

/**
 * ???????/* w  w  w . ja  v  a2s  . c  o m*/
 * 
 * @return ?????true??????????false?
 */
public boolean waitUntilLoad() {
    try {
        // WebView?????
        mWait.until(ExpectedConditions.presenceOfElementLocated(By.className("android.webkit.WebView")));
    } catch (TimeoutException e) {
        return false;
    }
    return true;
}

From source file:com.numenta.htmit.mobile.test.behavior.TestUtilities.java

License:Open Source License

public static void waitClick(By locator, WebDriver driver, int value) {
    WebDriverWait wait = new WebDriverWait(driver, value);
    wait.until(ExpectedConditions.presenceOfElementLocated(locator)).click();
}

From source file:com.numenta.htmit.mobile.test.behavior.TestUtilities.java

License:Open Source License

public static String waitGetText(By locator, WebDriver driver, int value) {
    WebDriverWait wait = new WebDriverWait(driver, value);
    return wait.until(ExpectedConditions.presenceOfElementLocated(locator)).getText();
}

From source file:com.opera.core.systems.OperaExtensionsTest.java

License:Apache License

@Test
public void operaExtensionIsInstalled() throws IOException {
    File oexSource = resourceCopy(resources.locate("dummy-extension.oex"));

    settings.profile().addExtension(oexSource);
    TestDriver driver = new TestDriverBuilder().using(settings).get();

    assertNotNull(driver);/*from   w  ww  . j a  v  a  2  s.c o  m*/
    assertTrue("Expected Opera to run", driver.isRunning());
    driver.navigate().to(pages.oex);

    try {
        // The dummy extension sets a HTML attribute on the <html> element.
        By by = By.cssSelector("html[isoexinstalled759='yes']");
        (new WebDriverWait(driver, 2)).until(ExpectedConditions.presenceOfElementLocated(by));
    } catch (TimeoutException e) {
        fail("Custom opera extension not detected!");
    }

    driver.quit();
}

From source file:com.partnet.automation.HtmlView.java

License:Apache License

/**
 * An expectation for checking that an element is present on the DOM of a
 * page. This does not necessarily mean that the element is visible.
 * /* w  w  w  .  j  a  v a2 s . co  m*/
 * @param by locator for the element
 * @param maxWaitInSeconds max seconds to wait for element to appear
 * @return WebElement
 */
protected WebElement waitForPresenceOfElement(By by, int maxWaitInSeconds) {
    return (new WebDriverWait(webDriver, maxWaitInSeconds))
            .until(ExpectedConditions.presenceOfElementLocated(by));
}

From source file:com.pentaho.ctools.cdf.CommentComponent.java

License:Apache License

/**
 * ############################### Test Case 4 ###############################
 *
 * Test Case Name:// ww w  . java 2  s.co m
 *    Display Page
 * Description:
 *    We pretend validate the comments added are listed.
 * Steps:
 *    1. Add one comment
 *    2. Add another comment
 *    3. Add another comment
 */
@Test
public void tc4_AddComponent_CommentIsDisplayed() {
    this.log.info("tc4_AddComponent_CommentIsDisplayed");
    /*
     * Guarantee no comments displayed
     */
    cleanAllComments();

    String smallText = "Remove this comment please";
    String longText = "The policy states that a pre departure beverage should be served to First Class/Envoy Class customers on every flight. Beverages given by flight attendants (including bottles of water) must be collected before or during the walk through before takeoff/landing. Because we have not integrated ALL P/P's between East/West, you may find that the West f/a's collect before closing the a/c door as it was/may still be policy. Reasons short of laziness to not serve? Catering hasn't provided adequate supplies yet. Steady stream of passengers because the flight is way late and the agents have a steady flow of customers line up. Even then, they should try. Short of that, there is NO excuse.";
    String specCharText = "+~~-113334233&#$%66/8&%$53";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);

    /*
     * ## Step 1
     */
    this.elemHelper.ClickJS(driver, By.cssSelector("div.addComment"));
    //After click in add, check if the button add, save and cancel are displayed
    String noComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.comment"));
    assertEquals("No Comments to show!", noComments);
    String addComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.addComment"));
    assertEquals("Add Comment", addComments);
    String cancelComments = this.elemHelper.WaitForElementPresentGetText(driver,
            By.cssSelector("div.cancelComment"));
    assertEquals("Cancel", cancelComments);
    String saveComments = this.elemHelper.WaitForElementPresentGetText(driver,
            By.cssSelector("div.saveComment"));
    assertEquals("Save", saveComments);
    //Insert the text
    this.elemHelper.FindElement(driver, By.cssSelector("textarea.addCommentText")).sendKeys(smallText);
    this.elemHelper.ClickJS(driver, By.cssSelector("div.saveComment"));
    Date timeAddedComment1 = new Date();
    //wait for the page rendered
    wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("div.navigateRefresh")));
    //Check if the comment was added
    String strCommentTimeAdded = "admin, " + sdf.format(timeAddedComment1);
    // Need to remove the last digit of minutes to avoid failing. Because, we 
    // could catch something like 14:22 and the comment was added at 14:21:59
    strCommentTimeAdded = strCommentTimeAdded.substring(0, strCommentTimeAdded.length() - 1);
    String commentDetails1 = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[1]/div"));
    assertThat("Comment added: " + commentDetails1, commentDetails1,
            CoreMatchers.containsString(strCommentTimeAdded));
    String commentAdded1 = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[1]/div[2]/div"));
    assertEquals(commentAdded1, smallText);

    /*
     * ## Step 2
     */
    this.elemHelper.ClickJS(driver, By.cssSelector("div.addComment"));
    //After click in add, check if the button add, save and cancel are displayed
    addComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.addComment"));
    assertEquals("Add Comment", addComments);
    cancelComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.cancelComment"));
    assertEquals("Cancel", cancelComments);
    saveComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.saveComment"));
    assertEquals("Save", saveComments);
    //Insert the text
    this.elemHelper.FindElement(driver, By.cssSelector("textarea.addCommentText")).sendKeys(longText);
    this.elemHelper.ClickJS(driver, By.cssSelector("div.saveComment"));
    Date timeAddedComment2 = new Date();
    //wait for the page rendered (and for the two added comments persist
    wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("div.navigateRefresh")));
    wait.until(
            ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='sampleObject']/div/div/div[1]")));
    wait.until(
            ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='sampleObject']/div/div/div[2]")));
    //Check if the comment was added
    //Comment added 2
    String strCommentTimeAdded2 = "admin, " + sdf.format(timeAddedComment2);
    // Need to remove the last digit of minutes to avoid failing. Because, we 
    // could catch something like 14:22 and the comment was added at 14:21:59
    strCommentTimeAdded2 = strCommentTimeAdded2.substring(0, strCommentTimeAdded2.length() - 1);
    String commentDetails2 = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[1]/div"));
    assertThat("Comment added: " + commentDetails2, commentDetails2,
            CoreMatchers.containsString(strCommentTimeAdded2));
    String commentAdded2 = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[1]/div[2]/div"));
    assertEquals(commentAdded2, longText);
    //Comment added 1
    commentDetails1 = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[2]/div"));
    assertThat("Comment added: " + commentDetails1, commentDetails1,
            CoreMatchers.containsString(strCommentTimeAdded));
    commentAdded1 = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[2]/div[2]/div"));
    assertEquals(commentAdded1, smallText);

    /*
     * ## Step 3
     */
    this.elemHelper.ClickJS(driver, By.cssSelector("div.addComment"));
    //After click in add, check if the button add, save and cancel are displayed
    addComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.addComment"));
    assertEquals("Add Comment", addComments);
    cancelComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.cancelComment"));
    assertEquals("Cancel", cancelComments);
    saveComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.saveComment"));
    assertEquals("Save", saveComments);
    //Insert the text
    this.elemHelper.FindElement(driver, By.cssSelector("textarea.addCommentText")).sendKeys(specCharText);
    this.elemHelper.ClickJS(driver, By.cssSelector("div.saveComment"));
    Date timeAddedComment3 = new Date();
    //wait for the page rendered (and for the two added comments persist
    wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("div.navigateRefresh")));
    wait.until(
            ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='sampleObject']/div/div/div[1]")));
    wait.until(
            ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='sampleObject']/div/div/div[2]")));
    wait.until(
            ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='sampleObject']/div/div/div[3]")));
    //Check if the comment was added
    //Comment added 3
    String strCommentTimeAdded3 = "admin, " + sdf.format(timeAddedComment3);
    // Need to remove the last digit of minutes to avoid failing. Because, we 
    // could catch something like 14:22 and the comment was added at 14:21:59
    strCommentTimeAdded3 = strCommentTimeAdded3.substring(0, strCommentTimeAdded3.length() - 1);
    String commentDetails3 = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[1]/div"));
    assertThat("Comment added: " + commentDetails3, commentDetails3,
            CoreMatchers.containsString(strCommentTimeAdded3));
    String commentAdded3 = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[1]/div[2]/div"));
    assertEquals(commentAdded3, specCharText);
    //Comment added 2
    strCommentTimeAdded2 = "" + sdf.format(timeAddedComment2);
    commentDetails2 = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[2]/div"));
    assertThat("Comment added: " + commentDetails2, commentDetails2,
            CoreMatchers.containsString(strCommentTimeAdded2));
    commentAdded2 = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[2]/div[2]/div"));
    assertEquals(commentAdded2, longText);
    //Comment added 1
    commentDetails1 = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[3]/div"));
    assertThat("Comment added: " + commentDetails1, commentDetails1,
            CoreMatchers.containsString(strCommentTimeAdded));
    commentAdded1 = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[3]/div[2]/div"));
    assertEquals(commentAdded1, smallText);
}

From source file:com.pentaho.ctools.cdf.CommentComponent.java

License:Apache License

/**
 * ############################### Test Case 5 ###############################
 *
 * Test Case Name://from   w  w w.  j  a v a  2s.c o m
 *    Display Page
 * Description:
 *    We pretend validate to check if a comment is removed.
 * Steps:
 *    1. Add a comment
 *    2. Remove added comment
 */
@Test
public void tc5_RemoveCoomment_CommentRemoved() {
    this.log.info("tc5_RemoveCoomment_CommentRemoved");
    this.tcRemoveComment = true;
    /*
     * Guarantee no comments displayed
     */
    cleanAllComments();

    String commentText = "Some comment!";
    String noComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.comment"));
    assertEquals("No Comments to show!", noComments);
    String addComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.addComment"));
    assertEquals("Add Comment", addComments);

    /*
     * ## Step 1
     */
    this.elemHelper.ClickJS(driver, By.cssSelector("div.addComment"));
    //Insert the text
    this.elemHelper.FindElement(driver, By.cssSelector("textarea.addCommentText")).sendKeys(commentText);
    this.elemHelper.ClickJS(driver, By.cssSelector("div.saveComment"));
    //wait for the page rendered
    wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("div.navigateRefresh")));
    //Check if the comment was added
    String commentAdded = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[1]/div[2]/div"));
    assertEquals(commentAdded, commentText);

    /*
     * ## Step 2
     */
    Actions acts = new Actions(driver);
    acts.moveToElement(this.elemHelper.FindElement(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[1]/div[2]/div")));
    acts.build().perform();
    acts.perform();
    acts.moveToElement(this.elemHelper.FindElement(driver, By.cssSelector("div.archive")));
    acts.click();
    acts.perform();
    //Check we don't have more comments
    noComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.comment"));
    assertEquals("No Comments to show!", noComments);
    addComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.addComment"));
    assertEquals("Add Comment", addComments);
    String refreshComments = this.elemHelper.WaitForElementPresentGetText(driver,
            By.cssSelector("div.navigateRefresh"));
    assertEquals("Refresh", refreshComments);
}

From source file:com.pentaho.ctools.cdf.ExecuteAnalyzerComponent.java

License:Apache License

/**
 * ############################### Test Case 3 ###############################
 *
 * Test Case Name:// www.j a va 2 s. c  om
 *    Select HTML and PDF (content type)
 * Description:
 *    The test case pretends validate the result when change for option HTML
 *    and PDF for content-type.
 * Steps:
 *    1. Check the contents presented
 */
@Test
public void tc3_CheckDisplayPage_DataIsDisplayedAsExpected() {
    this.log.info("tc3_CheckDisplayPage_DataIsDisplayedAsExpected");

    // ## Step 1
    String buttonText = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//button/span"));
    assertEquals("Execute Analyzer", buttonText);
    this.elemHelper.FindElement(driver, By.xpath("//button/span")).click();
    wait.until(ExpectedConditions.presenceOfElementLocated(By.id("fancybox-content")));
    //Move to iframe
    WebElement elemIFrame = this.elemHelper.FindElement(driver, By.xpath("//iframe"));
    String attrId = elemIFrame.getAttribute("id");
    driver.switchTo().frame(attrId);
    //Wait for glasspane display and disable
    this.elemHelper.WaitForElementPresence(driver, By.id("glasspane"), 5);
    this.elemHelper.WaitForElementInvisibility(driver, By.id("glasspane"));
    //Check presence of tool bar elements
    WebElement elemLine = this.elemHelper.WaitForElementPresenceAndVisible(driver, By.id("sortHandle_1"), 45);
    assertNotNull(elemLine);
}

From source file:com.pentaho.ctools.cdf.ExecutePrptComponent.java

License:Apache License

/**
 * ############################### Test Case 3 ###############################
 *
 * Test Case Name://www  .j a  v  a2s  .c  o m
 *    Select HTML and PDF (content type)
 * Description:
 *    The test case pretends validate the result when change for option HTML
 *    and PDF for content-type.
 * Steps:
 *    1. Check the contents presented
 */
@Test
public void tc3_CheckDisplayPage_DataIsDisplayedAsExpected() {
    this.log.info("tc3_CheckDisplayPage_DataIsDisplayedAsExpected");

    // ## Step 1
    String buttonText = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//button/span"));
    assertEquals("Execute Prpt", buttonText);
    this.elemHelper.FindElement(driver, By.xpath("//button/span")).click();
    wait.until(ExpectedConditions.presenceOfElementLocated(By.id("fancybox-content")));
    //Move to iframe
    WebElement elemIFrame = this.elemHelper.FindElement(driver, By.xpath("//iframe"));
    String attrId = elemIFrame.getAttribute("id");
    driver.switchTo().frame(attrId);
    //Wait for glasspane display and disable
    this.elemHelper.WaitForElementPresence(driver, By.id("glasspane"), 5);
    this.elemHelper.WaitForElementInvisibility(driver, By.id("glasspane"));
    //Check presence of tool bar elements
    assertNotNull(this.elemHelper.FindElement(driver, By.xpath("//div[@id='toolbar']/div")));
    assertNotNull(this.elemHelper.FindElement(driver, By.xpath("//div[@id='toolbar']/div[2]")));
    assertNotNull(this.elemHelper.FindElement(driver, By.xpath("//div[@id='toolbar']/span")));
    //Check the Product Name and Output Type
    WebElement elemtLine = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.cssSelector("div.parameter-label"), 45);
    assertNotNull(elemtLine);
    String prodName = this.elemHelper.WaitForElementPresentGetText(driver,
            By.cssSelector("div.parameter-label"));
    assertEquals("Line", prodName);
    assertNotNull(this.elemHelper.FindElement(driver, By.xpath("//td/div/div[2]/select")));
    String outputTypeName = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@class='parameter']/div[2]/select/../../div"));
    assertEquals("Output Type", outputTypeName);
    assertNotNull(this.elemHelper.FindElement(driver, By.xpath("//div[@class='parameter']/div[2]/select")));
    //Check for View Report button
    if (pentahoReleaseVersion.equalsIgnoreCase(ConfigurationSettings.PENTAHO_RELEASE_VERSION_6X)) {
        String buttonName = this.elemHelper.WaitForElementPresentGetText(driver,
                By.cssSelector("button.pentaho-button"));
        assertEquals("View Report", buttonName);
    } else {
        String buttonName = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//button/span"));
        assertEquals("View Report", buttonName);
    }
    //Check the generated image
    this.elemHelper.WaitForElementPresence(driver, By.cssSelector("iframe#reportContent"));
    WebDriver driverReportContent = driver.switchTo().frame("reportContent");
    WebElement elemReport = this.elemHelper.WaitForElementPresenceAndVisible(driverReportContent,
            By.xpath("//tbody/tr"));
    assertNotNull(elemReport);
    this.elemHelper.WaitForTextPresence(driverReportContent, By.xpath("//tbody/tr"), "LINE: Classic Cars");
    String strTitle = this.elemHelper.WaitForElementPresentGetText(driverReportContent, By.xpath("//tbody/tr"));
    assertEquals("LINE: Classic Cars", strTitle);
    this.elemHelper.WaitForTextPresence(driverReportContent, By.xpath("//tbody/tr[3]/td"),
            "Autoart Studio Design");
    String strCompany = this.elemHelper.WaitForElementPresentGetText(driverReportContent,
            By.xpath("//tbody/tr[3]/td"));
    assertEquals("Autoart Studio Design", strCompany);
    this.elemHelper.WaitForTextPresence(driverReportContent, By.xpath("//tbody/tr[5]/td[3]/a"),
            "1958 Chevy Corvette Limited Edition");
    String strValue = this.elemHelper.WaitForElementPresentGetText(driverReportContent,
            By.xpath("//tbody/tr[5]/td[3]/a"));
    assertEquals("1958 Chevy Corvette Limited Edition", strValue);
    String strHref = this.elemHelper.GetAttribute(driverReportContent, By.xpath("//tbody/tr[5]/td[3]/a"),
            "href");
    assertEquals("http://images.google.com/images?q=1958%20Chevy%20Corvette%20Limited%20Edition", strHref);
}