Search in sources :

Example 11 with Cookie

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

the class BaseTest method authenticateResourceOwnerAndDenyAccess.

public AuthorizationResponse authenticateResourceOwnerAndDenyAccess(String authorizeUrl, AuthorizationRequest authorizationRequest, String userId, String userSecret) {
    String authorizationRequestUrl = authorizeUrl + "?" + authorizationRequest.getQueryString();
    AuthorizeClient authorizeClient = new AuthorizeClient(authorizeUrl);
    authorizeClient.setRequest(authorizationRequest);
    System.out.println("authenticateResourceOwnerAndDenyAccess: authorizationRequestUrl:" + authorizationRequestUrl);
    startSelenium();
    driver.navigate().to(authorizationRequestUrl);
    WebElement usernameElement = driver.findElement(By.name(loginFormUsername));
    WebElement passwordElement = driver.findElement(By.name(loginFormPassword));
    WebElement loginButton = driver.findElement(By.name(loginFormLoginButton));
    if (userId != null) {
        usernameElement.sendKeys(userId);
    }
    passwordElement.sendKeys(userSecret);
    loginButton.click();
    String authorizationResponseStr = driver.getCurrentUrl();
    WebElement doNotAllowButton = driver.findElement(By.name(authorizeFormDoNotAllowButton));
    final String previousURL = driver.getCurrentUrl();
    doNotAllowButton.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("authenticateResourceOwnerAndDenyAccess: sessionState:" + sessionState);
    stopSelenium();
    AuthorizationResponse authorizationResponse = new AuthorizationResponse(authorizationResponseStr);
    if (authorizationRequest.getRedirectUri() != null && authorizationRequest.getRedirectUri().equals(authorizationResponseStr)) {
        authorizationResponse.setResponseMode(ResponseMode.FORM_POST);
    }
    authorizationResponse.setSessionState(sessionState);
    authorizeClient.setResponse(authorizationResponse);
    showClientUserAgent(authorizeClient);
    return authorizationResponse;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Cookie(org.openqa.selenium.Cookie) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) WebElement(org.openqa.selenium.WebElement)

Example 12 with Cookie

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

the class BaseTest method authorizationRequestAndDenyAccess.

