Example usage for org.openqa.selenium Cookie getValue

List of usage examples for org.openqa.selenium Cookie getValue

Introduction

In this page you can find the example usage for org.openqa.selenium Cookie getValue.

Prototype

public String getValue() 

Source Link

Usage

From source file:org.alfresco.po.share.LoginPageTest.java

License:Open Source License

/**
 * Helper method to extract cookie value
 * of Alfresco-CSRFToken//  w  w  w  . j  a v  a 2  s .c o  m
 * @return String token value
 */
private String getCookieValue() {
    Cookie cookie = driver.manage().getCookieNamed("Alfresco-CSRFToken");
    if (cookie != null) {
        return cookie.getValue();
    }
    return "";
}

From source file:org.alfresco.po.share.util.FileDownloader.java

License:Open Source License

/**
 * Loads the cookies from WebDriver to mimic the browser cookie state
 * @return {@link BasicCookieStore} current state
 *//*from   w  w w.j  a v  a 2 s .com*/
private BasicCookieStore getCookies() {

    BasicCookieStore mimicWebDriverCookie = new BasicCookieStore();
    Set<Cookie> cookies = driver.manage().getCookies();

    for (Cookie seleniumCookie : cookies) {
        BasicClientCookie duplicateCookie = new BasicClientCookie(seleniumCookie.getName(),
                seleniumCookie.getValue());
        duplicateCookie.setDomain(seleniumCookie.getDomain());
        duplicateCookie.setSecure(seleniumCookie.isSecure());
        duplicateCookie.setExpiryDate(seleniumCookie.getExpiry());
        duplicateCookie.setPath(seleniumCookie.getPath());
        mimicWebDriverCookie.addCookie(duplicateCookie);
    }
    return mimicWebDriverCookie;
}

From source file:org.alfresco.selenium.FetchHttpClient.java

License:Open Source License

/**
 * Prepare the client cookie based on the authenticated {@link WebDriver} 
 * cookie. /*from  ww w.  j a va  2 s  . c o m*/
 * @param driver {@link WebDriver}
 * @return BasicClientCookie with correct credentials.
 */
public static BasicClientCookie generateSessionCookie(WebDriver driver) {
    Cookie originalCookie = driver.manage().getCookieNamed("JSESSIONID");
    if (originalCookie == null) {
        return null;
    }
    // just build new apache-like cookie based on webDriver's one
    String cookieName = originalCookie.getName();
    String cookieValue = originalCookie.getValue();
    BasicClientCookie resultCookie = new BasicClientCookie(cookieName, cookieValue);
    resultCookie.setDomain(originalCookie.getDomain());
    resultCookie.setExpiryDate(originalCookie.getExpiry());
    resultCookie.setPath(originalCookie.getPath());
    return resultCookie;
}

From source file:org.auraframework.http.AppCacheResourcesUITest.java

License:Apache License

/**
 * Opening cached app that had a prior cache error will reload the app.
 * BrowserType.SAFARI is disabled : W-2367702
 *///w  w w  .  j  a v a2 s  .c om
@TargetBrowsers({ BrowserType.GOOGLECHROME, BrowserType.IPAD, BrowserType.IPHONE })
public void testCacheError() throws Exception {
    List<Request> logs = loadMonitorAndValidateApp(TOKEN, TOKEN, "", TOKEN);
    assertRequests(getExpectedInitialRequests(), logs);
    assertAppCacheStatus(Status.IDLE);

    Date expiry = new Date(System.currentTimeMillis() + 60000);
    String cookieName = getManifestCookieName();
    updateCookie(cookieName, "error", expiry, "/");

    logs = loadMonitorAndValidateApp(TOKEN, TOKEN, "", TOKEN);
    List<Request> expectedChange = Lists.newArrayList();
    expectedChange.add(new Request("/auraResource", null, null, "manifest", 404)); // reset
    expectedChange.add(new Request(getUrl(), null, null, null, 302)); // hard refresh
    switch (getBrowserType()) {
    case GOOGLECHROME:
        expectedChange.add(new Request(3, "/auraResource", null, null, "manifest", 200));
        expectedChange.add(new Request(2, getUrl(), null, null, null, 200));
        break;
    default:
        expectedChange.add(new Request("/auraResource", null, null, "manifest", 200));
        expectedChange.add(new Request(getUrl(), null, null, null, 200));
        expectedChange.add(new Request("/auraResource", null, null, "css", 200));
        expectedChange.add(new Request("/auraResource", null, null, "js", 200));
    }
    assertRequests(expectedChange, logs);
    assertAppCacheStatus(Status.IDLE);
    // There may be a varying number of requests, depending on when the initial manifest response is received.
    Cookie cookie = getDriver().manage().getCookieNamed(cookieName);
    assertFalse("Manifest cookie was not changed " + cookie.getValue(), "error".equals(cookie.getValue()));
}

