use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.
the class ImageGenerator method generateImageWithRandomText.
/**
* Generates unique 200x200(px) .png image, with random text in its center
*/
public void generateImageWithRandomText() {
int fontStyle = Font.BOLD;
int fontSize = 20;
int textLength = 16;
String fontName = "TimesRoman";
String imageExtension = "png";
String imageText = getRandomText(textLength);
Color fontColor = Color.BLUE;
this.imagePath = imageFolder + "random_image." + imageExtension;
String actionName = "generate random image";
String actionDescription = "generated image with random text: " + imageText;
Graphics2D g2 = imageBuffer.createGraphics();
g2.setPaint(fontColor);
Font font = new Font(fontName, fontStyle, fontSize);
g2.setFont(font);
FontMetrics fontMetrics = g2.getFontMetrics();
int stringWidth = fontMetrics.stringWidth(imageText);
// Draw the text in the middle of the image
g2.drawString(imageText, (imageWidth - stringWidth) / 2, imageHeight / 2);
try {
if (ImageIO.write(imageBuffer, imageExtension, new File(imagePath))) {
PageObjectLogging.logOnLowLevel(actionName, actionDescription, true);
}
} catch (IOException e) {
throw new WebDriverException(ExceptionUtils.getStackTrace(e));
}
}
use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.
the class GraphApi method deleteFacebookTestUser.
public HashMap<String, String> deleteFacebookTestUser(String userId) {
try {
HttpResponse response = deleteTestUser(userId);
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 AdsBaseObject method verifyExpandedAdVisibleInSlot.
public void verifyExpandedAdVisibleInSlot(String slotSelector, WebElement slot) {
waitForSlotExpanded(slot);
boolean adVisible = new AdsComparison().isAdVisible(slot, slotSelector, driver);
extractGptInfo(slotSelector);
if (!adVisible) {
throw new WebDriverException("Ad is not present in " + slotSelector);
}
PageObjectLogging.log("ScreenshotsComparison", "Ad is present in " + slotSelector, true);
}
use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.
the class AdsRecoveryObject method verifyPageFairRecoveryWithAdBlock.
public void verifyPageFairRecoveryWithAdBlock() {
By spansBodyChildrenSelector = By.cssSelector("body>span");
Dimension topLeaderboardSize = new Dimension(728, 90);
Dimension medrecSize = new Dimension(300, 250);
String expectedRecoveredLB;
String expectedRecoveredMR;
try {
expectedRecoveredLB = readFileToString(new File(EXPECTED_TOP_LEADERBOARD_PATH));
expectedRecoveredMR = readFileToString(new File(EXPECTED_MEDREC_PATH));
} catch (IOException e) {
PageObjectLogging.log("Can't open expected PageFair recovery file.", e, false);
throw new WebDriverException("Can't open expected PageFair recovery file.");
}
// when PF recovered ad is on page, inserts span elements as a direct children of body
wait.forElementPresent(spansBodyChildrenSelector);
// verify that adblock is turned on on that page
verifyNoAdsOnPage();
String firstSpanClass = driver.findElement(spansBodyChildrenSelector).getAttribute("class");
List<WebElement> recoveredAds = driver.findElements(By.cssSelector("body>span." + firstSpanClass)).stream().filter(WebElement::isDisplayed).filter(e -> e.getCssValue("background").contains("data:image/jpeg")).collect(Collectors.toList());
Assert.assertEquals(recoveredAds.size(), RECOVERABLE_ADS_COUNT);
for (WebElement ad : recoveredAds) {
Dimension adSize = ad.getSize();
if (adSize.equals(topLeaderboardSize)) {
Assertion.assertTrue(ad.getCssValue("background").contains(expectedRecoveredLB), "TOP_LEADERBOARD is not correctly recovered!");
} else if (adSize.equals(medrecSize)) {
Assertion.assertTrue(ad.getCssValue("background").contains(expectedRecoveredMR), "MEDREC is not correctly recovered!");
} else {
Assertion.fail("Not supported PageFair recovery ad size encountered: " + adSize);
}
}
}
use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.
the class EmailUtils method getActivationLinkFromEmailContent.
public static String getActivationLinkFromEmailContent(String mailContent) {
// mail content contain '=' chars, which has to be removed
String content = mailContent.replace("=", "");
// mail content contain 'upn3D' chars, which has to be changed to 'upn='
content = content.replace("upn3D", "upn=");
// getting activation URL
Pattern p = Pattern.compile("button\" href3D\"http[\\s\\S]*?(?=\")");
// from mail content
Matcher m = p.matcher(content);
if (m.find()) {
return m.group(0).replace("button\" href3D\"", "");
// m.group(0) returns first match for the regexp
} else {
throw new WebDriverException("There was no match in the following content: \n" + content);
}
}
Aggregations