本文整理汇总了Java中org.openqa.selenium.WebDriverException类的典型用法代码示例。如果您正苦于以下问题:Java WebDriverException类的具体用法?Java WebDriverException怎么用?Java WebDriverException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebDriverException类属于org.openqa.selenium包,在下文中一共展示了WebDriverException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: embedScreenshot
import org.openqa.selenium.WebDriverException; //导入依赖的package包/类
@After
public void embedScreenshot(Scenario scenario) {
try {
if (!scenario.isFailed()) {
// Take a screenshot only in the failure case
return;
}
String webDriverType = System.getProperty("WebDriverType");
if (!webDriverType.equals("HtmlUnit")) {
// HtmlUnit does not support screenshots
byte[] screenshot = getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
}
} catch (WebDriverException somePlatformsDontSupportScreenshots) {
scenario.write(somePlatformsDontSupportScreenshots.getMessage());
}
}
示例2: executeIgnoringExceptions
import org.openqa.selenium.WebDriverException; //导入依赖的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());
}
示例3: timeoutException
import org.openqa.selenium.WebDriverException; //导入依赖的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;
}
示例4: getAgentJar
import org.openqa.selenium.WebDriverException; //导入依赖的package包/类
public String getAgentJar() {
String prefix = launchType.getPrefix();
if (System.getenv(MARATHON_AGENT + ".file") != null) {
return System.getenv(MARATHON_AGENT + ".file");
}
if (System.getProperty(MARATHON_AGENT + ".file") != null) {
return System.getProperty(MARATHON_AGENT + ".file");
}
String path = findFile(new String[] { ".", "marathon-" + prefix + "-agent", "../marathon-" + prefix + "-agent",
"../../marathonv4/marathon-" + prefix + "/marathon-" + prefix + "-agent", System.getProperty(PROP_HOME, "."),
dirOfMarathonJavaDriverJar }, "marathon-" + prefix + "-agent.*.jar");
if (path != null) {
Logger.getLogger(JavaProfile.class.getName()).info("Using " + path + " for agent");
return path;
}
throw new WebDriverException("Unable to find marathon-agent.jar. Set " + MARATHON_AGENT + ".file"
+ " environment variable to point to the jar file: " + new File(".").getAbsolutePath());
}
示例5: runTest
import org.openqa.selenium.WebDriverException; //导入依赖的package包/类
@Override
protected void runTest() throws Throwable {
try {
// check whether DTM has been loaded on the page
Object response = _page
.executeJavaScript("(typeof Visitor !== 'undefined') ? Visitor.version : 'unavailable'")
.getJavaScriptResult();
// make sure the element exists
if (String.class.isAssignableFrom(response.getClass()) && !((String) response).equals("unavailable")) {
boolean result = Tools.testVersionNotOlderThanBaseVersion((String) response, _minVersion);
assertTrue(Tools.MCVID + " min version should be " + _minVersion, result);
} else {
fail(Tools.MCVID + " version not available");
}
} catch (WebDriverException we) {
fail(Tools.MCVID + " not found");
}
}
示例6: getArtifact
import org.openqa.selenium.WebDriverException; //导入依赖的package包/类
/**
* Produce page source from the specified driver.
*
* @param optDriver optional web driver object
* @param reason impetus for capture request; may be 'null'
* @param logger SLF4J logger object
* @return page source; if capture fails, an empty string is returned
*/
public static String getArtifact(Optional<WebDriver> optDriver, Throwable reason, Logger logger) {
if (canGetArtifact(optDriver, logger)) {
try {
WebDriver driver = optDriver.get();
StringBuilder sourceBuilder = new StringBuilder(driver.getPageSource());
insertBaseElement(sourceBuilder, driver);
insertBreakpointInfo(sourceBuilder, reason);
insertOriginalUrl(sourceBuilder, driver);
return sourceBuilder.toString();
} catch (WebDriverException e) {
logger.warn("The driver is capable of producing page source, but failed.", e);
}
}
return "";
}
示例7: ifTooManyAttemtpsActionTimesOut
import org.openqa.selenium.WebDriverException; //导入依赖的package包/类
@Test
public void ifTooManyAttemtpsActionTimesOut() throws IOException, URISyntaxException {
int maxRetries = 3;
ActionExecutor webDriverActionExecutionBase = getWebDriverActionExecutionBase(10, maxRetries);
Iterator<WebDriverAction> webDriverActionIterator = mock(Iterator.class);
TestScenarioActions testScenarioSteps = mock(TestScenarioActions.class);
when(testScenarioSteps.iterator()).thenReturn(webDriverActionIterator);
TestScenario testScenario = mock(TestScenario.class);
when(testScenario.steps()).thenReturn(testScenarioSteps);
when(webDriverActionIterator.hasNext()).thenReturn(true, false);
WebDriverAction firstAction = mock(WebDriverAction.class);
doThrow(new WebDriverException("Exception occured!")).when(firstAction).execute(any(), any(), any());
when(webDriverActionIterator.next()).thenReturn(firstAction);
ExecutionReport report = webDriverActionExecutionBase.execute(testScenario);
assertEquals(AutomationResult.TIMEOUT, report.getAutomationResult());
verify(firstAction, times(maxRetries)).execute(any(), any(), any());
}
示例8: afterTest
import org.openqa.selenium.WebDriverException; //导入依赖的package包/类
/**
* <p>
* Takes screen-shot if the scenario fails
* </p>
*
* @param scenario will be the individual scenario's within the Feature files
* @throws InterruptedException Exception thrown if there is an interuption within the JVM
*/
@After()
public void afterTest(Scenario scenario) throws InterruptedException {
LOG.info("Taking screenshot IF Test Failed");
System.out.println("Taking screenshot IF Test Failed (sysOut)");
if (scenario.isFailed()) {
try {
System.out.println("Scenario FAILED... screen shot taken");
scenario.write(getDriver().getCurrentUrl());
byte[] screenShot = ((TakesScreenshot) getDriver()).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenShot, "image/png");
} catch (WebDriverException e) {
LOG.error(e.getMessage());
}
}
}
示例9: executeJavascript
import org.openqa.selenium.WebDriverException; //导入依赖的package包/类
private void executeJavascript(String imagePlaceholderId) {
frameSwitcher.switchTo("/");
JavascriptExecutor js = (JavascriptExecutor) webDriver;
LOG.debug("executing javascript with argument: '{}'", imagePlaceholderId);
bobcatWait.withTimeout(Timeouts.MEDIUM).until(driver -> {
boolean executedSuccessfully = false;
do {
try {
String javaScript = getJavascriptToExecute();
js.executeScript(javaScript, imagePlaceholderId);
executedSuccessfully = true;
} catch (WebDriverException wde) {
LOG.warn("error while executing JavaScript: '{}'", wde.getMessage(), wde);
} catch (IOException ioe) {
String msg = "error while loading JavaScript from file: " + IMAGE_SETTER_JS_FILENAME;
LOG.error(msg, ioe);
throw new BobcatRuntimeException(msg);
}
} while (!executedSuccessfully);
return executedSuccessfully;
}, DELAY_BEFORE_RETRY_IN_SECONDS);
frameSwitcher.switchBack();
}
示例10: runTest
import org.openqa.selenium.WebDriverException; //导入依赖的package包/类
@Override
protected void runTest() throws Throwable {
try {
// sleep
Thread.sleep(_delay);
// get the value of the dl element from the page
Object response = _page.executeJavaScript(_elementName).getJavaScriptResult();
// make sure the element exists
if (String.class.isAssignableFrom(response.getClass())) {
assertEquals("Data Layer element " + _elementName + " value should be " + _elementExpectedValue
+ "after " + _delay + "ms", _elementExpectedValue, (String) response);
} else {
fail("Data Layer element " + _elementName + " does not exist");
}
} catch (WebDriverException we) {
fail("Data Layer element " + _elementName + " does not exist");
}
}
开发者ID:janexner,项目名称:site-infrastructure-tests,代码行数:21,代码来源:DataLayerElementDelayedValueTestCase.java
示例11: runTest
import org.openqa.selenium.WebDriverException; //导入依赖的package包/类
@Override
protected void runTest() throws Throwable {
// wait
Thread.sleep(_milliseconds);
try {
// get the value of the dl element from the page
Object response = _page.executeJavaScript("(typeof " + _elementName + " !== 'undefined')")
.getJavaScriptResult();
// make sure the element exists
if (Boolean.class.isAssignableFrom(response.getClass())) {
assertTrue("Data Layer element " + _elementName + " must exist after " + _milliseconds + "ms",
(Boolean) response);
} else {
fail("Data Layer element " + _elementName + " does not exist");
}
} catch (WebDriverException we) {
fail("Data Layer element " + _elementName + " does not exist");
}
}
开发者ID:janexner,项目名称:site-infrastructure-tests,代码行数:23,代码来源:DataLayerElementDelayedExistsTestCase.java
示例12: runTest
import org.openqa.selenium.WebDriverException; //导入依赖的package包/类
@Override
protected void runTest() throws Throwable {
try {
// sleep
Thread.sleep(_delay);
// get the value of the dl element from the page
Object response = _page.executeJavaScript(_elementName).getJavaScriptResult();
// make sure the element exists
if (Long.class.isAssignableFrom(response.getClass())) {
assertEquals("Data Layer element " + _elementName + " numeric value should be " + _elementExpectedValue
+ "after " + _delay + "ms", _elementExpectedValue, (Long) response);
} else {
fail("Data Layer element " + _elementName + " does not exist");
}
} catch (WebDriverException we) {
fail("Data Layer element " + _elementName + " does not exist");
}
}
开发者ID:janexner,项目名称:site-infrastructure-tests,代码行数:21,代码来源:DataLayerNumericElementDelayedValueTestCase.java
示例13: ajaxCompleted
import org.openqa.selenium.WebDriverException; //导入依赖的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 + "'";
}
};
}
示例14: isPresent
import org.openqa.selenium.WebDriverException; //导入依赖的package包/类
public boolean isPresent() {
if (StringUtils.isNotBlank(id) && id != "-1" && cacheable) {
return true;
}
try {
List<WebElement> eles = null;
if ((parentElement != null)) {
if (!parentElement.isPresent()) {
return false;
}
eles = parentElement.findElements(getBy());
} else {
eles = getWrappedDriver().findElements(getBy());
}
if ((eles != null) && (eles.size() > 0)) {
if (StringUtils.isBlank(id)) {
id = ((QAFExtendedWebElement) eles.get(0)).id;
}
return true;
}
return false;
} catch (WebDriverException e) {
return false;
}
}
示例15: waitForIndex
import org.openqa.selenium.WebDriverException; //导入依赖的package包/类
public void waitForIndex(final int index) {
new QAFWebDriverWait()
.withMessage(String.format("Wait timeout for list of %s with size %d",
description, index + 1))
.until(new ExpectedCondition<QAFExtendedWebDriver, Boolean>() {
@SuppressWarnings("unchecked")
@Override
public Boolean apply(QAFExtendedWebDriver driver) {
try {
clear();
addAll((Collection<T>) context.findElements(by));
return size() > index;
} catch (WebDriverException e) {
return false;
}
}
});
}