use of org.openqa.selenium.Cookie in project selenified by Coveros.
the class ActionGoIT method setCookieTest.
@Test(groups = { "integration", "actions", "go" }, description = "An integration test to check the setCookie method")
public void setCookieTest(ITestContext context) throws IOException, ParseException {
String dateval = "2011-11-17T09:52:13";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
Cookie cookie = new Cookie("new_cookie", "this_cookie", getTestSite(this.getClass().getName(), context).split("/")[2].split(":")[0], "/", df.parse(dateval));
// use this object to manipulate the app
App app = this.apps.get();
// perform some actions
app.setCookie(cookie);
// verify no issues
finish();
}
use of org.openqa.selenium.Cookie in project java.webdriver by sayems.
the class StoreCookieInfo method main.
public static void main(String... args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.facebook.com");
driver.findElement(By.name("email")).sendKeys("<<ur mailID>>");
driver.findElement(By.name("pass")).sendKeys("<<ur password>>");
driver.findElement(By.name("persistent")).click();
driver.findElement(By.name("pass")).submit();
File f = new File("browser.data");
try {
f.delete();
f.createNewFile();
FileWriter fos = new FileWriter(f);
BufferedWriter bos = new BufferedWriter(fos);
for (Cookie ck : driver.manage().getCookies()) {
bos.write((ck.getName() + ";" + ck.getValue() + ";" + ck.getDomain() + ";" + ck.getPath() + ";" + ck.getExpiry() + ";" + ck.isSecure()));
bos.newLine();
}
bos.flush();
bos.close();
fos.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.openqa.selenium.Cookie in project ats-framework by Axway.
the class PhantomJsDriver method getHttpOnlyCookies.
public static List<Cookie> getHttpOnlyCookies() {
List<Cookie> cookies = new ArrayList<Cookie>();
if (System.getProperty(PhantomJsDriver.HTTP_ONLY_COOKIES_PROPERTY) != null) {
String[] cookieNames = System.getProperty(PhantomJsDriver.HTTP_ONLY_COOKIES_PROPERTY).split(",");
try {
String cookiesFileContent = IoUtils.streamToString(IoUtils.readFile(PhantomJsDriver.cookiesFile));
for (String cookieName : cookieNames) {
int cookieIndex = cookiesFileContent.indexOf(cookieName + "=");
if (cookieIndex >= 0) {
int endIndex = cookiesFileContent.indexOf("\\0", cookieIndex);
if (endIndex < 0) {
endIndex = cookiesFileContent.indexOf(')', cookieIndex);
}
String wholeCookieData = cookiesFileContent.substring(cookieIndex, endIndex);
String[] cookieParts = wholeCookieData.split(";\\s+");
String value = cookieParts[0].substring(cookieParts[0].indexOf('=') + 1);
String path = null;
String domain = null;
boolean isSecure = false;
for (String cp : cookieParts) {
if ("secure".equalsIgnoreCase(cp)) {
isSecure = true;
} else if (cp.startsWith("path=")) {
path = cp.substring(cp.indexOf('=') + 1);
} else if (cp.startsWith("domain=")) {
domain = cp.substring(cp.indexOf('=') + 1);
}
}
cookies.add(new Cookie(cookieName, value, domain, path, null, isSecure));
}
}
} catch (Exception e) {
log.error("Couldn't parse HttpOnly cookeis, from the temp file: " + cookiesFile, e);
}
}
return cookies;
}
use of org.openqa.selenium.Cookie in project selenium_java by sergueik.
the class GoogleDriveTest method getCookieTest.
// @Ignore
@Test
public void getCookieTest() throws Exception {
doLogin();
Set<Cookie> cookies = driver.manage().getCookies();
if (debug) {
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 selenium_java by sergueik.
the class YandexTest method useCookieTest.
// @Ignore
@Test
public void useCookieTest() throws Exception {
String loginUrl = 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 " + loginUrl);
driver.get(loginUrl);
System.err.println("Loading cookies");
for (Cookie cookie : cookies) {
driver.manage().addCookie(cookie);
}
driver.navigate().refresh();
System.err.println("Waiting for inbox");
try {
wait.until(ExpectedConditions.urlContains("#inbox"));
} catch (TimeoutException | UnreachableBrowserException e) {
verificationErrors.append(e.toString());
}
doLogout();
}
Aggregations