use of org.openqa.selenium.WebDriverException in project zeppelin by apache.
the class ScreenCaptureHtmlUnitDriver method getScreenshotAs.
@Override
@SuppressWarnings("unchecked")
public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
byte[] archive = new byte[0];
try {
archive = downloadCssAndImages(getWebClient(), (HtmlPage) getCurrentWindow().getEnclosedPage());
} catch (Exception e) {
LOGGER.error("Exception in ScreenCaptureHtmlUnitDriver while getScreenshotAs ", e);
}
if (target.equals(OutputType.BASE64)) {
return target.convertFromBase64Png(new Base64Encoder().encode(archive));
}
if (target.equals(OutputType.FILE)) {
File f = new File("screen.tmp");
try {
FileOutputStream scr = new FileOutputStream(f);
scr.write(archive);
scr.close();
} catch (IOException e) {
throw new WebDriverException(e);
}
return (X) f;
}
return (X) archive;
}
use of org.openqa.selenium.WebDriverException in project sonarqube by SonarSource.
the class Retry method execute.
<T> void execute(Supplier<Optional<T>> target, Consumer<T> action) {
WebDriverException lastError = null;
boolean retried = false;
long start = System.currentTimeMillis();
while ((System.currentTimeMillis() - start) < timeoutInMs) {
try {
Optional<T> targetElement = target.get();
if (targetElement.isPresent()) {
action.accept(targetElement.get());
if (retried) {
System.out.println();
}
return;
}
} catch (StaleElementReferenceException e) {
// ignore
} catch (WebDriverException e) {
lastError = e;
}
retried = true;
System.out.print(".");
}
if (retried) {
System.out.println();
}
if (lastError != null) {
throw lastError;
}
throw new NoSuchElementException("Not found");
}
use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.
the class GraphApi method createFacebookTestUser.
public HashMap<String, String> createFacebookTestUser(String appId) {
try {
HttpResponse response = createTestUser(appId);
String entity = EntityUtils.toString(response.getEntity());
return new Gson().fromJson(entity, new TypeToken<HashMap<String, String>>() {
}.getType());
} catch (IOException e) {
PageObjectLogging.log(URI_SYNTAX_EXCEPTION, ExceptionUtils.getStackTrace(e), false);
throw new WebDriverException(ERROR_MESSAGE);
} catch (URISyntaxException e) {
PageObjectLogging.log(URI_SYNTAX_EXCEPTION, ExceptionUtils.getStackTrace(e), false);
throw new WebDriverException(ERROR_MESSAGE);
}
}
use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.
the class PageObjectLogging method afterNavigateTo.
@Override
public void afterNavigateTo(String url, WebDriver driver) {
StringBuilder builder = new StringBuilder();
if (!AlertHandler.isAlertPresent(driver)) {
if (url.equals(driver.getCurrentUrl())) {
builder.append("<tr class=\"success\"><td>Url after navigation</td><td>" + "<a href='" + driver.getCurrentUrl() + "'>" + driver.getCurrentUrl() + "</a></td><td> <br/> </td></tr>");
CommonUtils.appendTextToFile(logPath, builder.toString());
} else {
if (driver.getCurrentUrl().contains("data:text/html,chromewebdata ")) {
driver.get(url);
}
logWarning("Url after navigation", driver.getCurrentUrl());
}
} else {
logWarning("Url after navigation", "Unable to check URL after navigation - alert present");
}
if (driver.getCurrentUrl().contains(Configuration.getWikiaDomain())) {
// HACK FOR DISABLING NOTIFICATIONS
try {
new JavascriptActions(driver).execute("$(\".sprite.close-notification\")[0].click()");
} catch (WebDriverException e) {
}
/**
* We want to disable sales pitch dialog for new potential contributors to avoid hiding other
* UI elements. see https://wikia-inc.atlassian.net/browse/CE-3768
*/
if ("true".equals(Configuration.getDisableCommunityPageSalesPitchDialog())) {
driver.manage().addCookie(new Cookie("cpBenefitsModalShown", "1", Configuration.getWikiaDomain(), null, null));
}
if (TestContext.isFirstLoad() && "true".equals(Configuration.getMockAds())) {
driver.manage().addCookie(new Cookie("mock-ads", XMLReader.getValue("mock.ads_token"), String.format(".%s", Configuration.getEnvType().getWikiaDomain()), null, null));
}
}
Method method = TestContext.getCurrentTestMethod();
Class<?> declaringClass = method.getDeclaringClass();
if (TestContext.isFirstLoad()) {
User user = null;
TestContext.setFirstLoad(false);
if (declaringClass.isAnnotationPresent(Execute.class)) {
user = declaringClass.getAnnotation(Execute.class).asUser();
}
if (method.isAnnotationPresent(Execute.class)) {
user = method.getAnnotation(Execute.class).asUser();
}
if (user != null && user != User.ANONYMOUS) {
// log in, make sure user is logged in and flow is on the requested url
new WikiBasePageObject().loginAs(user);
}
}
logJSError(driver);
}
use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.
the class ImageComparison method areFilesTheSame.
/**
* Compare two images after converting them into byte arrays
*
* @param file1 - file containing first image
* @param file2 - file containing second image
* @return boolean - if images are the same
*/
public boolean areFilesTheSame(File file1, File file2) {
byte[] fileInBytes1;
byte[] fileInBytes2;
try {
fileInBytes1 = FileUtils.readFileToByteArray(file1);
fileInBytes2 = FileUtils.readFileToByteArray(file2);
} catch (IOException e) {
throw new WebDriverException(e);
}
return Arrays.equals(fileInBytes1, fileInBytes2);
}
Aggregations