Search in sources :

Example 6 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 7 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 8 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 9 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)

Example 10 with Cookie

use of org.openqa.selenium.Cookie in project oxAuth by GluuFederation.

the class BaseTest method authenticateResourceOwner.

/**
     * The authorization server authenticates the resource owner (via the user-agent)
     * No authorization page.
     */
public AuthorizationResponse authenticateResourceOwner(String authorizeUrl, AuthorizationRequest authorizationRequest, String userId, String userSecret, boolean cleanupCookies) {
    String authorizationRequestUrl = authorizeUrl + "?" + authorizationRequest.getQueryString();
    AuthorizeClient authorizeClient = new AuthorizeClient(authorizeUrl);
    authorizeClient.setRequest(authorizationRequest);
    System.out.println("authenticateResourceOwner: authorizationRequestUrl:" + authorizationRequestUrl);
    startSelenium();
    if (cleanupCookies) {
        System.out.println("authenticateResourceOwner: Cleaning cookies");
        deleteAllCookies();
    }
    driver.navigate().to(authorizationRequestUrl);
    if (userSecret != null) {
        if (userId != null) {
            WebElement usernameElement = driver.findElement(By.name(loginFormUsername));
            usernameElement.sendKeys(userId);
        }
        WebElement passwordElement = driver.findElement(By.name(loginFormPassword));
        passwordElement.sendKeys(userSecret);
        WebElement loginButton = driver.findElement(By.name(loginFormLoginButton));
        loginButton.click();
    }
    String authorizationResponseStr = driver.getCurrentUrl();
    /*WebElement allowButton = driver.findElement(By.name(authorizeFormAllowButton));

        final String previousURL = driver.getCurrentUrl();
        allowButton.click();
        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver d) {
                return (d.getCurrentUrl() != previousURL);
            }
        });

        authorizationResponseStr = driver.getCurrentUrl();*/
    Cookie sessionStateCookie = driver.manage().getCookieNamed("session_state");
    String sessionState = null;
    if (sessionStateCookie != null) {
        sessionState = sessionStateCookie.getValue();
    }
    System.out.println("authenticateResourceOwner: sessionState:" + sessionState);
    stopSelenium();
    AuthorizationResponse authorizationResponse = new AuthorizationResponse(authorizationResponseStr);
    if (authorizationRequest.getRedirectUri() != null && authorizationRequest.getRedirectUri().equals(authorizationResponseStr)) {
        authorizationResponse.setResponseMode(ResponseMode.FORM_POST);
    }
    authorizeClient.setResponse(authorizationResponse);
    showClientUserAgent(authorizeClient);
    return authorizationResponse;
}
Also used : Cookie(org.openqa.selenium.Cookie) WebElement(org.openqa.selenium.WebElement)

Aggregations

Cookie (org.openqa.selenium.Cookie)24 WebDriver (org.openqa.selenium.WebDriver)11 Test (org.junit.Test)8 WebElement (org.openqa.selenium.WebElement)7 Date (java.util.Date)5 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)5 PublicAtsApi (com.axway.ats.common.PublicAtsApi)3 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)3 File (java.io.File)2 JavascriptActions (com.wikia.webdriver.common.core.elemnt.JavascriptActions)1 User (com.wikia.webdriver.common.core.helpers.User)1 WikiBasePageObject (com.wikia.webdriver.pageobjectsfactory.pageobject.WikiBasePageObject)1 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1