From source file:org.auraframework.http.AppCacheResourcesUITest.java

License:Apache License

/**
 * Manifest request limit exceeded for the time period should result in reset.
 * BrowserType.SAFARI is disabled : W-2367702
 *///ww w  . j ava2 s.  com
@TargetBrowsers({ BrowserType.GOOGLECHROME, BrowserType.IPAD, BrowserType.IPHONE })
public void testManifestRequestLimitExceeded() throws Exception {
    List<Request> logs = loadMonitorAndValidateApp(TOKEN, TOKEN, "", TOKEN);
    assertRequests(getExpectedInitialRequests(), logs);
    assertAppCacheStatus(Status.IDLE);

    Date expiry = new Date(System.currentTimeMillis() + 60000);
    String cookieName = getManifestCookieName();
    Cookie cookie = getDriver().manage().getCookieNamed(cookieName);
    String timeVal = cookie.getValue().split(":")[1];
    updateCookie(cookieName, "8:" + timeVal, expiry, "/");
    logs = loadMonitorAndValidateApp(TOKEN, TOKEN, "", TOKEN);
    List<Request> expectedChange = Lists.newArrayList();

    expectedChange.add(new Request("/auraResource", null, null, "manifest", 404)); // reset
    expectedChange.add(new Request(getUrl(), null, null, null, 302)); // hard refresh
    switch (getBrowserType()) {
    case GOOGLECHROME:
        expectedChange.add(new Request(3, "/auraResource", null, null, "manifest", 200));
        expectedChange.add(new Request(2, getUrl(), null, null, null, 200));
        break;
    default:
        expectedChange.add(new Request("/auraResource", null, null, "manifest", 200));
        expectedChange.add(new Request(getUrl(), null, null, null, 200));
        expectedChange.add(new Request("/auraResource", null, null, "css", 200));
        expectedChange.add(new Request("/auraResource", null, null, "js", 200));
    }
    assertRequests(expectedChange, logs);
    assertAppCacheStatus(Status.IDLE);
}

From source file:org.auraframework.integration.test.http.AppCacheResourcesUITest.java

License:Apache License

/**
 * Opening cached app that had a prior cache error will reload the app. BrowserType.SAFARI is disabled : W-2367702
 *//*w  w w  .ja va 2  s.  c  om*/
@TargetBrowsers({ BrowserType.GOOGLECHROME, BrowserType.IPAD, BrowserType.IPHONE })
// TODO(W-2701964): Flapping in autobuilds, needs to be revisited
@Flapper
public void testCacheError() throws Exception {
    List<Request> logs = loadMonitorAndValidateApp(TOKEN, TOKEN, "", TOKEN);
    assertRequests(getExpectedInitialRequests(), logs);
    assertAppCacheStatus(Status.IDLE);

    Date expiry = new Date(System.currentTimeMillis() + 60000);
    String cookieName = getManifestCookieName();
    updateCookie(cookieName, "error", expiry, "/");

    logs = loadMonitorAndValidateApp(TOKEN, TOKEN, "", TOKEN);
    List<Request> expectedChange = Lists.newArrayList();
    expectedChange.add(new Request("/auraResource", "manifest", 404)); // reset
    expectedChange.add(new Request(getUrl(), null, 302)); // hard refresh
    switch (getBrowserType()) {
    case GOOGLECHROME:
        expectedChange.add(new Request(3, "/auraResource", "manifest", 200));
        expectedChange.add(new Request(2, getUrl(), null, 200));
        break;
    default:
        expectedChange.add(new Request("/auraResource", "manifest", 200));
        expectedChange.add(new Request(getUrl(), null, 200));
        expectedChange.add(new Request("/auraResource", "css", 200));
        expectedChange.add(new Request("/auraResource", "js", 200));
    }
    assertRequests(expectedChange, logs);
    assertAppCacheStatus(Status.IDLE);
    // There may be a varying number of requests, depending on when the initial manifest response is received.
    Cookie cookie = getDriver().manage().getCookieNamed(cookieName);
    assertFalse("Manifest cookie was not changed " + cookie.getValue(), "error".equals(cookie.getValue()));
}

