本文整理汇总了Java中org.openqa.selenium.TimeoutException类的典型用法代码示例。如果您正苦于以下问题:Java TimeoutException类的具体用法?Java TimeoutException怎么用?Java TimeoutException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TimeoutException类属于org.openqa.selenium包,在下文中一共展示了TimeoutException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeIgnoringExceptions
import org.openqa.selenium.TimeoutException; //导入依赖的package包/类
private void executeIgnoringExceptions(WebDriver webDriver, WebDriverAction webDriverAction) {
int i = 0;
while (i < dependencies.getMaxRetries()) {
try {
webDriverAction.execute(webDriver, dependencies.getReplayingState(), dependencies.getEventSynchronizer());
return;
} catch (WebDriverException ex) {
logger.error("Could not make it from first try because of {}", ex.toString());
i++;
try {
Thread.sleep(dependencies.getMeasurementsPrecisionMilli());
} catch (InterruptedException e) {
throw dependencies.webDriverActionExecutionException("Interrupted while waiting to retry", e);
}
}
}
throw new TimeoutException("Could not execute the action! " + webDriverAction.getName());
}
示例2: timeoutException
import org.openqa.selenium.TimeoutException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected RuntimeException timeoutException(String message, Throwable lastException) {
TimeoutException ex = new TimeoutException(message, lastException);
ex.addInfo(WebDriverException.DRIVER_INFO, context.getClass().getName());
WebDriver driver = WebDriverUtils.getDriver(context);
if (driver instanceof RemoteWebDriver) {
RemoteWebDriver remote = (RemoteWebDriver) driver;
if (remote.getSessionId() != null) {
ex.addInfo(WebDriverException.SESSION_ID, remote.getSessionId().toString());
}
if (remote.getCapabilities() != null) {
ex.addInfo("Capabilities", remote.getCapabilities().toString());
}
}
throw ex;
}
示例3: waitForElementToAppear
import org.openqa.selenium.TimeoutException; //导入依赖的package包/类
/**
* Wait for element to appear.
*
* @param driver the driver
* @param element the element
* @param logger the logger
*/
public static boolean waitForElementToAppear(WebDriver driver, WebElement element, ExtentTest logger) {
boolean webElementPresence = false;
try {
Wait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver).pollingEvery(2, TimeUnit.SECONDS)
.withTimeout(60, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
fluentWait.until(ExpectedConditions.visibilityOf(element));
if (element.isDisplayed()) {
webElementPresence= true;
}
} catch (TimeoutException toe) {
logger.log(LogStatus.ERROR, "Timeout waiting for webelement to be present<br></br>" + toe.getStackTrace());
} catch (Exception e) {
logger.log(LogStatus.ERROR, "Exception occured<br></br>" + e.getStackTrace());
}
return webElementPresence;
}
示例4: countRowsTable
import org.openqa.selenium.TimeoutException; //导入依赖的package包/类
/**
* Méthode countRowsTable. Prévoir une DIV avant la déclaration du tableau <display:table />.
* @param type
* @param selector
* @return
*/
private int countRowsTable(String type, String selector) throws TimeoutException {
int retour = 0;
try {
By locator = By.cssSelector(".pagebanner");
WebElement pagebanner = wait.until(ExpectedConditions.presenceOfElementLocated(locator));
String pageNumber = pagebanner.getText().trim().split(" ")[0];
if (!pageNumber.equals("Aucun")) {
return Integer.valueOf(pageNumber);
}
} catch (TimeoutException e) {
String pathScreenShot = takeScreenShot();
Assert.fail("countRowsTable impossible ! (type" + type + ", selector" + selector + ")"
+ e.getMessage() + " pathScreenShot=" + pathScreenShot);
}
return retour;
}
示例5: getDocument
import org.openqa.selenium.TimeoutException; //导入依赖的package包/类
RemoteWebElement getDocument() {
int cpt = 0;
while (!isReady) {
cpt++;
if (cpt > 20) {
isReady = true;
throw new TimeoutException("doc not ready.");
}
try {
Thread.sleep(250);
} catch (InterruptedException e) {
log.log(Level.FINE, "", e);
}
}
return document;
}
示例6: retrieveDocumentAndCheckReady
import org.openqa.selenium.TimeoutException; //导入依赖的package包/类
private RemoteWebElement retrieveDocumentAndCheckReady(long deadline) {
RemoteWebElement element = null;
String readyState = "";
while (!readyState.equals("complete")) {
if (deadline > 0 && System.currentTimeMillis() > deadline) {
throw new TimeoutException("Timeout waiting to get the document.");
}
try {
if (element == null) {
element = retrieveDocument();
}
readyState = element.getRemoteObject().call(".readyState");
} catch (WebDriverException e) {
log.info("Caught exception waiting for document to be ready. Retrying...: " + e);
element = null;
}
}
return element;
}
示例7: initialize
import org.openqa.selenium.TimeoutException; //导入依赖的package包/类
/**
* Initializes the instance. Call this method prior to chat interaction.
*/
public void initialize() {
switchToWindow();
this.mDriver.get(CHAT_SERVICE);
final WebElement loginAnchor = new CSSSelectorPresenceWait(this.mDriver, LOGIN_ANCHOR).waitUntilCondition();
try {
loginAnchor.click();
} catch (final TimeoutException e) {
// Ignore the error as it comes from the aborted page load
}
final WebElement outputFrame = new FramePresenceWait(this.mDriver, CHAT_OUTPUT_FRAME_NAME).waitUntilCondition();
final String frameSrc = outputFrame.getAttribute("src");
final Pattern idPattern = Pattern.compile(ID_PATTERN);
final Matcher idMatcher = idPattern.matcher(frameSrc);
if (idMatcher.matches()) {
this.mId = idMatcher.group(1);
}
}
示例8: testLocate_context_timeout
import org.openqa.selenium.TimeoutException; //导入依赖的package包/类
@Test(expected = TimeoutException.class)
public void testLocate_context_timeout() throws Throwable {
//prepare
when(locator.by()).thenReturn(Locator.ByLocator.ID);
when(locator.value()).thenReturn("testId");
when(locator.timeout()).thenReturn(1);
when(webElement.isDisplayed()).thenReturn(false);
when(searchContext.findElement(By.id("testId"))).thenReturn(webElement);
//act
Instant start = Instant.now();
try {
WebElementLocator.locate(searchContext, locator);
} finally {
Duration dur = Duration.between(start, Instant.now());
assertTrue(dur.compareTo(Duration.ofMillis(950)) > 0);
}
}
示例9: convert
import org.openqa.selenium.TimeoutException; //导入依赖的package包/类
/**
* Download the FogBugz attachment, then reupload it to GitHub Issues. If
* the file type is incompatible with GitHub Issues, zip it beforehand.
* Since ZIP files are supported by GitHub Issues, this guarantees that any
* attachment (within size constraints) will be accepted.
*
* @param fogBugz The {@link FogBugz} instance that owns the
* {@link FBAttachment}
* @param fbAttachment The {@link FBAttachment}
* @return URL of the uploaded file
*/
@Override
public String convert(final FogBugz fogBugz, final FBAttachment fbAttachment) {
try {
// Download FogBugz attachment
String filename = fbAttachment.getFilename();
String fbURL = fbAttachment.getAbsoluteUrl(fogBugz);
File temp = FB2GHUtils.createTempFile(filename);
int timeoutInMillis = timeoutInSeconds * 1000;
FileUtils.copyURLToFile(new URL(fbURL), temp, timeoutInMillis, timeoutInMillis);
// Upload to GitHub Issues
return upload(temp);
} catch (IOException | TimeoutException e) {
logger.error("Could not convert: " + fbAttachment.getAbsoluteUrl(fogBugz), e);
return fallback.convert(fogBugz, fbAttachment);
}
}
示例10: waitFor
import org.openqa.selenium.TimeoutException; //导入依赖的package包/类
private List<WebElement> waitFor() {
// When we use complex By strategies (like ChainedBy or ByAll)
// there are some problems (StaleElementReferenceException, implicitly
// wait time out
// for each chain By section, etc)
try {
changeImplicitlyWaitTimeOut(0, TimeUnit.SECONDS);
FluentWait<By> wait = new FluentWait<>(by);
wait.withTimeout(timeOutDuration.getTime(), timeOutDuration.getTimeUnit());
return wait.until(waitingFunction);
} catch (TimeoutException e) {
return new ArrayList<>();
} finally {
changeImplicitlyWaitTimeOut(timeOutDuration.getTime(), timeOutDuration.getTimeUnit());
}
}
示例11: getWithRetry
import org.openqa.selenium.TimeoutException; //导入依赖的package包/类
public <T> T getWithRetry(String url, ExpectedCondition<T> expectedCondition, Long duration, TimeUnit timeUnit, int retryCount, ExpectedCondition retryImmediatelyCondition) {
TimeoutException lastException = null;
RetryImmediateCondition<T> condition = new RetryImmediateCondition<T>(expectedCondition, retryImmediatelyCondition);
for (int ctr = 0; ctr < retryCount; ctr++) {
try {
boolean gotIt = get(url, condition, duration, timeUnit);
if (gotIt && !condition.retry) return condition.ret;
}
catch (TimeoutException ignored) {
lastException = ignored;
}
}
throw lastException;
}
示例12: execute
import org.openqa.selenium.TimeoutException; //导入依赖的package包/类
@Override
protected ExecuteResult execute(final WebSiteConnector connector) {
final WebDriverWait wait = new WebDriverWait(connector.getDriver(), maxWaitTime);
node.setSelector(insertVariableValues(node.getSelector()));
value = insertVariableValues(value);
try {
if (regexp) {
LOGGER.info(LEARNER_MARKER, "Waiting for pattern '{}' to be present in node '{}' for a maximum of " +
"{}ms.", value, node, maxWaitTime);
wait.until(ExpectedConditions.textMatches(node.getBy(), Pattern.compile(value)));
} else {
LOGGER.info(LEARNER_MARKER, "Waiting for text '{}' to be present in node '{}' for a maximum of {}ms.",
value, node, maxWaitTime);
wait.until(ExpectedConditions.textToBePresentInElementLocated(node.getBy(), value));
}
return getSuccessOutput();
} catch (NoSuchElementException | TimeoutException e) {
LOGGER.info(LEARNER_MARKER, "Waiting for text/patter '{}' to be present in node '{}' failed.",
value, node);
return getFailedOutput();
}
}
示例13: setUp
import org.openqa.selenium.TimeoutException; //导入依赖的package包/类
@Before
public void setUp() {
findService = (BIFindService)getApplication().findService();
savedSearchService = getApplication().savedSearchService();
elementFactory = (BIIdolFindElementFactory)getElementFactory();
findPage = elementFactory.getFindPage();
findService.searchAnyView("careful now");
try {
findPage = elementFactory.getFindPage();
findPage.waitUntilSearchTabsLoaded();
savedSearchService.deleteAll();
elementFactory.getConceptsPanel().removeAllConcepts();
} catch(final TimeoutException ignored) {
//no-op
}
elementFactory.getTopicMap().waitForMapLoaded();
}
示例14: shouldExcludeModules
import org.openqa.selenium.TimeoutException; //导入依赖的package包/类
@Test(priority = 1)
public void shouldExcludeModules() {
projectExplorer.openItemByPath(PROJECT_NAME + "/pom.xml");
editor.waitActive();
editor.goToCursorPositionVisible(25, 8);
editor.typeTextIntoEditor("!--");
editor.goToCursorPositionVisible(26, 32);
editor.typeTextIntoEditor("--");
try {
projectExplorer.waitFolderDefinedTypeOfFolderByPath(PROJECT_NAME + "/my-lib", SIMPLE_FOLDER);
} catch (TimeoutException ex) {
// remove try-catch block after issue has been resolved
fail("Known issue https://github.com/eclipse/che/issues/7109");
}
projectExplorer.waitFolderDefinedTypeOfFolderByPath(PROJECT_NAME + "/my-webapp", SIMPLE_FOLDER);
}
示例15: findElement
import org.openqa.selenium.TimeoutException; //导入依赖的package包/类
public WebElement findElement(String label, Browser browser, String id) {
try {
return new WebDriverWait(browser.getWebDriver(), testTimeout, POLLING_LATENCY)
.until(ExpectedConditions.presenceOfElementLocated(By.id(id)));
} catch (TimeoutException e) {
log.warn("Timeout when waiting for element {} to exist in browser {}", id, label);
int originalTimeout = 60;
try {
originalTimeout = browser.getTimeout();
log.debug("Original browser timeout (s): {}, set to 10", originalTimeout);
browser.setTimeout(10);
browser.changeTimeout(10);
WebElement elem = browser.getWebDriver().findElement(By.id(id));
log.info("Additional findElement call was able to locate {} in browser {}", id, label);
return elem;
} catch (NoSuchElementException e1) {
log.debug("Additional findElement call couldn't locate {} in browser {} ({})", id, label,
e1.getMessage());
throw new NoSuchElementException("Element with id='" + id + "' not found after "
+ testTimeout + " seconds in browser " + label);
} finally {
browser.setTimeout(originalTimeout);
browser.changeTimeout(originalTimeout);
}
}
}