当前位置: 首页>>代码示例>>Java>>正文


Java ExpectedCondition类代码示例

本文整理汇总了Java中org.openqa.selenium.support.ui.ExpectedCondition的典型用法代码示例。如果您正苦于以下问题:Java ExpectedCondition类的具体用法?Java ExpectedCondition怎么用?Java ExpectedCondition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ExpectedCondition类属于org.openqa.selenium.support.ui包,在下文中一共展示了ExpectedCondition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: absenceElementBy

import org.openqa.selenium.support.ui.ExpectedCondition; //导入依赖的package包/类
public static ExpectedCondition<Boolean> absenceElementBy(final By locator) {
    return new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(final WebDriver driver) {
            try {
                driver.findElement(locator);
                return false;
            } catch (WebDriverException ignored) {
                return true;
            }
        }

        @Override
        public String toString() {
            return String.format("absence of element located by %s", locator);
        }
    };
}
 
开发者ID:WileyLabs,项目名称:teasy,代码行数:19,代码来源:TeasyExpectedConditions.java

示例2: hasNodePropertyValue

import org.openqa.selenium.support.ui.ExpectedCondition; //导入依赖的package包/类
/**
 * Checks if specified node property has specified value
 *
 * @param session       Jcr session.
 * @param nodePath      Absolute path to node.
 * @param propertyName  Property name.
 * @param propertyValue Property value.
 * @return True if node property has specified value.
 */
public static ExpectedCondition<Boolean> hasNodePropertyValue(final Session session,
    final String nodePath, final String propertyName, final String propertyValue) {
  LOG.debug("Checking if node '{}' has property '{}' with value '{}'", nodePath, propertyName,
      propertyValue);
  return input -> {
    Boolean result = null;
    try {
      session.refresh(true);
      result = session.getNode(nodePath).getProperty(propertyName).getValue().getString()
          .equals(propertyValue);
    } catch (RepositoryException e) {
      LOG.error(JCR_ERROR, e);
    }
    return result;
  };
}
 
开发者ID:Cognifide,项目名称:bobcat,代码行数:26,代码来源:JcrExpectedConditions.java

示例3: appearingOfWindowAndSwitchToIt

import org.openqa.selenium.support.ui.ExpectedCondition; //导入依赖的package包/类
/**
 * We don't know the actual window title without switching to one.
 * This method was always used to make sure that the window appeared. After it we switched to appeared window.
 * Switching between windows is rather time consuming operation
 * <p>
 * To avoid the double switching to the window we are switching to window in this method
 * <p>
 * The same approach is applies to all ExpectedConditions for windows
 *
 * @param title - title of window
 * @return - handle of expected window
 */
public static ExpectedCondition<String> appearingOfWindowAndSwitchToIt(final String title) {
    return new ExpectedCondition<String>() {
        @Override
        public String apply(final WebDriver driver) {
            final String initialHandle = driver.getWindowHandle();
            for (final String handle : driver.getWindowHandles()) {
                if (needToSwitch(initialHandle, handle)) {
                    driver.switchTo().window(handle);
                    if (driver.getTitle().equals(title)) {
                        return handle;
                    }
                }
            }
            driver.switchTo().window(initialHandle);
            return null;
        }

        @Override
        public String toString() {
            return String.format("appearing of window by title %s and switch to it", title);
        }
    };
}
 
开发者ID:WileyLabs,项目名称:teasy,代码行数:36,代码来源:TeasyExpectedConditions.java

示例4: clickDialogFooterButton

import org.openqa.selenium.support.ui.ExpectedCondition; //导入依赖的package包/类
/**
 * Clicks button at the bottom of edit Window and expect for dialog to disappear.
 *
 * @param buttonText button label
 * @return Returns this dialog instance.
 */
public AemDialog clickDialogFooterButton(final String buttonText) {
  final WebElement footerButton = getFooterButtonWebElement(buttonText);

  bobcatWait.withTimeout(Timeouts.BIG).until((ExpectedCondition<Object>) input -> {
    try {
      footerButton.click();
      footerButton.isDisplayed();
      return Boolean.FALSE;
    } catch (NoSuchElementException | StaleElementReferenceException
        | ElementNotVisibleException e) {
      LOG.debug("Dialog footer button is not available: {}", e);
      return Boolean.TRUE;
    }
  }, 2);
  bobcatWait.withTimeout(Timeouts.MEDIUM).until(CommonExpectedConditions.noAemAjax());
  return this;
}
 
开发者ID:Cognifide,项目名称:bobcat,代码行数:24,代码来源:AemDialog.java

示例5: ajaxCompleted

import org.openqa.selenium.support.ui.ExpectedCondition; //导入依赖的package包/类
public static ExpectedCondition<Boolean> ajaxCompleted() {
    return new ExpectedCondition<Boolean>() {
        boolean result;
        @Override
        public Boolean apply(WebDriver driver) {
            try {
                result = (Boolean) ((JavascriptExecutor) driver).executeScript("return typeof($) !== 'undefined' && $.active == 0");
                //System.out.println("Ajax return $.active == 0  is: '" + result + "'");
            } catch (WebDriverException e) {
                return false;
            }
            return result;
        }
        public String toString() {
            return "Ajax return $.active == 0  is: '" + result + "'";
        }
    };
}
 
