Unable to get persistent cookie

436 views
Skip to first unread message

Nax143

unread,
Jul 9, 2012, 7:15:22 AM7/9/12
to seleniu...@googlegroups.com
I have to test a cookie duration in which I have to retrieve the cookies in browser.

Test : Login with check the remember me check box.
steps :
Enter User Name,
Enter Password,
Check "Remember Me " check box.
Click "Login"
Expected : Login credentials should be saved in cookie for 30 days.

The catch is , the pages are https , but I need not to do any exceptions .It handles when I give http:// itself.


I have used following code to retrieve the cookies :

****************************************************************

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

Iterator<Cookie> itr = cookies.iterator();


    while (itr.hasNext()){

    Cookie c = itr.next();

    System.out.println("Cookie Name: " + c.getName() + " --- " + "Cookie Domain: " + c.getDomain() + " --- " + "Cookie Value: " + c.getValue());

******************************************************************

the above code only returning 'session' cookie only. My web pages are 'https' , and the other cookie which I couldn't able to retrieve is (http only).

Note : I am not asking how to retrieve cookies,I am asking is there any way to retrieve cookies which are http only.


Can anyone help ? , feel free to ask me if you need more information.

David

unread,
Jul 9, 2012, 1:31:15 PM7/9/12
to seleniu...@googlegroups.com
Which domain & path are the other cookies tied to? Same domain but HTTPS?

Don't know if WebDriver works differently, but in Selenium RC, not all the browser cookies are "visible" (i.e. available) until you are in the right domain and/or page. Hence I guess that's why there's a deleteAllVisibleCookies() method in RC, which means it won't delete invisible cookies until you call the method again at the right page.

If WebDriver is similar, then you'd have to navigate to HTTP page, etc. before you can call the cookie code to get the expected cookies.

Or otherwise, you may have found a bug?

Nax143

unread,
Jul 13, 2012, 7:05:27 PM7/13/12
to seleniu...@googlegroups.com
Hi David,
I have tried to navigate to HTTP page, then I called the cookies.It worked fine for chrome driver, but I really not understand that its not working for firefox.

Please see the the method I have written for different browsers.Actually I am running via command prompt as a maven test.
*************************************

public static WebDriver getWebDriver(String ...args) throws IOException {

String param = System.getProperty("driver","html");

String grid = System.getProperty("grid", "false");

//String platform = System.getProperty("platform","WINDOWS");

WebDriver driver = null;

DesiredCapabilities cap = null;

//ChromeDriverService service;

boolean useProfile = false;

for (int i=0; i < args.length; i++) {

if ("useProfile".equalsIgnoreCase(args[i])) {

useProfile = true;

}

}


log.debug("command line parm driver - {}", param);


if ("html".equals(param)) {

if ("true".equalsIgnoreCase(grid)) {

cap = DesiredCapabilities.htmlUnit();

cap.setBrowserName("html");

cap.setPlatform(org.openqa.selenium.Platform.WINDOWS);

driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),cap);

}

driver = new HtmlUnitDriver();

} else if ("firefox".equals(param)) {

if ("true".equalsIgnoreCase(grid)) {

cap = DesiredCapabilities.firefox();

cap.setBrowserName("firefox");

cap.setPlatform(org.openqa.selenium.Platform.VISTA);

driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),cap);

}

FirefoxProfile profile = new FirefoxProfile(new File(System.getProperty("user.dir") + File.separator + "src"

+ File.separator + "test" + File.separator

+ "resources" + File.separator + "Selenium_Firefox_Profile"));

profile.setAssumeUntrustedCertificateIssuer(false);

driver = new FirefoxDriver(profile); 

} else if ("ie".equals(param)) {

if ("true".equalsIgnoreCase(grid)) {

cap = DesiredCapabilities.internetExplorer();

cap.setBrowserName("internetExplorer");

cap.setPlatform(org.openqa.selenium.Platform.WINDOWS);

driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),cap);

}

driver = new InternetExplorerDriver();

    } else if ("chrome".equals(param)) {

System.setProperty("webdriver.chrome.driver",

System.getProperty("user.dir") + File.separator + "src"

+ File.separator + "test" + File.separator

+ "resources" + File.separator + "chromedriver");

System.out.println(System.getProperty("webdriver.chrome.driver"));

if ("true".equalsIgnoreCase(grid)) {

cap = DesiredCapabilities.chrome();

cap.setBrowserName("chrome");

cap.setCapability("chrome.switches", Arrays.asList("--user-data-dir=~/selemium/profile"));

cap.setPlatform(org.openqa.selenium.Platform.WINDOWS);

driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),cap);

}

if (useProfile) {

cap = DesiredCapabilities.chrome();

cap.setCapability("chrome.switches", Arrays.asList("--user-data-dir=selenium_chrome_profile")); 

driver = new ChromeDriver(cap);

}

************************************************************
I have copied the profile and pasted under project resources.

Tried a lot, but no luck..

Any help will be appreciated.

Regards,
Venkat

David

unread,
Jul 15, 2012, 12:51:11 AM7/15/12
to seleniu...@googlegroups.com
Sorry, I don't know what you can do about this. You can try readng the cookies through Javascript to see if that makes any difference:


Reply all
Reply to author
Forward
0 new messages