From source file:org.auraframework.integration.test.http.AppCacheResourcesUITest.java

License:Apache License

/**
 * Manifest request limit exceeded for the time period should result in reset. BrowserType.SAFARI is disabled :
 * W-2367702/* ww w.j av a 2 s.c om*/
 */
@TargetBrowsers({ BrowserType.GOOGLECHROME, BrowserType.IPAD, BrowserType.IPHONE })
// TODO(W-2701964): Flapping in autobuilds, needs to be revisited
@Flapper
public void testManifestRequestLimitExceeded() throws Exception {
    List<Request> logs = loadMonitorAndValidateApp(TOKEN, TOKEN, "", TOKEN);
    assertRequests(getExpectedInitialRequests(), logs);
    assertAppCacheStatus(Status.IDLE);

    Date expiry = new Date(System.currentTimeMillis() + 60000);
    String cookieName = getManifestCookieName();
    Cookie cookie = getDriver().manage().getCookieNamed(cookieName);
    String timeVal = cookie.getValue().split(":")[1];
    updateCookie(cookieName, "8:" + timeVal, expiry, "/");
    logs = loadMonitorAndValidateApp(TOKEN, TOKEN, "", TOKEN);
    List<Request> expectedChange = Lists.newArrayList();

    expectedChange.add(new Request("/auraResource", "manifest", 404)); // reset
    expectedChange.add(new Request(getUrl(), null, 302)); // hard refresh
    switch (getBrowserType()) {
    case GOOGLECHROME:
        expectedChange.add(new Request(3, "/auraResource", "manifest", 200));
        expectedChange.add(new Request(2, getUrl(), null, 200));
        break;
    default:
        expectedChange.add(new Request("/auraResource", "manifest", 200));
        expectedChange.add(new Request(getUrl(), null, 200));
        expectedChange.add(new Request("/auraResource", "css", 200));
        expectedChange.add(new Request("/auraResource", "js", 200));
    }
    assertRequests(expectedChange, logs);
    assertAppCacheStatus(Status.IDLE);
}

From source file:org.cerberus.service.engine.impl.WebDriverService.java

License:Open Source License

@Override
public String getFromCookie(Session session, String cookieName, String cookieParameter) {
    Cookie cookie = session.getDriver().manage().getCookieNamed(cookieName);
    if (cookie != null) {
        if (cookieParameter.equals("name")) {
            return cookie.getName();
        }//  w w  w  . j  av  a 2s  .  c  om
        if (cookieParameter.equals("expiry")) {
            return cookie.getExpiry().toString();
        }
        if (cookieParameter.equals("value")) {
            return cookie.getValue();
        }
        if (cookieParameter.equals("domain")) {
            return cookie.getDomain();
        }
        if (cookieParameter.equals("path")) {
            return cookie.getPath();
        }
        if (cookieParameter.equals("isHttpOnly")) {
            return String.valueOf(cookie.isHttpOnly());
        }
        if (cookieParameter.equals("isSecure")) {
            return String.valueOf(cookie.isSecure());
        }
    } else {
        return "cookieNotFound";
    }
    return null;
}

From source file:org.cloudfoundry.identity.uaa.integration.feature.FacebookLoginIT.java

License:Open Source License

