List of usage examples for org.openqa.selenium WebElement isDisplayed
boolean isDisplayed();
From source file:com.pentaho.ctools.cde.reference.PopupComponent.java
License:Apache License
/** * ############################### Test Case 2 ############################### * * Test Case Name://w ww . ja va 2 s . c o m * PopupExample1 * Description: * The test case pretends validate if the popup works as expect. * Steps: * 1. Check page contents * 2. Check popup display */ @Test public void tc02_PopupExample1_PopupDisplay() { this.log.info("tc02_PopupExample1_PopupDisplay"); /* * ## Step 1 */ String strExampleTitle = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@id='Example1Title']")); String strExampleDesc = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@id='Example1Desc']/p")); String strButtonName = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@id='example1Obj']/button")); assertEquals("Example 1", strExampleTitle); assertEquals("Button popup with the default settings. You can drag it around and close on the button", strExampleDesc); assertEquals("Popup", strButtonName); /* * ## Step 2 */ this.elemHelper.ClickJS(driver, By.xpath("//div[@id='example1Obj']/button")); this.elemHelper.WaitForElementPresence(driver, By.xpath("//div[@id='popupContent1']")); //Wait for the charts load this.elemHelper.WaitForElementPresenceAndVisible(driver, By.xpath("//*[3][@width>13]")); //Check text String textInPopup = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@id='text']")); assertEquals("This will appear in the popup", textInPopup); //Check rect in chart WebElement elemRect1 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='popupContent1']/div/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='rect'][1]")); WebElement elemRect2 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='popupContent1']/div/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='rect'][2]")); WebElement elemRect3 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='popupContent1']/div/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='rect'][3]")); WebElement elemRect4 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='popupContent1']/div/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='rect'][4]")); assertNotNull(elemRect1); assertNotNull(elemRect2); assertNotNull(elemRect3); assertNotNull(elemRect4); assertEquals("35.521816666666666", elemRect1.getAttribute("width")); //36.27305471479055 assertEquals("136.75265000000002", elemRect2.getAttribute("width")); //139.64478231479157 assertEquals("13.579274999999999", elemRect3.getAttribute("width")); //13.866458173700408 assertEquals("104.68426666666666", elemRect4.getAttribute("width")); //106.89819634537434 //Check subtitles Actions acts = new Actions(driver); acts.moveToElement(elemRect2).perform(); String tooltipValue = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@class='tipsy tipsy-s']/div[2]/div/table/tbody/tr[3]/td[3]/span")); assertEquals("49,578", tooltipValue); //Close popup this.elemHelper.ClickJS(driver, By.cssSelector("a.close")); //wait for popup disappear this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("a.close")); WebElement element = driver.findElement(By.cssSelector("a.close")); assertFalse(element.isDisplayed()); }
From source file:com.pentaho.ctools.cde.reference.PopupComponent.java
License:Apache License
/** * ############################### Test Case 3 ############################### * * Test Case Name:/*from w w w.j ava 2s . c o m*/ * PopupExample2 * Description: * The test case pretends validate if the popup works as expect. * Steps: * 1. Check page contents * 2. Check popup display */ @Test public void tc03_PopupExample2_PopupDisplay() { this.log.info("tc03_PopupExample2_PopupDisplay"); /* * ## Step 1 */ String strExampleTitle = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@id='Example2Title']")); String strExampleDesc = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@id='Example2Desc']/p")); String strButtonName = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@id='example2Obj']/button")); assertEquals("Example 2", strExampleTitle); assertEquals( "Button popup appearing in the west, can't be dragged and clicking anywhere outside the element will popup the button", strExampleDesc); assertEquals("Popup", strButtonName); /* * ## Step 2 */ this.elemHelper.ClickJS(driver, By.xpath("//div[@id='example2Obj']/button")); this.elemHelper.WaitForElementPresence(driver, By.xpath("//div[@id='popupContent2']")); //Check text String textInPopup = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@id='popupContent2']")); assertEquals("A simple text that can be used as a tooltip", textInPopup); //Close popup this.elemHelper.ClickJS(driver, By.xpath("//div[8]/a")); //wait for popup disappear this.elemHelper.WaitForElementInvisibility(driver, By.xpath("//div[8]/a")); WebElement element = driver.findElement(By.xpath("//div[8]/a")); assertFalse(element.isDisplayed()); }
From source file:com.pentaho.ctools.cdf.DateRangeInputComponent.java
License:Apache License
/** * ############################### Test Case 8 ############################### * * Test Case Name:// w w w . j a va 2 s. c o m * Set Date Range Today * Description: * When click on All Dates Before option an alert is displayed with an * interval starting from '2014-04-22' to the selected date. * Steps: * 1. Click in Today option and then Cancel * 2. Click in Today option and then Done * 3. Check for Alert */ @Test public void tc8_AllDatesBeforePressCancelAndSelectDate_DateIsCancelAndThenSetSuccessful() { /* * ## Step 1 */ this.elemHelper.Click(driver, By.id("myInput")); this.elemHelper.FindElement(driver, By.linkText("All Dates Before")).sendKeys(Keys.ENTER); this.elemHelper.Click(driver, By.xpath("(//button[contains(text(),'Cancel')])[7]")); this.elemHelper.WaitForElementInvisibility(driver, By.xpath("(//a[text()='All Dates Before'])[2]"), 5); WebElement dataPickerDisable = this.elemHelper.WaitForElementPresence(driver, By.xpath("(//a[text()='All Dates Before'])[2]"), 1); assertFalse(dataPickerDisable.isDisplayed()); /* * ## Step 2 */ //Click in day 29 this.elemHelper.Click(driver, By.id("myInput")); //ADD THIS LINE TO RUN IN WIN8: this.elemHelper.Click( driver, By.id( "myInput2" ) ); this.elemHelper.FindElement(driver, By.linkText("All Dates Before")).sendKeys(Keys.ENTER); this.elemHelper.FindElement(driver, By.linkText("29")).sendKeys(Keys.ENTER); /* * ## Step 3 */ wait.until(ExpectedConditions.alertIsPresent()); Alert alert = driver.switchTo().alert(); String confirmationMsg = alert.getText(); alert.accept(); Calendar c = Calendar.getInstance(); c.add(Calendar.YEAR, -1); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String beginDate = sdf.format(c.getTime()); assertEquals("You chose from " + beginDate + " to 2014-09-29", confirmationMsg); }
From source file:com.pentaho.ctools.cdf.require.DateRangeInputComponent.java
License:Apache License
/** * ############################### Test Case 8 ############################### * * Test Case Name://w w w. j av a2s . c o m * Set Date Range Today * Description: * When click on All Dates Before option an alert is displayed with an * interval starting from '2014-04-22' to the selected date. * Steps: * 1. Click in Today option and then Cancel * 2. Click in Today option and then Done * 3. Check for Alert */ @Test public void tc8_AllDatesBeforePressCancelAndSelectDate_DateIsCancelAndThenSetSuccessful() { this.log.info("tc8_AllDatesBeforePressCancelAndSelectDate_DateIsCancelAndThenSetSuccessful"); /* * ## Step 1 */ this.elemHelper.Click(driver, By.id("myInput")); this.elemHelper.FindElement(driver, By.linkText("All Dates Before")).sendKeys(Keys.ENTER); this.elemHelper.Click(driver, By.xpath("(//button[contains(text(),'Cancel')])[7]")); this.elemHelper.WaitForElementInvisibility(driver, By.xpath("(//a[text()='All Dates Before'])[2]"), 5); WebElement dataPickerDisable = this.elemHelper.WaitForElementPresence(driver, By.xpath("(//a[text()='All Dates Before'])[2]"), 1); assertFalse(dataPickerDisable.isDisplayed()); /* * ## Step 2 */ //Click in day 29 this.elemHelper.Click(driver, By.id("myInput")); //ADD THIS LINE TO RUN IN WIN8: this.elemHelper.Click( driver, By.id( "myInput2" ) ); this.elemHelper.FindElement(driver, By.linkText("All Dates Before")).sendKeys(Keys.ENTER); this.elemHelper.FindElement(driver, By.linkText("29")).sendKeys(Keys.ENTER); /* * ## Step 3 */ String confirmationMsg = this.elemHelper.WaitForAlertReturnConfirmationMsg(driver); Calendar c = Calendar.getInstance(); c.add(Calendar.YEAR, -1); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String beginDate = sdf.format(c.getTime()); assertEquals(confirmationMsg, "You chose from " + beginDate + " to 2014-09-29"); }
From source file:com.pentaho.ctools.utils.ElementHelper.java
License:Apache License
/** * This method pretends to check if the element is present, if it doesn't * then don't wait, if element is present, wait for its invisibility. * true - element invisible/*from w w w . jav a2 s . c o m*/ * false - element visible * @param driver * @param locator * @param timeout */ public boolean WaitForElementInvisibility(final WebDriver driver, final By locator, final Integer timeout) { this.log.debug("WaitForElementInvisibility::Enter"); this.log.debug("Locator: " + locator.toString()); boolean isElemVisible = false; ExecutorService executor = null; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); try { class RunnableObject implements Runnable { private boolean isVisible; public boolean getVisibility() { return this.isVisible; } public void run() { Wait<WebDriver> wait = new FluentWait<WebDriver>(driver) .withTimeout(timeout, TimeUnit.SECONDS).pollingEvery(50, TimeUnit.MILLISECONDS); // Wait for element invisible this.isVisible = wait.until(new Function<WebDriver, Boolean>() { @Override public Boolean apply(WebDriver d) { try { List<WebElement> listElements = d.findElements(locator); if (listElements.size() > 0) { WebElement elem = listElements.get(0); return (!elem.isDisplayed()) ? true : false; } // The element does not exit, i.e., is not visible and even present return true; } catch (StaleElementReferenceException sere) { return false; } } }); } } RunnableObject r = new RunnableObject(); executor = Executors.newSingleThreadExecutor(); executor.submit(r).get(timeout + 2, TimeUnit.SECONDS); isElemVisible = r.getVisibility(); } catch (InterruptedException ie) { this.log.warn("Interrupted Exception"); this.log.warn(ie.toString()); } catch (ExecutionException ee) { if (ee.getCause().getClass().getCanonicalName() .equalsIgnoreCase(TimeoutException.class.getCanonicalName())) { this.log.warn("WebDriver timeout exceeded! Looking for: " + locator.toString()); this.log.warn(ee.toString()); } else { this.log.warn("Execution Exception"); this.log.warn(ee.toString()); } } catch (java.util.concurrent.TimeoutException cte) { this.log.warn("Thread timeout exceeded! Looking for: " + locator.toString()); this.log.warn(cte.toString()); } catch (Exception e) { this.log.error("Exception"); this.log.catching(e); } if (executor != null) { executor.shutdown(); } driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); } catch (Exception ge) { this.log.error("Exception"); this.log.catching(ge); } this.log.debug("WaitForElementInvisibility::Exit"); return isElemVisible; }
From source file:com.pentaho.ctools.utils.ElementHelper.java
License:Apache License
/** * This method pretends to check if the element is present, if it doesn't * we wait for presence for a specific timeout (input), after this, we will * wait for element visible. And, if the element is present then we have to * check if is visible if not wait for visibility. * * @param driver//ww w . jav a 2s .c o m * @param locator * @param timeout */ public WebElement WaitForElementPresenceAndVisible(final WebDriver driver, final By locator, final Integer timeout) { this.log.debug("WaitForElementPresenceAndVisible::Enter"); this.log.debug("Locator: " + locator.toString()); WebElement element = null; ExecutorService executor = null; driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); try { class RunnableObject implements Runnable { private WebElement theElement; public RunnableObject(WebElement theElement) { this.theElement = theElement; } public WebElement getValue() { return this.theElement; } @Override public void run() { Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(timeout, TimeUnit.SECONDS) .pollingEvery(50, TimeUnit.MILLISECONDS); // Wait for element visible this.theElement = wait.until(new Function<WebDriver, WebElement>() { @Override public WebElement apply(WebDriver d) { try { List<WebElement> listElem = d.findElements(locator); if (listElem.size() > 0) { WebElement elem = listElem.get(0); if (elem != null && ((elem.isEnabled() == true) && (elem.isDisplayed() == true))) { return elem; } return null; } return null; } catch (StaleElementReferenceException sere) { return null; } } }); } } RunnableObject r = new RunnableObject(element); executor = Executors.newSingleThreadExecutor(); executor.submit(r).get(timeout + 2, TimeUnit.SECONDS); element = r.getValue(); } catch (InterruptedException ie) { this.log.warn("Interrupted Exception"); this.log.warn(ie.toString()); } catch (ExecutionException ee) { if (ee.getCause().getClass().getCanonicalName() .equalsIgnoreCase(TimeoutException.class.getCanonicalName())) { this.log.warn("WebDriver timeout exceeded! Looking for: " + locator.toString()); } else { this.log.warn("Execution Exception"); this.log.warn(ee.toString()); } } catch (java.util.concurrent.TimeoutException cte) { this.log.warn("Thread timeout exceeded! Looking for: " + locator.toString()); this.log.warn(cte.toString()); } catch (Exception e) { this.log.error("Exception"); this.log.catching(e); } if (executor != null) { executor.shutdown(); } driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); this.log.debug("WaitForElementPresenceAndVisible::Exit"); return element; }
From source file:com.provenir.automation.framework.helper.AdminPage.java
public boolean verifyPreAnalysisTasks() { Util.waitForAJAX(driver);//from ww w .ja va 2 s .c o m WebElement e = driver.findElement(By.xpath("//label[contains(.,'Pre-Analysis')]")); WebElement f = driver.findElement(By.xpath("//label[contains(.,'Enter Financial Statements')]")); WebElement g = driver.findElement(By.xpath("//label[contains(.,'Execute OFAC Check on all Parties')]")); WebElement h = driver.findElement(By.xpath("//label[contains(.,'Verify readiness to pull credit')]")); WebElement i = driver.findElement(By.xpath("//label[contains(.,'Retrieve Credit Bureau Data')]")); WebElement j = driver.findElement(By.xpath("//label[contains(.,'Execute Auto-Decision')]")); WebElement k = driver.findElement(By.xpath("//label[contains(.,'Duplicate Check')]")); WebElement l = driver.findElement(By.xpath("//label[contains(.,'Fraud Check')]")); if (e.isDisplayed() && f.isDisplayed() && g.isDisplayed() && h.isDisplayed() && i.isDisplayed() && j.isDisplayed() && k.isDisplayed() && l.isDisplayed()) return true; else return false; }
From source file:com.provenir.automation.framework.helper.AdminPage.java
public boolean verifyDecision() { Util.waitForAJAX(driver);// w w w . j a va 2 s . c om WebElement e = driver.findElement(By.xpath("//label[starts-with(.,'Decision')]")); WebElement f = driver.findElement(By.xpath("//label[contains(.,'Policy Exceptions')]")); WebElement g = driver.findElement(By.xpath("//label[contains(.,'Post Bureau Check')]")); WebElement h = driver.findElement(By.xpath("//label[contains(.,'Review or Amend Decision')]")); WebElement i = driver.findElement(By.xpath("//label[contains(.,'Generate Commitment Letter')]")); if (e.isDisplayed() && f.isDisplayed() && g.isDisplayed() && h.isDisplayed() && i.isDisplayed()) return true; else return false; }
From source file:com.provenir.automation.framework.helper.AdminPage.java
public boolean verifyCustomerAcceptance() { Util.waitForAJAX(driver);//from ww w.j a va 2 s.c om WebElement e = driver.findElement(By.xpath("//label[contains(.,'Customer Acceptance')]")); WebElement f = driver.findElement(By.xpath("//label[contains(.,'Complete Application Checklist')]")); WebElement g = driver.findElement(By.xpath("//label[contains(.,'Does Customer Accept Approved Terms?')]")); if (e.isDisplayed() && f.isDisplayed() && g.isDisplayed()) return true; else return false; }
From source file:com.provenir.automation.framework.helper.AdminPage.java
public boolean verifyDueDiligence() { Util.waitForAJAX(driver);/* www. j a v a 2s . c o m*/ WebElement e = driver.findElement(By.xpath("//label[contains(.,'Fulfillment - Due diligence')]")); WebElement f = driver.findElement(By.xpath("//label[contains(.,'Due Diligence checklist')]")); WebElement g = driver.findElement(By.xpath("//label[contains(.,'Complete Pre-Document Checklist')]")); if (e.isDisplayed() && f.isDisplayed() && g.isDisplayed()) return true; else return false; }