Search in sources :

Example 21 with WebDriverException

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));
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) WebDriverException(org.openqa.selenium.WebDriverException)

Example 22 with WebDriverException

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);
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) HttpResponse(org.apache.http.HttpResponse) Gson(com.google.gson.Gson) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 23 with WebDriverException

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);
}
Also used : AdsComparison(com.wikia.webdriver.pageobjectsfactory.pageobject.adsbase.helpers.AdsComparison) WebDriverException(org.openqa.selenium.WebDriverException)

Example 24 with WebDriverException

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);
        }
    }
}
Also used : Dimension(org.openqa.selenium.Dimension) Assertion(com.wikia.webdriver.common.core.Assertion) By(org.openqa.selenium.By) WebDriver(org.openqa.selenium.WebDriver) WebDriverException(org.openqa.selenium.WebDriverException) WebElement(org.openqa.selenium.WebElement) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) PageObjectLogging(com.wikia.webdriver.common.logging.PageObjectLogging) List(java.util.List) Assert(org.testng.Assert) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) By(org.openqa.selenium.By) Dimension(org.openqa.selenium.Dimension) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) IOException(java.io.IOException) WebElement(org.openqa.selenium.WebElement) File(java.io.File) WebDriverException(org.openqa.selenium.WebDriverException)

Example 25 with WebDriverException

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);
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) WebDriverException(org.openqa.selenium.WebDriverException)

Aggregations

WebDriverException (org.openqa.selenium.WebDriverException)28 IOException (java.io.IOException)16 File (java.io.File)8 Matcher (java.util.regex.Matcher)4 URISyntaxException (java.net.URISyntaxException)3 Pattern (java.util.regex.Pattern)3 ClientProtocolException (org.apache.http.client.ClientProtocolException)3 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 Gson (com.google.gson.Gson)2 TypeToken (com.google.gson.reflect.TypeToken)2 User (com.wikia.webdriver.common.core.helpers.User)2 AdsComparison (com.wikia.webdriver.pageobjectsfactory.pageobject.adsbase.helpers.AdsComparison)2 BufferedImage (java.awt.image.BufferedImage)2 Method (java.lang.reflect.Method)2 URL (java.net.URL)2 NoSuchElementException (java.util.NoSuchElementException)2 HttpResponse (org.apache.http.HttpResponse)2 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpPost (org.apache.http.client.methods.HttpPost)2