Search in sources :

Example 1 with User

use of com.wikia.webdriver.common.core.helpers.User 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 User

use of com.wikia.webdriver.common.core.helpers.User in project selenium-tests by Wikia.

the class BrowserAndTestEventListener method afterNavigateTo.

@Override
public void afterNavigateTo(String url, WebDriver driver) {
    Method method = TestContext.getCurrentTestMethod();
    if (method != null) {
        Class<?> declaringClass = method.getDeclaringClass();
        String cookieDomain = String.format(".%s", Configuration.getEnvType().getDomain(driver.getCurrentUrl()));
        Date cookieDate = new Date(new DateTime().plusYears(10).getMillis());
        if (!AlertHandler.isAlertPresent(driver)) {
            String command = "Url after navigation";
            if (url.equals(driver.getCurrentUrl())) {
                Log.ok(command, VelocityWrapper.fillLink(driver.getCurrentUrl(), driver.getCurrentUrl()));
            } else {
                // A fast lane to stop executing any test on "not a valid community" page
                if (driver.getCurrentUrl().contains(URLsContent.NOT_A_VALID_COMMUNITY)) {
                    throw new SkipException(String.format("Wrong redirect to: %s", driver.getCurrentUrl()));
                }
                if (driver.getCurrentUrl().contains("data:text/html,chromewebdata ")) {
                    driver.get(url);
                    Log.warning(command, driver.getCurrentUrl());
                } else {
                    Log.warning(command, driver.getCurrentUrl());
                }
            }
        } else {
            Log.warning("Url after navigation", "Unable to check URL after navigation - alert present");
        }
        boolean reload = false;
        if (driver.getCurrentUrl().contains(cookieDomain)) {
            // HACK FOR DISABLING NOTIFICATIONS
            try {
                new JavascriptActions(driver).execute("$('.wds-banner-notification__close').click()");
                new JavascriptActions(driver).execute("$('#WikiaNotifications .sprite.close-notification').click()");
            } catch (WebDriverException e) {
                Log.info("Hack for disabling notifications", "Failed to execute js action");
            }
            if (TestContext.isFirstLoad()) {
                boolean userOptedIn = true;
                boolean userOptedOut = false;
                try {
                    JavascriptExecutor js = DriverProvider.getActiveDriver();
                    Object mobileWikiVersion = js.executeScript("return requirejs.entries['mobile-wiki/config/environment'].module.exports.default.APP.version");
                    Configuration.setTestValue("mobileWikiVersion", mobileWikiVersion.toString());
                } catch (WebDriverException e) {
                    Configuration.setTestValue("mobileWikiVersion", null);
                }
                if (method.isAnnotationPresent(Execute.class) && !method.getAnnotation(Execute.class).trackingOptIn()) {
                    userOptedIn = false;
                }
                if (method.isAnnotationPresent(Execute.class) && method.getAnnotation(Execute.class).trackingOptOut()) {
                    userOptedOut = true;
                }
                String cmpVersion = "2";
                if (userOptedIn) {
                    driver.manage().addCookie(new Cookie("tracking-opt-in-status", "accepted", cookieDomain, "/", cookieDate));
                    driver.manage().addCookie(new Cookie("tracking-opt-in-version", cmpVersion, cookieDomain, "/", cookieDate));
                    reload = true;
                } else if (userOptedOut) {
                    driver.manage().addCookie(new Cookie("tracking-opt-in-status", "rejected", cookieDomain, "/", cookieDate));
                    driver.manage().addCookie(new Cookie("tracking-opt-in-version", cmpVersion, cookieDomain, "/", cookieDate));
                    reload = true;
                }
            }
            /**
             * 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 (TestContext.isFirstLoad() && "true".equals(Configuration.getDisableCommunityPageSalesPitchDialog())) {
                driver.manage().addCookie(new Cookie("cpBenefitsModalShown", "1", cookieDomain, "/", cookieDate));
                reload = true;
            }
            if (TestContext.isFirstLoad() && "true".equals(Configuration.getMockAds())) {
                driver.manage().addCookie(new Cookie("mock-ads", XMLReader.getValue("mock.ads_token"), cookieDomain, "/", cookieDate));
                reload = true;
                Log.info(String.format("Adding moc-ads cookie with value: %s, and domain: %s", XMLReader.getValue("mock.ads_token"), String.format(".%s", Configuration.getEnvType().getDomain(driver.getCurrentUrl()))));
            }
        }
        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);
            }
            NetworkTrafficInterceptor networkTrafficInterceptor = DriverProvider.getActiveDriver().getProxy();
            if (networkTrafficInterceptor != null) {
                networkTrafficInterceptor.startIntercepting();
            }
        }
        if (reload) {
            driver.navigate().refresh();
        }
    }
    Log.logJSError();
}
Also used : Cookie(org.openqa.selenium.Cookie) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) User(com.wikia.webdriver.common.core.helpers.User) Execute(com.wikia.webdriver.common.core.annotations.Execute) WikiBasePageObject(com.wikia.webdriver.pageobjectsfactory.pageobject.WikiBasePageObject) Method(java.lang.reflect.Method) Date(java.util.Date) DateTime(org.joda.time.DateTime) JavascriptActions(com.wikia.webdriver.common.core.elemnt.JavascriptActions) NetworkTrafficInterceptor(com.wikia.webdriver.common.core.networktrafficinterceptor.NetworkTrafficInterceptor) WikiBasePageObject(com.wikia.webdriver.pageobjectsfactory.pageobject.WikiBasePageObject) SkipException(org.testng.SkipException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 3 with User

use of com.wikia.webdriver.common.core.helpers.User in project selenium-tests by Wikia.

the class UpvotingTests method setUp.

@BeforeSuite
private void setUp() {
    User user = User.USER_5;
    String siteId = Utils.extractSiteIdFromWikiName("qadiscussions", "de");
    existingPost = DiscussionsClient.using(user, driver).createPostWithUniqueData(siteId);
    DiscussionsClient.using(user, driver).createReplyToPost(siteId, existingPost);
}
Also used : User(com.wikia.webdriver.common.core.helpers.User) BeforeSuite(org.testng.annotations.BeforeSuite)

Aggregations

User (com.wikia.webdriver.common.core.helpers.User)3 JavascriptActions (com.wikia.webdriver.common.core.elemnt.JavascriptActions)2 WikiBasePageObject (com.wikia.webdriver.pageobjectsfactory.pageobject.WikiBasePageObject)2 Method (java.lang.reflect.Method)2 Cookie (org.openqa.selenium.Cookie)2 WebDriverException (org.openqa.selenium.WebDriverException)2 Execute (com.wikia.webdriver.common.core.annotations.Execute)1 NetworkTrafficInterceptor (com.wikia.webdriver.common.core.networktrafficinterceptor.NetworkTrafficInterceptor)1 Date (java.util.Date)1 DateTime (org.joda.time.DateTime)1 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)1 SkipException (org.testng.SkipException)1 BeforeSuite (org.testng.annotations.BeforeSuite)1