-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Session Isolation within the same Process instance.
Finally an API to support multi-cookie jar is available in PhantomJS: ariya/phantomjs#11535. This allows us to create a completely new CookieJar every time we create a Session. A version of PhantomJS with the new CookieJar API hasn't been released yet: once the commit linked above is part of a stable release, this will work. Otherwise, stick with GhostDriver 1.1.0. Fixes #170.
- Loading branch information
Showing
2 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
test/java/src/test/java/ghostdriver/IsolatedSessionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package ghostdriver; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.openqa.selenium.Cookie; | ||
import org.openqa.selenium.WebDriver; | ||
|
||
import java.util.Set; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
|
||
public class IsolatedSessionTest extends BaseTest { | ||
// New Session Cookies will be stored in here | ||
private String url = "http://www.google.com"; | ||
private Set<Cookie> sessionCookies; | ||
|
||
@Before | ||
public void createSession() throws Exception { | ||
disableAutoQuitDriver(); | ||
|
||
WebDriver d = getDriver(); | ||
d.get(url); | ||
|
||
// Grab set of session cookies | ||
sessionCookies = d.manage().getCookies(); | ||
|
||
// Manually quit the current Driver and create a new one | ||
d.quit(); | ||
prepareDriver(); | ||
} | ||
|
||
@Test | ||
public void shouldCreateASeparateSessionWithEveryNewDriverInstance() { | ||
WebDriver d = getDriver(); | ||
d.get(url); | ||
|
||
// Grab NEW set of session cookies | ||
Set<Cookie> newSessionCookies = d.manage().getCookies(); | ||
|
||
// No cookie of the new Session can be found in the cookies of the old Session | ||
for (Cookie c : sessionCookies) { | ||
assertFalse(newSessionCookies.contains(c)); | ||
} | ||
// No cookie of the old Session can be found in the cookies of the new Session | ||
for (Cookie c : newSessionCookies) { | ||
assertFalse(sessionCookies.contains(c)); | ||
} | ||
} | ||
|
||
@After | ||
public void quitDriver() { | ||
getDriver().quit(); | ||
} | ||
} |