Reputation: 171
I currently have a web application using Selenium. Currently there is a page for authentication (check login/password). If successful, there is a jsp that will contain a UI to connect logic assuming a successful login.
Now I want to go directly to the business logic page in an existing session. My question is there something kind of like cookies or session to keep track of so on the back end it can get passed on to the page so that the page with the tasks comes up. Currently it just treats it is redirecting to username as password.
Upvotes: 2
Views: 1542
Reputation: 2199
Instead of storing session data, you can just re-use the WebDriver.
If I am understanding you correctly, it sounds like all you'll need to do is get/navigate to your desired page, using the same WebDriver which you previously used to log in.
For example, if in your current setup you have a test which successfully logs in, rather than quitting the WebDriver, you could set it in some field.
In the class:
WebDriver driver = null;
WebDriver loggedInDriver = null;
@Before
public void setupTest() {
driver = new FirefoxDriver();
}
In the test which successfully logs in:
logIn();
loggedInDriver = driver;
Then in your test which needs to be "in an existing session" - instead of using a new WebDriver, use the one you had set aside.
//driver.get(...);
loggedInDriver.get(...);
The only catch is your test which logs in will need to run before the test in question. You could include a check in the test, which checks that the loggedInDriver
field has been set (is not still null) and if not, call your method to login before proceeding.
Upvotes: 2