private void login(String url, String userName, String password) throws Exception {
    webDriver.get(url + "/logout.do");
    webDriver.get(url + "/");
    Cookie beforeLogin = webDriver.manage().getCookieNamed("JSESSIONID");
    assertNotNull(beforeLogin);/*from w  w  w  .  j av a2 s  .  c o  m*/
    assertNotNull(beforeLogin.getValue());
    webDriver.findElement(By.linkText(LINK_TEXT)).click();
    IntegrationTestUtils.takeScreenShot("test-screen-fb-before-login-", webDriver);
    Assert.assertThat(webDriver.getCurrentUrl(), Matchers.containsString("www.facebook.com"));
    IntegrationTestUtils.takeScreenShot("test-screen-fb-login-page-", webDriver);
    webDriver.findElement(By.name("email")).sendKeys(userName);
    webDriver.findElement(By.name("pass")).sendKeys(password);
    webDriver.findElement(By.name("login")).click();
    for (int i = 0; i < 5; i++) {
        IntegrationTestUtils.takeScreenShot("test-screen-fb-after-login-", webDriver);
        if (webDriver.getCurrentUrl().contains(url)) {
            break;
        } else {
            Thread.sleep(5000);
        }
    }
    Assert.assertThat(webDriver.getCurrentUrl(), Matchers.containsString(url));
    assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to?"));
    Cookie afterLogin = webDriver.manage().getCookieNamed("JSESSIONID");
    assertNotNull(afterLogin);
    assertNotNull(afterLogin.getValue());
    assertNotEquals(beforeLogin.getValue(), afterLogin.getValue());
}

From source file:org.cloudfoundry.identity.uaa.integration.feature.SamlLoginIT.java

License:Open Source License

