List of usage examples for org.openqa.selenium.support.ui ExpectedConditions visibilityOfElementLocated
public static ExpectedCondition<WebElement> visibilityOfElementLocated(final By locator)
From source file:org.apache.zeppelin.integration.PersonalizeActionsIT.java
License:Apache License
@Test public void testGraphAction() throws Exception { try {//from www.jav a 2s . com // step 1 : (admin) create a new note, run a paragraph, change active graph to 'Bar chart', turn on personalized mode AuthenticationIT authenticationIT = new AuthenticationIT(); authenticationIT.authenticationUser("admin", "password1"); By locator = By .xpath("//div[contains(@class, \"col-md-4\")]/div/h5/a[contains(.,'Create new" + " note')]"); WebDriverWait wait = new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC); WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); if (element.isDisplayed()) { createNewNote(); } String noteId = driver.getCurrentUrl().substring(driver.getCurrentUrl().lastIndexOf("/") + 1); setTextOfParagraph(1, "print(s\"\"\"%table\\n" + "name\\tsize\\n" + "sun\\t100\\n" + "moon\\t10\"\"\")"); runParagraph(1); try { waitForParagraph(1, "FINISHED"); } catch (TimeoutException e) { waitForParagraph(1, "ERROR"); collector.checkThat( "Exception in PersonalizeActionsIT while testGraphAction, status of 1st Spark Paragraph ", "ERROR", CoreMatchers.equalTo("FINISHED")); } pollingWait(By.xpath(getParagraphXPath(1) + "//button[contains(@uib-tooltip, 'Bar Chart')]"), MAX_BROWSER_TIMEOUT_SEC).click(); collector.checkThat("The output of graph mode is changed", driver.findElement(By.xpath(getParagraphXPath(1) + "//button[contains(@class," + "'btn btn-default btn-sm ng-binding ng-scope active')]//i")).getAttribute("class"), CoreMatchers.equalTo("fa fa-bar-chart")); pollingWait( By.xpath( "//*[@id='actionbar']" + "//button[contains(@uib-tooltip, 'Switch to personal mode')]"), MAX_BROWSER_TIMEOUT_SEC).click(); clickAndWait( By.xpath("//div[@class='modal-dialog'][contains(.,'Do you want to personalize your analysis?')" + "]//div[@class='modal-footer']//button[contains(.,'OK')]")); authenticationIT.logoutUser("admin"); // step 2 : (user1) make sure it is on personalized mode and active graph is 'Bar chart', // try to change active graph to 'Table' and then check result authenticationIT.authenticationUser("user1", "password2"); locator = By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + noteId + "')]"); element = wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); if (element.isDisplayed()) { pollingWait(By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + noteId + "')]"), MAX_BROWSER_TIMEOUT_SEC).click(); } collector.checkThat("The personalized mode enables", driver.findElement(By.xpath("//*[@id='actionbar']" + "//button[contains(@class, 'btn btn-default btn-xs ng-scope ng-hide')]")) .getAttribute("uib-tooltip"), CoreMatchers.equalTo("Switch to personal mode (owner can change)")); collector.checkThat("Make sure the output of graph mode is", driver.findElement(By.xpath(getParagraphXPath(1) + "//button[contains(@class," + "'btn btn-default btn-sm ng-binding ng-scope active')]//i")).getAttribute("class"), CoreMatchers.equalTo("fa fa-bar-chart")); pollingWait(By.xpath(getParagraphXPath(1) + "//button[contains(@uib-tooltip, 'Table')]"), MAX_BROWSER_TIMEOUT_SEC).click(); collector.checkThat("The output of graph mode is not changed", driver.findElement(By.xpath(getParagraphXPath(1) + "//button[contains(@class," + "'btn btn-default btn-sm ng-binding ng-scope active')]//i")).getAttribute("class"), CoreMatchers.equalTo("fa fa-bar-chart")); authenticationIT.logoutUser("user1"); } catch (Exception e) { handleException("Exception in PersonalizeActionsIT while testGraphAction ", e); } }
From source file:org.apache.zeppelin.integration.PersonalizeActionsIT.java
License:Apache License
@Test public void testDynamicFormAction() throws Exception { try {/* w w w .j a v a 2s . c o m*/ // step 1 : (admin) login, create a new note, run a paragraph with data of spark tutorial, logout. AuthenticationIT authenticationIT = new AuthenticationIT(); authenticationIT.authenticationUser("admin", "password1"); By locator = By .xpath("//div[contains(@class, \"col-md-4\")]/div/h5/a[contains(.,'Create new" + " note')]"); WebDriverWait wait = new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC); WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); if (element.isDisplayed()) { createNewNote(); } String noteId = driver.getCurrentUrl().substring(driver.getCurrentUrl().lastIndexOf("/") + 1); setTextOfParagraph(1, "%spark println(\"Status: \"+z.textbox(\"name\", \"Before\")) "); runParagraph(1); try { waitForParagraph(1, "FINISHED"); } catch (TimeoutException e) { waitForParagraph(1, "ERROR"); collector.checkThat( "Exception in PersonalizeActionsIT while testDynamicFormAction, status of 1st Spark Paragraph ", "ERROR", CoreMatchers.equalTo("FINISHED")); } collector.checkThat("The output of graph mode is changed", driver.findElement(By.xpath(getParagraphXPath(1) + "//input[contains(@name, 'name')]")) .getAttribute("value"), CoreMatchers.equalTo("Before")); pollingWait( By.xpath( "//*[@id='actionbar']" + "//button[contains(@uib-tooltip, 'Switch to personal mode')]"), MAX_BROWSER_TIMEOUT_SEC).click(); clickAndWait( By.xpath("//div[@class='modal-dialog'][contains(.,'Do you want to personalize your analysis?')" + "]//div[@class='modal-footer']//button[contains(.,'OK')]")); authenticationIT.logoutUser("admin"); // step 2 : (user1) make sure it is on personalized mode and dynamic form value is 'Before', // try to change dynamic form value to 'After' and then check result authenticationIT.authenticationUser("user1", "password2"); locator = By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + noteId + "')]"); element = wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); if (element.isDisplayed()) { pollingWait(By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + noteId + "')]"), MAX_BROWSER_TIMEOUT_SEC).click(); } collector.checkThat("The personalized mode enables", driver.findElement(By.xpath("//*[@id='actionbar']" + "//button[contains(@class, 'btn btn-default btn-xs ng-scope ng-hide')]")) .getAttribute("uib-tooltip"), CoreMatchers.equalTo("Switch to personal mode (owner can change)")); collector.checkThat("The output of graph mode is changed", driver.findElement(By.xpath(getParagraphXPath(1) + "//input[contains(@name, 'name')]")) .getAttribute("value"), CoreMatchers.equalTo("Before")); pollingWait(By.xpath(getParagraphXPath(1) + "//input[contains(@name, 'name')]"), MAX_BROWSER_TIMEOUT_SEC).clear(); pollingWait(By.xpath(getParagraphXPath(1) + "//input[contains(@name, 'name')]"), MAX_BROWSER_TIMEOUT_SEC).sendKeys("After"); runParagraph(1); try { waitForParagraph(1, "FINISHED"); } catch (TimeoutException e) { waitForParagraph(1, "ERROR"); collector.checkThat( "Exception in PersonalizeActionsIT while testDynamicFormAction, status of 1st Spark Paragraph ", "ERROR", CoreMatchers.equalTo("FINISHED")); } collector.checkThat("The output of graph mode is changed", driver.findElement( By.xpath(getParagraphXPath(1) + "//div[contains(@class, 'text plainTextContent')]")) .getText(), CoreMatchers.equalTo("Status: Before")); authenticationIT.logoutUser("user1"); } catch (Exception e) { handleException("Exception in PersonalizeActionsIT while testGraphAction ", e); } }
From source file:org.cc.demo.test.Selenium2.java
License:Apache License
/** * Element??, timeout??.//from w w w . j a v a 2 s.c o m */ public void waitForVisible(By by, int timeout) { (new WebDriverWait(driver, timeout)).until(ExpectedConditions.visibilityOfElementLocated(by)); }
From source file:org.cerberus.service.appium.impl.AppiumService.java
License:Open Source License
private WebElement getElement(Session session, Identifier identifier, boolean visible, boolean clickable) { AppiumDriver driver = session.getAppiumDriver(); By locator = this.getBy(identifier); LOG.debug("Waiting for Element : " + identifier.getIdentifier() + "=" + identifier.getLocator()); try {/* w w w . j a v a2 s .c o m*/ WebDriverWait wait = new WebDriverWait(driver, TimeUnit.MILLISECONDS.toSeconds(session.getCerberus_appium_wait_element())); if (visible) { if (clickable) { wait.until(ExpectedConditions.elementToBeClickable(locator)); } else { wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); } } else { wait.until(ExpectedConditions.presenceOfElementLocated(locator)); } } catch (TimeoutException exception) { LOG.fatal("Exception waiting for element :" + exception.toString()); throw new NoSuchElementException(identifier.getIdentifier() + "=" + identifier.getLocator()); } LOG.debug("Finding Element : " + identifier.getIdentifier() + "=" + identifier.getLocator()); return driver.findElement(locator); }
From source file:org.cerberus.service.engine.impl.AppiumService.java
License:Open Source License
private WebElement getElement(Session session, Identifier identifier, boolean visible, boolean clickable) { AppiumDriver driver = session.getAppiumDriver(); By locator = this.getBy(identifier); MyLogger.log(RunTestCaseService.class.getName(), Level.DEBUG, "Waiting for Element : " + identifier.getIdentifier() + "=" + identifier.getLocator()); try {//from w w w .ja v a 2 s. c o m WebDriverWait wait = new WebDriverWait(driver, session.getDefaultWait()); if (visible) { if (clickable) { wait.until(ExpectedConditions.elementToBeClickable(locator)); } else { wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); } } else { wait.until(ExpectedConditions.presenceOfElementLocated(locator)); } } catch (TimeoutException exception) { MyLogger.log(RunTestCaseService.class.getName(), Level.FATAL, "Exception waiting for element :" + exception); throw new NoSuchElementException(identifier.getIdentifier() + "=" + identifier.getLocator()); } MyLogger.log(RunTestCaseService.class.getName(), Level.DEBUG, "Finding Element : " + identifier.getIdentifier() + "=" + identifier.getLocator()); return driver.findElement(locator); }
From source file:org.cerberus.service.engine.impl.WebDriverService.java
License:Open Source License
private AnswerItem<WebElement> getSeleniumElement(Session session, Identifier identifier, boolean visible, boolean clickable) { AnswerItem<WebElement> answer = new AnswerItem<WebElement>(); MessageEvent msg;/*from w ww. j a v a2s . c o m*/ By locator = this.getBy(identifier); MyLogger.log(WebDriverService.class.getName(), Level.DEBUG, "Waiting for Element : " + identifier.getIdentifier() + "=" + identifier.getLocator()); try { WebDriverWait wait = new WebDriverWait(session.getDriver(), session.getDefaultWait()); WebElement element; if (visible) { if (clickable) { element = wait.until(ExpectedConditions.elementToBeClickable(locator)); } else { element = wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); } } else { element = wait.until(ExpectedConditions.presenceOfElementLocated(locator)); } answer.setItem(element); msg = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT); msg.setDescription(msg.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator())); } catch (TimeoutException exception) { MyLogger.log(WebDriverService.class.getName(), Level.FATAL, "Exception waiting for element :" + exception); //throw new NoSuchElementException(identifier.getIdentifier() + "=" + identifier.getLocator()); msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT_NO_SUCH_ELEMENT); msg.setDescription(msg.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator())); } answer.setResultMessage(msg); return answer; }
From source file:org.cerberus.service.SeleniumServiceTest.java
License:Open Source License
@Test public void testDoActionClickObjectWhenSuccess() throws Exception { String object = "id=test"; String property = "null"; String msg = "Element '" + object + "' clicked."; PowerMockito.mockStatic(ExpectedConditions.class); PowerMockito.mockStatic(By.class); when(selenium.getDriver()).thenReturn(driver); when(By.id(anyString())).thenReturn(by); PowerMockito.whenNew(WebDriverWait.class).withAnyArguments().thenReturn(webDriverWait); when(ExpectedConditions.visibilityOfElementLocated(by)).thenReturn(expectedCondition); when(fluentWait.until(expectedCondition)).thenReturn(element); when(driver.findElement(by)).thenReturn(element); MessageEvent message = this.seleniumService.doSeleniumActionClick(selenium, object, property); Assert.assertEquals(msg, message.getDescription()); }
From source file:org.cerberus.service.SeleniumServiceTest.java
License:Open Source License
@Test public void testDoActionClickPropertyWhenSuccess() throws Exception { String object = "null"; String property = "id=test"; String msg = "Element '" + property + "' clicked."; PowerMockito.mockStatic(ExpectedConditions.class); PowerMockito.mockStatic(By.class); when(selenium.getDriver()).thenReturn(driver); when(By.id(anyString())).thenReturn(by); PowerMockito.whenNew(WebDriverWait.class).withAnyArguments().thenReturn(webDriverWait); when(ExpectedConditions.visibilityOfElementLocated(by)).thenReturn(expectedCondition); when(fluentWait.until(ExpectedConditions.visibilityOfElementLocated(by))).thenReturn(element); when(driver.findElement(by)).thenReturn(element); MessageEvent message = this.seleniumService.doSeleniumActionClick(selenium, object, property); Assert.assertEquals(msg, message.getDescription()); }
From source file:org.cerberus.service.SeleniumServiceTest.java
License:Open Source License
/** * Action ClickAndWait//from w w w.jav a 2 s.c o m */ @Test public void testDoActionClickWaitWhenSuccess() throws Exception { String object = "id=test"; String property = "100"; String msg = "Element '" + object + "' clicked and waited " + property + " ms."; PowerMockito.mockStatic(ExpectedConditions.class); PowerMockito.mockStatic(By.class); when(selenium.getDriver()).thenReturn(driver); when(By.id(anyString())).thenReturn(by); PowerMockito.whenNew(WebDriverWait.class).withAnyArguments().thenReturn(webDriverWait); when(ExpectedConditions.visibilityOfElementLocated(by)).thenReturn(expectedCondition); when(webDriverWait.until(ExpectedConditions.visibilityOfElementLocated(by))).thenReturn(element); when(driver.findElement(by)).thenReturn(element); MessageEvent message = this.seleniumService.doSeleniumActionClickWait(selenium, object, property); Assert.assertEquals(msg, message.getDescription()); }
From source file:org.cerberus.service.SeleniumServiceTest.java
License:Open Source License
@Test public void testDoActionClickWaitWhenPropertyNotNumeric() throws Exception { String object = "id=test"; String property = "dez"; String msg = "Failed to wait because '" + property + "' in not numeric!"; PowerMockito.mockStatic(ExpectedConditions.class); PowerMockito.mockStatic(By.class); when(selenium.getDriver()).thenReturn(driver); when(By.id(anyString())).thenReturn(by); PowerMockito.whenNew(WebDriverWait.class).withAnyArguments().thenReturn(webDriverWait); when(ExpectedConditions.visibilityOfElementLocated(by)).thenReturn(expectedCondition); when(webDriverWait.until(ExpectedConditions.visibilityOfElementLocated(by))).thenReturn(element); when(driver.findElement(by)).thenReturn(element); MessageEvent message = this.seleniumService.doSeleniumActionClickWait(selenium, object, property); Assert.assertEquals(msg, message.getDescription()); }