本文整理汇总了Java中org.openqa.selenium.WebDriver.Timeouts类的典型用法代码示例。如果您正苦于以下问题:Java Timeouts类的具体用法?Java Timeouts怎么用?Java Timeouts使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Timeouts类属于org.openqa.selenium.WebDriver包,在下文中一共展示了Timeouts类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: waitOverridingImplicitWait
import org.openqa.selenium.WebDriver.Timeouts; //导入依赖的package包/类
/**
* If there is an implicit wait set, then you might need to wait for a shorter period. This
* method makes it possible with setting the implicit wait temporarily to 0.
*
* @param webDriver webdriver to be used
* @param seconds timeout in seconds
* @return a {@link Wait} instance, which set the implicit wait temporarily to 0.
*/
public Wait<WebDriver> waitOverridingImplicitWait(WebDriver webDriver, int seconds) {
//API comes from selenium -> cannot migrate guava to java 8
//noinspection Guava
return new Wait<WebDriver>() {
@Override
public <T> T until(Function<? super WebDriver, T> function) {
Timeouts timeouts = webDriver.manage().timeouts();
try {
timeouts.implicitlyWait(0, TimeUnit.SECONDS);
return new WebDriverWait(webDriver, seconds, CONDITION_POLL_INTERVAL).until(function);
} finally {
timeouts.implicitlyWait(implicitWait.getNano(), TimeUnit.NANOSECONDS);
}
}
};
}
示例2: setDriverTimeouts
import org.openqa.selenium.WebDriver.Timeouts; //导入依赖的package包/类
/**
* Set configured timeout intervals in the specified driver.
*
* @param driver driver object in which to configure timeout intervals
* @param config configuration object that specifies timeout intervals
*/
public static void setDriverTimeouts(WebDriver driver, SeleniumConfig config) {
Timeouts timeouts = driver.manage().timeouts();
timeouts.setScriptTimeout(WaitType.SCRIPT.getInterval(config), TimeUnit.SECONDS);
timeouts.implicitlyWait(WaitType.IMPLIED.getInterval(config), TimeUnit.SECONDS);
timeouts.pageLoadTimeout(WaitType.PAGE_LOAD.getInterval(config), TimeUnit.SECONDS);
}
示例3: postConstruct
import org.openqa.selenium.WebDriver.Timeouts; //导入依赖的package包/类
@Override
public void postConstruct(D webDriver) {
Timeouts timeouts = webDriver.manage().timeouts();
if (implicitWait != null) {
timeouts.implicitlyWait(implicitWait.getSeconds(), TimeUnit.SECONDS);
}
if (scriptTimeout != null) {
timeouts.setScriptTimeout(scriptTimeout.getSeconds(), TimeUnit.SECONDS);
}
if (pageLoadTimeout != null) {
timeouts.pageLoadTimeout(pageLoadTimeout.getSeconds(), TimeUnit.SECONDS);
}
}
示例4: acquireReference
import org.openqa.selenium.WebDriver.Timeouts; //导入依赖的package包/类
/**
* Acquire the element reference that's wrapped by the specified robust element wrapper.
*
* @param wrapper robust element wrapper
* @return wrapped element reference
*/
private static RobustElementWrapper acquireReference(RobustElementWrapper wrapper) {
SearchContext context = wrapper.context.getWrappedContext();
if (wrapper.strategy == Strategy.LOCATOR) {
Timeouts timeouts = wrapper.driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
try {
if (wrapper.index > 0) {
List<WebElement> elements = context.findElements(wrapper.locator);
if (wrapper.index < elements.size()) {
wrapper.wrapped = elements.get(wrapper.index);
} else {
throw new NoSuchElementException(
String.format("Too few elements located %s: need: %d; have: %d",
wrapper.locator, wrapper.index + 1, elements.size()));
}
} else {
wrapper.wrapped = context.findElement(wrapper.locator);
}
} catch (NoSuchElementException e) {
if (wrapper.index != OPTIONAL) {
throw e;
}
wrapper.deferredException = e;
wrapper.wrapped = null;
} finally {
timeouts.implicitlyWait(WaitType.IMPLIED.getInterval(), TimeUnit.SECONDS);
}
} else {
List<Object> args = new ArrayList<>();
List<WebElement> contextArg = new ArrayList<>();
if (context instanceof WebElement) {
contextArg.add((WebElement) context);
}
String js;
args.add(contextArg);
args.add(wrapper.selector);
if (wrapper.strategy == Strategy.JS_XPATH) {
js = LOCATE_BY_XPATH;
} else {
js = LOCATE_BY_CSS;
args.add(wrapper.index);
}
wrapper.wrapped = JsUtility.runAndReturn(wrapper.driver, js, args.toArray());
}
if (wrapper.wrapped != null) {
wrapper.acquiredAt = System.currentTimeMillis();
wrapper.deferredException = null;
}
return wrapper;
}
示例5: testWaitFixedTime
import org.openqa.selenium.WebDriver.Timeouts; //导入依赖的package包/类
@Test
public void testWaitFixedTime() {
final Options options = mockDriver.manage();
Mockito.when(options.timeouts()).thenReturn(Mockito.mock(Timeouts.class));
waitFixedTime();
}
示例6: assertElementNotFound
import org.openqa.selenium.WebDriver.Timeouts; //导入依赖的package包/类
protected void assertElementNotFound(String message, String cssPath) {
Timeouts timeouts = wd.manage().timeouts();
timeouts.implicitlyWait(NO_ELEMENT_WAIT, TimeUnit.MILLISECONDS);
assertEquals(message, 0, find(cssPath).size());
timeouts.implicitlyWait(IMPLICITLY_WAIT, TimeUnit.MILLISECONDS);
}
示例7: setTimeouts
import org.openqa.selenium.WebDriver.Timeouts; //导入依赖的package包/类
final public void setTimeouts(Integer pageLoad, Integer script) {
Timeouts timeOuts = driver.manage().timeouts();
timeOuts.pageLoadTimeout(pageLoad, TimeUnit.SECONDS);
timeOuts.setScriptTimeout(script, TimeUnit.SECONDS);
}
示例8: configure
import org.openqa.selenium.WebDriver.Timeouts; //导入依赖的package包/类
@Override
public void configure(Config conf) {
super.configure(conf);
// see https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true);
String userAgentString = getAgentString(conf);
// custom capabilities
Map<String, Object> confCapabilities = (Map<String, Object>) conf
.get("selenium.capabilities");
if (confCapabilities != null) {
Iterator<Entry<String, Object>> iter = confCapabilities.entrySet()
.iterator();
while (iter.hasNext()) {
Entry<String, Object> entry = iter.next();
Object val = entry.getValue();
// substitute variable $useragent for the real value
if (val instanceof String
&& "$useragent".equalsIgnoreCase(val.toString())) {
val = userAgentString;
}
capabilities.setCapability(entry.getKey(), entry.getValue());
}
}
// number of instances to create per connection
// https://github.com/DigitalPebble/storm-crawler/issues/505
int numInst = ConfUtils.getInt(conf, "selenium.instances.num", 1);
// load adresses from config
List<String> addresses = ConfUtils.loadListFromConf(
"selenium.addresses", conf);
if (addresses.size() == 0) {
throw new RuntimeException("No value found for selenium.addresses");
}
try {
for (String cdaddress : addresses) {
for (int inst = 0; inst < numInst; inst++) {
RemoteWebDriver driver = new RemoteWebDriver(new URL(
cdaddress), capabilities);
Timeouts touts = driver.manage().timeouts();
int implicitWait = ConfUtils.getInt(conf,
"selenium.implicitlyWait", 0);
int pageLoadTimeout = ConfUtils.getInt(conf,
"selenium.pageLoadTimeout", -1);
int setScriptTimeout = ConfUtils.getInt(conf,
"selenium.setScriptTimeout", 0);
touts.implicitlyWait(implicitWait, TimeUnit.MILLISECONDS);
touts.pageLoadTimeout(pageLoadTimeout,
TimeUnit.MILLISECONDS);
touts.setScriptTimeout(setScriptTimeout,
TimeUnit.MILLISECONDS);
drivers.add(driver);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例9: implicitWait
import org.openqa.selenium.WebDriver.Timeouts; //导入依赖的package包/类
public static WebDriver implicitWait(WebDriver webDriver) {
Options webDriverOptions = webDriver.manage();
Timeouts timeouts = webDriverOptions.timeouts();
timeouts.implicitlyWait(30, TimeUnit.SECONDS);
return webDriver;
}