@Test
public void testSamlLogin_Custom_User_Attributes_In_ID_Token() throws Exception {

    final String COST_CENTER = "costCenter";
    final String COST_CENTERS = "costCenters";
    final String DENVER_CO = "Denver,CO";
    final String MANAGER = "manager";
    final String MANAGERS = "managers";
    final String JOHN_THE_SLOTH = "John the Sloth";
    final String KARI_THE_ANT_EATER = "Kari the Ant Eater";

    //ensure we are able to resolve DNS for hostname testzone1.localhost
    assumeTrue("Expected testzone1/2/3/4.localhost to resolve to 127.0.0.1", doesSupportZoneDNS());
    String zoneId = "testzone1";
    String zoneUrl = baseUrl.replace("localhost", "testzone1.localhost");

    //identity client token
    RestTemplate identityClient = IntegrationTestUtils
            .getClientCredentialsTemplate(IntegrationTestUtils.getClientCredentialsResource(baseUrl,
                    new String[] { "zones.write", "zones.read", "scim.zones" }, "identity", "identitysecret"));
    //admin client token - to create users
    RestTemplate adminClient = IntegrationTestUtils.getClientCredentialsTemplate(
            IntegrationTestUtils.getClientCredentialsResource(baseUrl, new String[0], "admin", "adminsecret"));
    //create the zone
    IntegrationTestUtils.createZoneOrUpdateSubdomain(identityClient, baseUrl, zoneId, zoneId);

    //create a zone admin user
    String email = new RandomValueStringGenerator().generate() + "@samltesting.org";
    ScimUser user = IntegrationTestUtils.createUser(adminClient, baseUrl, email, "firstname", "lastname", email,
            true);/*from  w ww  . j a v a 2s .c  o m*/
    IntegrationTestUtils.makeZoneAdmin(identityClient, baseUrl, user.getId(), zoneId);

    //get the zone admin token
    String zoneAdminToken = IntegrationTestUtils.getAuthorizationCodeToken(serverRunning,
            UaaTestAccounts.standard(serverRunning), "identity", "identitysecret", email, "secr3T");

    SamlIdentityProviderDefinition samlIdentityProviderDefinition = createTestZone1IDP("simplesamlphp");
    samlIdentityProviderDefinition.addAttributeMapping(USER_ATTRIBUTE_PREFIX + COST_CENTERS, COST_CENTER);
    samlIdentityProviderDefinition.addAttributeMapping(USER_ATTRIBUTE_PREFIX + MANAGERS, MANAGER);

    IdentityProvider<SamlIdentityProviderDefinition> provider = new IdentityProvider();
    provider.setIdentityZoneId(zoneId);
    provider.setType(OriginKeys.SAML);
    provider.setActive(true);
    provider.setConfig(samlIdentityProviderDefinition);
    provider.setOriginKey(samlIdentityProviderDefinition.getIdpEntityAlias());
    provider.setName("simplesamlphp for testzone1");

    provider = IntegrationTestUtils.createOrUpdateProvider(zoneAdminToken, baseUrl, provider);
    assertEquals(provider.getOriginKey(), provider.getConfig().getIdpEntityAlias());

    List<String> idps = Arrays.asList(provider.getOriginKey());

    String adminClientInZone = new RandomValueStringGenerator().generate();
    BaseClientDetails clientDetails = new BaseClientDetails(adminClientInZone, null, "openid,user_attributes",
            "authorization_code,client_credentials", "uaa.admin,scim.read,scim.write,uaa.resource", zoneUrl);
    clientDetails.setClientSecret("secret");
    clientDetails.addAdditionalInformation(ClientConstants.AUTO_APPROVE, true);
    clientDetails.addAdditionalInformation(ClientConstants.ALLOWED_PROVIDERS, idps);

    clientDetails = IntegrationTestUtils.createClientAsZoneAdmin(zoneAdminToken, baseUrl, zoneId,
            clientDetails);
    clientDetails.setClientSecret("secret");

    String adminTokenInZone = IntegrationTestUtils.getClientCredentialsToken(zoneUrl,
            clientDetails.getClientId(), "secret");

    webDriver.get(zoneUrl + "/logout.do");

    String authUrl = zoneUrl + "/oauth/authorize?client_id=" + clientDetails.getClientId() + "&redirect_uri="
            + URLEncoder.encode(zoneUrl) + "&response_type=code&state=8tp0tR";
    webDriver.get(authUrl);
    //we should now be in the Simple SAML PHP site
    webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]"));
    webDriver.findElement(By.name("username")).clear();
    webDriver.findElement(By.name("username")).sendKeys("marissa5");
    webDriver.findElement(By.name("password")).sendKeys("saml5");
    webDriver.findElement(By.xpath("//input[@value='Login']")).click();
    assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to?"));

    Cookie cookie = webDriver.manage().getCookieNamed("JSESSIONID");

    //do an auth code grant
    //pass up the jsessionid
    System.out.println("cookie = " + String.format("%s=%s", cookie.getName(), cookie.getValue()));

    serverRunning.setHostName("testzone1.localhost");
    Map<String, String> authCodeTokenResponse = IntegrationTestUtils.getAuthorizationCodeTokenMap(serverRunning,
            UaaTestAccounts.standard(serverRunning), clientDetails.getClientId(),
            clientDetails.getClientSecret(), null, null, "token id_token", cookie.getValue(), zoneUrl, false);

    webDriver.get(baseUrl + "/logout.do");
    webDriver.get(zoneUrl + "/logout.do");

    //validate that we have an ID token, and that it contains costCenter and manager values

    String idToken = authCodeTokenResponse.get("id_token");
    assertNotNull(idToken);

    Jwt idTokenClaims = JwtHelper.decode(idToken);
    Map<String, Object> claims = JsonUtils.readValue(idTokenClaims.getClaims(),
            new TypeReference<Map<String, Object>>() {
            });

    assertNotNull(claims.get(ClaimConstants.USER_ATTRIBUTES));
    Map<String, List<String>> userAttributes = (Map<String, List<String>>) claims
            .get(ClaimConstants.USER_ATTRIBUTES);
    assertThat(userAttributes.get(COST_CENTERS), containsInAnyOrder(DENVER_CO));
    assertThat(userAttributes.get(MANAGERS), containsInAnyOrder(JOHN_THE_SLOTH, KARI_THE_ANT_EATER));

}