Example usage for org.openqa.selenium Cookie getPath

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

Introduction

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

Prototype

public String getPath() 

Source Link

Usage

From source file:org.ado.picasa.FileDownloader.java

License:Apache License

private HttpState mimicCookieState(Set<org.openqa.selenium.Cookie> seleniumCookieSet) {
    HttpState mimicWebDriverCookieState = new HttpState();
    for (org.openqa.selenium.Cookie seleniumCookie : seleniumCookieSet) {
        Cookie httpClientCookie = new Cookie(seleniumCookie.getDomain(), seleniumCookie.getName(),
                seleniumCookie.getValue(), seleniumCookie.getPath(), seleniumCookie.getExpiry(),
                seleniumCookie.isSecure());
        mimicWebDriverCookieState.addCookie(httpClientCookie);
    }// www.j ava 2 s  .  com
    return mimicWebDriverCookieState;
}

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
 *//* w  ww .  ja va  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 w  ww  . ja va2 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.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();
        }/*from w w w  .  j a  v  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.cybercat.automation.core.Browser.java

License:Apache License

private void saveCookies(EventTestFail event) {
    String currentDate = CommonUtils.getCurrentDate();
    Path cookiePath = Paths.get(WorkFolder.Screenshots.getPath().toString(), event.getTestClass().getName(),
            currentDate + event.getMethodName() + "_cookies.txt");
    try (BufferedWriter writer = Files.newBufferedWriter(cookiePath, Charset.defaultCharset())) {
        for (Cookie cookie : getCookies()) {
            writer.write("Domain: " + cookie.getDomain() + "; Name: " + cookie.getName() + "; Value: "
                    + cookie.getValue() + "; Path: " + cookie.getPath() + ";\n");
        }/*w  ww .  j av  a2  s.  c  o m*/
        TestCase test = new TestCase(event.getTestClass().getName());
        test.setCookies(cookiePath.toString());
        TestArtifactManager.updateTestInfo(test);
    } catch (Exception e) {
        log.error("Exception occurred while saving cookies.", e);
        return;
    }
    log.info("Cookies are saved to file " + cookiePath);
}

From source file:org.fitting.selenium.fixture.CookieFixture.java

License:Apache License

/**
 * Copy the cookie matching the given name to the given domain.
 *
 * @param driver The web driver./*from   w w  w  .j a  v  a2  s .  c o  m*/
 * @param name   The name of the cookie.
 * @param domain The domain.
 */
private void copyCookieToDomain(WebDriver driver, String name, String domain) {
    try {
        final Cookie cookie = getCookie(driver, name);
        addCookie(driver, name, cookie.getValue(), cookie.getPath(), domain);
    } catch (NullPointerException e) {
        throw new FormattedFittingException(format("No cookie with name [%s] found.", name), e);
    }
}

From source file:org.keycloak.testsuite.AbstractAuthTest.java

License:Apache License

public void listCookies() {
    log.info("LIST OF COOKIES: ");
    for (Cookie c : driver.manage().getCookies()) {
        log.info(MessageFormat.format(" {1} {2} {0}", c.getName(), c.getDomain(), c.getPath(), c.getValue()));
    }/*from w ww. j a va 2  s .c  om*/
}

From source file:org.keycloak.testsuite.adapter.servlet.CookieStoreRootContextTest.java

License:Apache License

@Test
public void testTokenInCookieSSORoot() {
    // Login/*  ww w .  ja  va 2 s. c  o m*/
    String tokenCookie = loginToCustomerCookiePortalRoot();
    Cookie cookie = driver.manage().getCookieNamed(AdapterConstants.KEYCLOAK_ADAPTER_STATE_COOKIE);
    assertEquals("/", cookie.getPath());

    // SSO to second app
    customerPortal.navigateTo();
    assertLogged();

    customerCookiePortalRoot.navigateTo();
    assertLogged();
    cookie = driver.manage().getCookieNamed(AdapterConstants.KEYCLOAK_ADAPTER_STATE_COOKIE);
    String tokenCookie2 = cookie.getValue();
    assertEquals(tokenCookie, tokenCookie2);
    assertEquals("/", cookie.getPath());

    // Logout with httpServletRequest
    logoutFromCustomerCookiePortalRoot();

    // Also should be logged-out from the second app
    customerPortal.navigateTo();
    assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);
}

From source file:org.suren.autotest.web.framework.invoker.KaptchaInvoker.java

License:Apache License

/**
 * ???/*from  w  ww.  jav  a 2  s.  c  o  m*/
 * @param engine 
 * @param param data,http://localhost:8080/G2/captcha!getLastCode.do
 * @return ??
 */
public static String execute(SeleniumEngine engine, String param) {
    WebDriver driver = engine.getDriver();
    Options manage = driver.manage();

    String[] paramArray = param.split(",", 2);

    if (paramArray.length != 2) {
        throw new RuntimeException("Param format is error, should be 'data,url'");
    }

    String key = paramArray[0];
    String url = paramArray[1];

    Set<Cookie> cookies = manage.getCookies();
    List<AtCookie> atCookieList = new ArrayList<AtCookie>();
    for (Cookie cookie : cookies) {
        String name = cookie.getName();
        String value = cookie.getValue();

        AtCookie atCookie = new AtCookie();
        atCookie.setName(name);
        atCookie.setValue(value);
        atCookie.setPath(cookie.getPath());
        atCookie.setDomain(cookie.getDomain());

        atCookieList.add(atCookie);
    }

    String code = HttpApiUtil.getJsonValue(url, atCookieList, key);

    return code;
}

From source file:org.wso2.carbon.appmanager.integration.ui.Util.APPMPublisherRestClient.java

License:Open Source License

/**
 * logs in to the publisher/*from  w ww.j av a2  s .  c om*/
 *
 * @param userName
 * @param password
 * @return
 * @throws Exception
 */
public String login(String userName, String password) throws Exception {

    WebDriverWait wait = new WebDriverWait(driver, 30);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username")));
    // find element username
    WebElement usernameEle = driver.findElement(By.id("username"));
    // fill user name
    usernameEle.sendKeys(userName);
    // find element password
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("password")));
    WebElement passwordEle = driver.findElement(By.id("password"));
    // fill element
    passwordEle.sendKeys(password);
    // find submit button and click on it.
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("btn-primary")));
    driver.findElement(By.className("btn-primary")).click();
    // get the current
    String redirectedUrl = driver.getCurrentUrl();
    // parsing url
    URL aURL = new URL(redirectedUrl);

    Set<org.openqa.selenium.Cookie> allCookies = driver.manage().getCookies();
    for (org.openqa.selenium.Cookie loadedCookie : allCookies) {

        // get /publisher cookie
        if (loadedCookie.getPath().equals("/publisher/")) {
            this.setSession(loadedCookie.toString());
        }
    }

    String urlPath = aURL.getPath();

    //driver.quit();

    if ((urlPath.equals("/publisher/assets/webapp/"))) {
        return "logged in";
    } else {
        return "not logged in";
    }

}