WaitUntilAction extends FindElementAction { @Override protected void execute(WebElement webElement, SeleniumBrowser browser, TestContext context) { WebDriverWait q = new WebDriverWait(browser.getWebDriver(), Math.round(timeout / 1000.0D)); if (condition.equals("hidden")) { q.until(ExpectedConditions.invisibilityOf(webElement)); } else if (condition.equals("visible")) { q.until(ExpectedConditions.visibilityOf(webElement)); } else { throw new CitrusRuntimeException("Unknown wait condition"); } } WaitUntilAction(Builder builder); Long getTimeout(); String getCondition();  }
@Test public void testWaitForHidden() throws Exception { when(webDriver.findElement(any(By.class))).thenReturn(element); when(element.isDisplayed()).thenReturn(false); WaitUntilAction action = new WaitUntilAction.Builder() .browser(seleniumBrowser) .element("class-name", "clickable") .condition("hidden") .build(); action.execute(context); verify(element).isDisplayed(); }
@Test(expectedExceptions = TimeoutException.class) public void testWaitForHiddenTimeout() throws Exception { when(webDriver.findElement(any(By.class))).thenReturn(element); when(element.isDisplayed()).thenReturn(true); WaitUntilAction action = new WaitUntilAction.Builder() .browser(seleniumBrowser) .element("class-name", "clickable") .condition("hidden") .timeout(1000L) .build(); action.execute(context); }
@Test public void testWaitForVisible() throws Exception { when(webDriver.findElement(any(By.class))).thenReturn(element); when(element.isDisplayed()).thenReturn(true); WaitUntilAction action = new WaitUntilAction.Builder() .browser(seleniumBrowser) .element("class-name", "clickable") .condition("visible") .build(); action.execute(context); verify(element).isDisplayed(); }
@Test(expectedExceptions = TimeoutException.class) public void testWaitForVisibleTimeout() throws Exception { when(webDriver.findElement(any(By.class))).thenReturn(element); when(element.isDisplayed()).thenReturn(false); WaitUntilAction action = new WaitUntilAction.Builder() .browser(seleniumBrowser) .element("class-name", "clickable") .condition("visible") .timeout(1000L) .build(); action.execute(context); }
@Test(expectedExceptions = CitrusRuntimeException.class) public void testUnsupportedWaitCondition() throws Exception { when(webDriver.findElement(any(By.class))).thenReturn(element); when(element.isDisplayed()).thenReturn(false); WaitUntilAction action = new WaitUntilAction.Builder() .browser(seleniumBrowser) .element("class-name", "clickable") .condition("unknown") .build(); action.execute(context); }