Search in sources :

Example 26 with Cookie

use of org.openqa.selenium.Cookie in project selenium_java by sergueik.

the class GoogleDriveTest method useCookieTest.

// @Ignore
@Test
public void useCookieTest() throws Exception {
    doLogin();
    System.err.println("Getting the cookies");
    Set<Cookie> cookies = driver.manage().getCookies();
    System.err.println("Closing the browser");
    wait = null;
    System.err.println("re-open the browser, about to use the session cookies");
    driver.close();
    driver = new FirefoxDriver();
    // re-initialize wait object
    wait = new WebDriverWait(driver, flexibleWait);
    wait.pollingEvery(polling, TimeUnit.MILLISECONDS);
    System.err.println("Navigating to " + baseURL);
    driver.get(baseURL);
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
    System.err.println("Loading cookies");
    for (Cookie cookie : cookies) {
        if (debug) {
            System.err.println(formatter.format("Name: '%s'\n" + "Value: '%s'\n" + "Domain: '%s'\n" + "Path: '%s'\n" + "Expiry: '%tc'\n" + "Secure: '%b'\n" + "HttpOnly: '%b'\n" + "\n", cookie.getName(), cookie.getValue(), cookie.getDomain(), cookie.getPath(), cookie.getExpiry(), cookie.isSecure(), cookie.isHttpOnly()).toString());
        }
        try {
            driver.manage().addCookie(cookie);
        } catch (InvalidCookieDomainException e) {
        // ignore the exception
        }
    }
    driver.get(baseURL);
    driver.navigate().refresh();
    System.err.println("Waiting for inbox");
    /*
		 * try { wait.until(ExpectedConditions.urlContains("#inbox")); } catch
		 * (TimeoutException | UnreachableBrowserException e) {
		 * verificationErrors.append(e.toString()); }
		 */
    try {
        Thread.sleep(10000);
    } catch (InterruptedException e) {
    }
    doLogout();
}
Also used : Cookie(org.openqa.selenium.Cookie) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) InvalidCookieDomainException(org.openqa.selenium.InvalidCookieDomainException) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Test(org.junit.Test)

Example 27 with Cookie

use of org.openqa.selenium.Cookie in project selenium_java by sergueik.

the class YandexTest method getCookieTest.

// @Ignore
@Test
public void getCookieTest() throws Exception {
    doLogin();
    Set<Cookie> cookies = driver.manage().getCookies();
    System.err.println("Cookies:");
    JSONArray cookieJSONArray = new JSONArray();
    for (Cookie cookie : cookies) {
        if (debug) {
            System.err.println(formatter.format("Name: '%s'\n" + "Value: '%s'\n" + "Domain: '%s'\n" + "Path: '%s'\n" + "Expiry: '%tc'\n" + "Secure: '%b'\n" + "HttpOnly: '%b'\n" + "\n", cookie.getName(), cookie.getValue(), cookie.getDomain(), cookie.getPath(), cookie.getExpiry(), cookie.isSecure(), cookie.isHttpOnly()).toString());
        }
        JSONObject cookieJSONObject = new JSONObject(cookie);
        if (debug) {
            System.err.println(cookieJSONObject.toString());
        }
        cookieJSONArray.put(cookieJSONObject);
    }
    JSONObject cookiesJSONObject = new JSONObject();
    cookiesJSONObject.put("cookies", cookieJSONArray);
    if (debug) {
        System.err.println(cookiesJSONObject.toString());
    }
    doLogout();
}
Also used : Cookie(org.openqa.selenium.Cookie) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Test(org.junit.Test)

Example 28 with Cookie

use of org.openqa.selenium.Cookie in project core by weld.

the class NumberGuessClusterTest method switchBrowsers.

private void switchBrowsers() throws MalformedURLException {
    String address = getAddressForSecondInstance();
    String sid = driver.manage().getCookieNamed("JSESSIONID").getValue();
    String contextPath = browsersSwitched ? contextPath1 : contextPath2;
    // We navigate to the home page on the second server, just to set the cookies
    driver.navigate().to(new URL(contextPath));
    driver.manage().deleteAllCookies();
    driver.manage().addCookie(new Cookie("JSESSIONID", sid));
    // Now we navigate for reals
    driver.navigate().to(new URL(contextPath + "/" + address));
    browsersSwitched = !browsersSwitched;
}
Also used : Cookie(org.openqa.selenium.Cookie) URL(java.net.URL)

Example 29 with Cookie

use of org.openqa.selenium.Cookie in project browsermator by pcalkins.

the class SetCookieAction method RunAction.

@Override
public void RunAction(WebDriver driver) {
    Cookie cookie = new Cookie(this.Variable1, this.Variable2);
    driver.manage().addCookie(cookie);
}
Also used : Cookie(org.openqa.selenium.Cookie)

Example 30 with Cookie

use of org.openqa.selenium.Cookie in project cia by Hack23.

the class UserPageVisit method logoutUser.

/**
 * Logout user.
 *
 * @throws Exception
 *             the exception
 */
public void logoutUser() throws Exception {
    final WebElement logoutButton = findButton("Logout");
    assertNotNull("Expect to find a Logout Button", logoutButton);
    final Cookie cookie = driver.manage().getCookieNamed("JSESSIONID");
    final String sessionId = cookie.getValue();
    performClickAction(logoutButton);
    final WebElement body = driver.findElement(By.tagName("body"));
    body.sendKeys(Keys.ESCAPE);
    waitForBrowser(1000);
    driver.navigate().refresh();
    waitForBrowser(2000);
    final Cookie newCookie = driver.manage().getCookieNamed("JSESSIONID");
    final String newSessionId = newCookie.getValue();
    assertNotEquals(sessionId, newSessionId);
    final String url = systemTestTargetUrl + "#!" + CommonsViews.MAIN_VIEW_NAME;
    assertEquals(browser, url, driver.getCurrentUrl());
}
Also used : Cookie(org.openqa.selenium.Cookie) WebElement(org.openqa.selenium.WebElement)

Aggregations

Cookie (org.openqa.selenium.Cookie)73 Test (org.junit.Test)26 WebElement (org.openqa.selenium.WebElement)16 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 IOException (java.io.IOException)7 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)7 BasicClientCookie (org.apache.http.impl.cookie.BasicClientCookie)6 Test (org.testng.annotations.Test)6 Collectors (java.util.stream.Collectors)5 BasicCookieStore (org.apache.http.impl.client.BasicCookieStore)5 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)5 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)5 AuthorizeClient (org.gluu.oxauth.client.AuthorizeClient)5 Matchers (org.hamcrest.Matchers)5 Page (org.jboss.arquillian.graphene.page.Page)5 Assert (org.junit.Assert)5 AdminRoles (org.keycloak.models.AdminRoles)5