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();
}
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();
}
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;
}
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);
}
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());
}
Aggregations