开发者ID:automician,项目名称:snippets,代码行数:19,代码来源:CustomConditions.java

示例6: waitWithTitleAndDelayed

import org.openqa.selenium.support.ui.ExpectedCondition; //导入依赖的package包/类
/**
 * 根据标题中包含某个子串来等待
 * @param title 标题子串
 * @param timeOutInMillis 超时时间毫秒数
 * @param delayedMillis 延迟毫秒数
 */
public void waitWithTitleAndDelayed(final String title, int timeOutInMillis, int delayedMillis) {
    (new WebDriverWait(this, timeOutInMillis/1000)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            String t = d.getTitle();
            if (StringUtils.isEmpty(title)) {
                //等到有title就停止
                return StringUtils.isNotBlank(t);
            }
            return t != null && t.contains(title);
        }
    });
    if (delayedMillis > 0) {
        sleep(delayedMillis);
    }
}
 
开发者ID:brucezee,项目名称:jspider,代码行数:22,代码来源:WebDriverEx.java

示例7: waitWithContentAndDelayed

import org.openqa.selenium.support.ui.ExpectedCondition; //导入依赖的package包/类
/**
 * 根据内容中包含某个子串来等待
 * @param content 内容子串
 * @param timeOutInMillis 超时时间毫秒数
 * @param delayedMillis 延迟毫秒数
 */
public void waitWithContentAndDelayed(final String content, int timeOutInMillis, int delayedMillis) {
    (new WebDriverWait(this, timeOutInMillis/1000)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            String html = d.getPageSource();
            if (StringUtils.isEmpty(content)) {
                //等到有内容就停止
                return StringUtils.isNotBlank(html);
            }
            return html != null && html.contains(content);
        }
    });
    if (delayedMillis > 0) {
        sleep(delayedMillis);
    }
}
 
开发者ID:brucezee,项目名称:jspider,代码行数:22,代码来源:WebDriverEx.java

示例8: appearingOfWindowByPartialTitle

import org.openqa.selenium.support.ui.ExpectedCondition; //导入依赖的package包/类
public static ExpectedCondition<String> appearingOfWindowByPartialTitle(final String fullTitle) {
    return new ExpectedCondition<String>() {
        @Override
        public String apply(final WebDriver driver) {
            final String initialHandle = driver.getWindowHandle();
            for (final String handle : driver.getWindowHandles()) {
                if (needToSwitch(initialHandle, handle)) {
                    driver.switchTo().window(handle);
                    if (fullTitle.contains(driver.getTitle().split("\\(")[0].trim())) {
                        return handle;
                    }
                }
            }
            driver.switchTo().window(initialHandle);
            return null;
        }

        @Override
        public String toString() {
            return String.format("appearing of window by partial title %s and switch to it", fullTitle);
        }
    };
}
 
开发者ID:WileyLabs,项目名称:teasy,代码行数:24,代码来源:TeasyExpectedConditions.java

示例9: appearingOfWindowWithNewTitle

import org.openqa.selenium.support.ui.ExpectedCondition; //导入依赖的package包/类
public static ExpectedCondition<String> appearingOfWindowWithNewTitle(final Set<String> oldTitle) {
    return new ExpectedCondition<String>() {
        @Override
        public String apply(final WebDriver driver) {
            Set<String> windowHandles = driver.getWindowHandles();
            if (windowHandles.containsAll(oldTitle)) {
                windowHandles.removeAll(oldTitle);
                if (!windowHandles.isEmpty()) {
                    return windowHandles.iterator().next();
                }
            }
            return null;
        }

        @Override
        public String toString() {
            return String.format("appearing of window with new title. Old windows titles %s", oldTitle);
        }
    };
}
 
开发者ID:WileyLabs,项目名称:teasy,代码行数:21,代码来源:TeasyExpectedConditions.java

示例10: appearingOfWindowByPartialUrl

import org.openqa.selenium.support.ui.ExpectedCondition; //导入依赖的package包/类
public static ExpectedCondition<String> appearingOfWindowByPartialUrl(final String url) {
    return new ExpectedCondition<String>() {
        @Override
        public String apply(final WebDriver driver) {
            final String initialHandle = driver.getWindowHandle();
            for (final String handle : driver.getWindowHandles()) {
                if (needToSwitch(initialHandle, handle)) {
                    driver.switchTo().window(handle);
                    if (driver.getCurrentUrl().contains(url)) {
                        return handle;
                    }
                }
            }
            driver.switchTo().window(initialHandle);
            return null;
        }

        @Override
        public String toString() {
            return String.format("appearing of window by partial url %s and switch to it", url);
        }
    };
}
 
开发者ID:WileyLabs,项目名称:teasy,代码行数:24,代码来源:TeasyExpectedConditions.java

示例11: stalenessOf