public AuthorizationResponse authorizationRequestAndDenyAccess(String authorizeUrl, AuthorizationRequest authorizationRequest) {
    String authorizationRequestUrl = authorizeUrl + "?" + authorizationRequest.getQueryString();
    AuthorizeClient authorizeClient = new AuthorizeClient(authorizeUrl);
    authorizeClient.setRequest(authorizationRequest);
    System.out.println("authorizationRequestAndDenyAccess: authorizationRequestUrl:" + authorizationRequestUrl);
    startSelenium();
    driver.navigate().to(authorizationRequestUrl);
    WebElement doNotAllowButton = driver.findElement(By.name(authorizeFormDoNotAllowButton));
    final String previousURL = driver.getCurrentUrl();
    doNotAllowButton.click();
    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver d) {
            return (d.getCurrentUrl() != previousURL);
        }
    });
    String authorizationResponseStr = driver.getCurrentUrl();
    Cookie sessionStateCookie = driver.manage().getCookieNamed("session_state");
    String sessionState = null;
    if (sessionStateCookie != null) {
        sessionState = sessionStateCookie.getValue();
    }
    System.out.println("authorizationRequestAndDenyAccess: 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 : WebDriver(org.openqa.selenium.WebDriver) Cookie(org.openqa.selenium.Cookie) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) WebElement(org.openqa.selenium.WebElement)

Example 13 with Cookie

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

the class BaseTest method authorizationRequestAndGrantAccess.

public AuthorizationResponse authorizationRequestAndGrantAccess(String authorizeUrl, AuthorizationRequest authorizationRequest) {
    String authorizationRequestUrl = authorizeUrl + "?" + authorizationRequest.getQueryString();
    AuthorizeClient authorizeClient = new AuthorizeClient(authorizeUrl);
    authorizeClient.setRequest(authorizationRequest);
    System.out.println("authorizationRequestAndGrantAccess: authorizationRequestUrl:" + authorizationRequestUrl);
    startSelenium();
    driver.navigate().to(authorizationRequestUrl);
    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("authorizationRequestAndGrantAccess: 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 : WebDriver(org.openqa.selenium.WebDriver) Cookie(org.openqa.selenium.Cookie) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) WebElement(org.openqa.selenium.WebElement)

Example 14 with Cookie

use of org.openqa.selenium.Cookie in project ghostdriver by detro.

the class CookieTest method modifyingACookie.

@Test
public void modifyingACookie() {
    server.setHttpHandler("GET", COOKIE_SETTING_CALLBACK);
    goToPage();
    driver.manage().addCookie(new Cookie("test", "newValue", ".localhost", "/", null, false));
    assertEquals(2, getCookies().length);
    Cookie cookie = driver.manage().getCookieNamed("test");
    assertEquals("test", cookie.getName());
    assertEquals("newValue", cookie.getValue());
    assertEquals(".localhost", cookie.getDomain());
    assertEquals("/", cookie.getPath());
    assertEquals(false, cookie.isSecure());
    cookie = driver.manage().getCookieNamed("test2");
    assertEquals("test2", cookie.getName());
    assertEquals("test2", cookie.getValue());
    assertEquals(".localhost", cookie.getDomain());
    assertEquals("/", cookie.getPath());
    assertEquals(false, cookie.isSecure());
}
Also used : Cookie(org.openqa.selenium.Cookie) Test(org.junit.Test)

Example 15 with Cookie

use of org.openqa.selenium.Cookie in project ghostdriver by detro.

the class CookieTest method shouldBeAbleToCreateCookieViaJavascriptOnGoogle.

@Test
public void shouldBeAbleToCreateCookieViaJavascriptOnGoogle() {
    String ckey = "cookiekey";
    String cval = "cookieval";
    WebDriver d = getDriver();
    d.get("http://www.google.com");
    JavascriptExecutor js = (JavascriptExecutor) d;
    // Of course, no cookie yet(!)
    Cookie c = d.manage().getCookieNamed(ckey);
    assertNull(c);
    // Attempt to create cookie on multiple Google domains
    js.executeScript("javascript:(" + "function() {" + "   cook = document.cookie;" + "   begin = cook.indexOf('" + ckey + "=');" + "   var val;" + "   if (begin !== -1) {" + "       var end = cook.indexOf(\";\",begin);" + "       if (end === -1)" + "           end=cook.length;" + "       val=cook.substring(begin+11,end);" + "   }" + "   val = ['" + cval + "'];" + "   if (val) {" + "       var d=Array('com','co.jp','ca','fr','de','co.uk','it','es','com.br');" + "       for (var i = 0; i < d.length; i++) {" + "           document.cookie = '" + ckey + "='+val+';path=/;domain=.google.'+d[i]+'; ';" + "       }" + "   }" + "})();");
    c = d.manage().getCookieNamed(ckey);
    assertNotNull(c);
    assertEquals(cval, c.getValue());
    // Set cookie as empty
    js.executeScript("javascript:(" + "function() {" + "   var d = Array('com','co.jp','ca','fr','de','co.uk','it','cn','es','com.br');" + "   for(var i = 0; i < d.length; i++) {" + "       document.cookie='" + ckey + "=;path=/;domain=.google.'+d[i]+'; ';" + "   }" + "})();");
    c = d.manage().getCookieNamed(ckey);
    assertNotNull(c);
    assertEquals("", c.getValue());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Cookie(org.openqa.selenium.Cookie) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Test(org.junit.Test)

Aggregations

Cookie (org.openqa.selenium.Cookie)24 WebDriver (org.openqa.selenium.WebDriver)11 Test (org.junit.Test)8 WebElement (org.openqa.selenium.WebElement)8 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 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)2 JBrowserDriver (com.machinepublishers.jbrowserdriver.JBrowserDriver)1 ProxyConfig (com.machinepublishers.jbrowserdriver.ProxyConfig)1 Type (com.machinepublishers.jbrowserdriver.ProxyConfig.Type)1 Settings (com.machinepublishers.jbrowserdriver.Settings)1 Builder (com.machinepublishers.jbrowserdriver.Settings.Builder)1 UserAgent (com.machinepublishers.jbrowserdriver.UserAgent)1 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