Search in sources :

Example 1 with JavascriptActions

use of com.wikia.webdriver.common.core.elemnt.JavascriptActions 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/> &nbsp;</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);
}
Also used : Cookie(org.openqa.selenium.Cookie) JavascriptActions(com.wikia.webdriver.common.core.elemnt.JavascriptActions) User(com.wikia.webdriver.common.core.helpers.User) WikiBasePageObject(com.wikia.webdriver.pageobjectsfactory.pageobject.WikiBasePageObject) Method(java.lang.reflect.Method) WebDriverException(org.openqa.selenium.WebDriverException)

Example 2 with JavascriptActions

use of com.wikia.webdriver.common.core.elemnt.JavascriptActions in project selenium-tests by Wikia.

the class PageObjectLogging method beforeNavigateTo.

@Override
public void beforeNavigateTo(String url, WebDriver driver) {
    new JavascriptActions(driver).execute("window.stop()");
    StringBuilder builder = new StringBuilder();
    builder.append("<tr class=\"success\"><td>Navigate to</td><td>" + "<a href='" + url + "'>" + url + "</a></td><td> <br/> &nbsp;</td></tr>");
    CommonUtils.appendTextToFile(logPath, builder.toString());
    logJSError(driver);
}
Also used : JavascriptActions(com.wikia.webdriver.common.core.elemnt.JavascriptActions)

Example 3 with JavascriptActions

use of com.wikia.webdriver.common.core.elemnt.JavascriptActions in project selenium-tests by Wikia.

the class LightboxTests method mercury_lightbox_PreserveScrollPositionAfterLightboxOpen.

@Test
public void mercury_lightbox_PreserveScrollPositionAfterLightboxOpen() {
    ArticlePage articlePage = new ArticlePage().open("/LightboxTest");
    articlePage.getLightbox().openLightboxImage(0);
    Long startingPosition = new JavascriptActions().getCurrentPosition();
    articlePage.getLightbox().clickCloseButton();
    Long closingPosition = new JavascriptActions().getCurrentPosition();
    Assertion.assertEquals(startingPosition, closingPosition, "Starting scroll position should be " + "the same as closing position");
    Assertion.assertTrue(startingPosition > 0 && closingPosition > 0, "Page shoudln't be scrolled" + "to top");
}
Also used : JavascriptActions(com.wikia.webdriver.common.core.elemnt.JavascriptActions) ArticlePage(com.wikia.webdriver.elements.mercury.pages.ArticlePage) Test(org.testng.annotations.Test)

Example 4 with JavascriptActions

use of com.wikia.webdriver.common.core.elemnt.JavascriptActions in project selenium-tests by Wikia.

the class TestAdsBrowserError method adsScrollHandlerBrowserError.

@Test(groups = "AdsScrollHandlerBrowserError")
public void adsScrollHandlerBrowserError() {
    JavascriptActions jsActions = new JavascriptActions(driver);
    String testPage = urlBuilder.getUrlForPath("project43", "SyntheticTests/UAP");
    testPage = urlBuilder.appendQueryStringToURL(testPage, "scrollhandler=1");
    AdsBaseObject adsBaseObject = new AdsBaseObject(driver);
    adsBaseObject.getUrl(testPage);
    jsActions.addErrorListenerScript();
    jsActions.waitForJavaScriptTruthy("window.scrollY == 0");
    jsActions.scrollBy(0, 5001);
    jsActions.waitForJavaScriptTruthy("window.scrollY != 0");
    Assertion.assertEquals(jsActions.getWindowErrors(), "");
}
Also used : JavascriptActions(com.wikia.webdriver.common.core.elemnt.JavascriptActions) AdsBaseObject(com.wikia.webdriver.pageobjectsfactory.pageobject.adsbase.AdsBaseObject) Test(org.testng.annotations.Test)

Example 5 with JavascriptActions

use of com.wikia.webdriver.common.core.elemnt.JavascriptActions in project selenium-tests by Wikia.

the class NavigationMercuryTests method mercury_navigation_scrollPositionPreservedAfterNavigatingBack.

@Test
public void mercury_navigation_scrollPositionPreservedAfterNavigatingBack() {
    ArticlePage testPage = new ArticlePage().open("/ScrollPreserveTest");
    Long firstPosition = testPage.scrollToLink(0, 200);
    testPage.clickArticleLink(0);
    driver.navigate().back();
    Long secondPosition = new JavascriptActions().getCurrentPosition();
    Assertion.assertEquals(firstPosition, secondPosition, "Scroll position should be preserved " + "after navigating back");
    Assertion.assertTrue(firstPosition > 0 && secondPosition > 0, "Page shoudln't be scrolled " + "to top");
}
Also used : JavascriptActions(com.wikia.webdriver.common.core.elemnt.JavascriptActions) ArticlePage(com.wikia.webdriver.elements.mercury.pages.ArticlePage) Test(org.testng.annotations.Test)

Aggregations

JavascriptActions (com.wikia.webdriver.common.core.elemnt.JavascriptActions)8 Test (org.testng.annotations.Test)3 ArticlePage (com.wikia.webdriver.elements.mercury.pages.ArticlePage)2 AdsBaseObject (com.wikia.webdriver.pageobjectsfactory.pageobject.adsbase.AdsBaseObject)2 User (com.wikia.webdriver.common.core.helpers.User)1 WikiBasePageObject (com.wikia.webdriver.pageobjectsfactory.pageobject.WikiBasePageObject)1 Method (java.lang.reflect.Method)1 Cookie (org.openqa.selenium.Cookie)1 WebDriverException (org.openqa.selenium.WebDriverException)1