import org.openqa.selenium.support.ui.ExpectedCondition; //导入依赖的package包/类
/**
 * Returns a 'wait' proxy that determines if the specified element reference has gone stale.
 *
 * @param element the element to wait for
 * @return 'false' if the element reference is still valid; otherwise 'true'
 */
public static Coordinator<Boolean> stalenessOf(final WebElement element) {
    return new Coordinator<Boolean>() {
        private final ExpectedCondition<Boolean> condition = conditionInitializer();

        // initializer for [condition] field
        private final ExpectedCondition<Boolean> conditionInitializer() {
            if (element instanceof WrapsElement) {
                return ExpectedConditions.stalenessOf(((WrapsElement) element).getWrappedElement());
            } else {
                return ExpectedConditions.stalenessOf(element);
            }
        }

        @Override
        public Boolean apply(SearchContext ignored) {
            return condition.apply(null);
        }

        @Override
        public String toString() {
            return condition.toString();
        }
    };
}
 
开发者ID:Nordstrom,项目名称:Selenium-Foundation,代码行数:31,代码来源:Coordinators.java

示例12: progress

import org.openqa.selenium.support.ui.ExpectedCondition; //导入依赖的package包/类
public void progress() throws Throwable {
    driver = new JavaDriver();
    final WebElement progressbar = driver.findElement(By.cssSelector("progress-bar"));
    AssertJUnit.assertNotNull("could not find progress-bar", progressbar);
    AssertJUnit.assertEquals("0", progressbar.getAttribute("value"));
    driver.findElement(By.cssSelector("button")).click();

    Wait<WebDriver> wait = new WebDriverWait(driver, 30);
    // Wait for a process to complete
    wait.until(new ExpectedCondition<Boolean>() {
        @Override public Boolean apply(WebDriver webDriver) {
            return progressbar.getAttribute("value").equals("100");
        }
    });

    AssertJUnit.assertEquals("100", progressbar.getAttribute("value"));
    AssertJUnit.assertTrue(driver.findElement(By.cssSelector("text-area")).getText().contains("Done!"));
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:19,代码来源:JProgressBarTest.java

示例13: textToBeEqualsToExpectedValue

import org.openqa.selenium.support.ui.ExpectedCondition; //导入依赖的package包/类
/**
 * Expects that the target element contains the given value as text.
 * The inner text and 'value' attribute of the element is checked.
 *
 * @param locator
 *            is the selenium locator
 * @param value
 *            is the expected value
 * @return true or false
 */
public static ExpectedCondition<Boolean> textToBeEqualsToExpectedValue(final By locator, final String value) {
    return new ExpectedCondition<Boolean>() {
        /**
         * {@inheritDoc}
         */
        @Override
        public Boolean apply(@Nullable WebDriver driver) {
            try {
                WebElement element = driver.findElement(locator);
                if (element != null && value != null) {
                    if (element.getAttribute(VALUE) == null || !value.equals(element.getAttribute(VALUE).trim())) {
                        if (!value.equals(element.getText())) {
                            return false;
                        }
                    }
                    return true;
                }
            } catch (Exception e) {
            }
            return false;
        }
    };
}
 
开发者ID:NoraUi,项目名称:NoraUi,代码行数:34,代码来源:ExpectSteps.java

示例14: atLeastOneOfTheseElementsIsPresent

import org.openqa.selenium.support.ui.ExpectedCondition; //导入依赖的package包/类
public static ExpectedCondition<WebElement> atLeastOneOfTheseElementsIsPresent(final By... locators) {
    return new ExpectedCondition<WebElement>() {
        @Override
        public WebElement apply(@Nullable WebDriver driver) {
            WebElement element = null;
            if (driver != null && locators.length > 0) {
                for (final By b : locators) {
                    try {
                        element = driver.findElement(b);
                    } catch (final Exception e) {
                        continue;
                    }
                }
            }
            return element;
        }
    };
}
 
开发者ID:NoraUi,项目名称:NoraUi,代码行数:19,代码来源:Utilities.java

示例15: visibilityOfNbElementsLocatedBy

import org.openqa.selenium.support.ui.ExpectedCondition; //导入依赖的package包/类
/**
 * An expectation for checking that nb elements present on the web page that match the locator
 * are visible. Visibility means that the elements are not only displayed but also have a height
 * and width that is greater than 0.
 *
 * @param locator
 *            used to find the element
 * @param nb
 *            is exactly number of responses
 * @return the list of WebElements once they are located
 */
public static ExpectedCondition<List<WebElement>> visibilityOfNbElementsLocatedBy(final By locator, final int nb) {
    return new ExpectedCondition<List<WebElement>>() {
        @Override
        public List<WebElement> apply(WebDriver driver) {
            int nbElementIsDisplayed = 0;
            final List<WebElement> elements = driver.findElements(locator);
            for (final WebElement element : elements) {
                if (element.isDisplayed()) {
                    nbElementIsDisplayed++;
                }
            }
            return nbElementIsDisplayed == nb ? elements : null;
        }
    };
}
 
开发者ID:NoraUi,项目名称:NoraUi,代码行数:27,代码来源:Utilities.java


注:本文中的org.openqa.selenium.support.ui.ExpectedCondition类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。