Search in sources :

Example 1 with Cookie

use of org.openqa.selenium.Cookie 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 Cookie

use of org.openqa.selenium.Cookie in project selenium-tests by Wikia.

the class WikiBasePageObject method loginAs.

public String loginAs(String userName, String password, String wikiURL) {
    String token = Helios.getAccessToken(userName, password);
    driver.manage().addCookie(new Cookie("access_token", token, String.format(".%s", Configuration.getEnvType().getWikiaDomain()), null, null));
    if (driver.getCurrentUrl().contains("Logout")) {
        driver.get(wikiURL);
    } else {
        refreshPageAddingCacheBuster();
    }
    this.verifyUserLoggedIn(userName);
    PageObjectLogging.log("loginCookie", "user was logged in by by helios using access token: " + token, true);
    logMercuryUserId();
    return token;
}
Also used : Cookie(org.openqa.selenium.Cookie)

Example 3 with Cookie

use of org.openqa.selenium.Cookie in project ats-framework by Axway.

the class AbstractHtmlEngine method setCookie.

/**
     *
     * @param cookieName the name of the cookie. May not be null or an empty string.
     * @param cookieValue the cookie value. May not be null.
     */
@PublicAtsApi
public void setCookie(String cookieName, String cookieValue) {
    Cookie cookie = new Cookie(cookieName, cookieValue);
    webDriver.manage().addCookie(cookie);
}
Also used : Cookie(org.openqa.selenium.Cookie) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 4 with Cookie

use of org.openqa.selenium.Cookie in project ats-framework by Axway.

the class AbstractHtmlEngine method getCookies.

/**
     * Get all the cookies for the current domain. This is the equivalent of calling "document.cookie" and parsing the result
     *
     * @return {@link com.axway.ats.uiengine.elements.html.Cookie Cookie}s array
     */
@PublicAtsApi
public com.axway.ats.uiengine.elements.html.Cookie[] getCookies() {
    Set<Cookie> cookies = webDriver.manage().getCookies();
    com.axway.ats.uiengine.elements.html.Cookie[] cookiesArr = new com.axway.ats.uiengine.elements.html.Cookie[cookies.size()];
    int i = 0;
    for (Cookie c : cookies) {
        cookiesArr[i++] = new com.axway.ats.uiengine.elements.html.Cookie(c.getName(), c.getValue(), c.getDomain(), c.getPath(), c.getExpiry(), c.isSecure());
    }
    return cookiesArr;
}
Also used : Cookie(org.openqa.selenium.Cookie) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 5 with Cookie

use of org.openqa.selenium.Cookie in project ats-framework by Axway.

the class AbstractHtmlEngine method setCookie.

/**
     *
     * @param name the name of the cookie. May not be null or an empty string.
     * @param value the cookie value. May not be null.
     * @param domain the domain the cookie is visible to.
     * @param path the path the cookie is visible to. If left blank or set to null, will be set to
     *        "/".
     * @param expiry the cookie's expiration date; may be null.
     * @param isSecure whether this cookie requires a secure connection.
     */
@PublicAtsApi
public void setCookie(String name, String value, String domain, String path, Date expiry, boolean isSecure) {
    Cookie cookie = new Cookie(name, value, domain, path, expiry, isSecure);
    webDriver.manage().addCookie(cookie);
}
Also used : Cookie(org.openqa.selenium.Cookie) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

Cookie (org.openqa.selenium.Cookie)53 WebElement (org.openqa.selenium.WebElement)16 Test (org.junit.Test)14 WebDriver (org.openqa.selenium.WebDriver)14 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)9 Date (java.util.Date)8 App (com.coveros.selenified.application.App)7 Test (org.testng.annotations.Test)6 AuthorizationResponse (org.gluu.oxauth.client.AuthorizationResponse)5 AuthorizeClient (org.gluu.oxauth.client.AuthorizeClient)5 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)5 PublicAtsApi (com.axway.ats.common.PublicAtsApi)3 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)3 JavascriptActions (com.wikia.webdriver.common.core.elemnt.JavascriptActions)2 User (com.wikia.webdriver.common.core.helpers.User)2 WikiBasePageObject (com.wikia.webdriver.pageobjectsfactory.pageobject.WikiBasePageObject)2 File (java.io.File)2 Method (java.lang.reflect.Method)2