'Is there a way to have selenium store the cookie so I can call it, in java code?
So, basically I am using selenium to automate testing against a web application.
- I am using Java imported in from the Selenium IDE of the basic steps and then I am adding some additional Java code.
- Then I am sending it to the Selenium server to execute the automation steps.
Here is what the code is doing broken down into 2 parts:
Part 1:
This is basically some steps to log into the web application.
It has username and password and it sends a POST with POSTDATA to the server.
Everything here is done through Selenium, and you can see it completed when the test is being run, in a web browser as Selenium automates through.
Part 2:
This is basically some steps that sends usernames within the database to a php file on the server using a POST and POSTDATA. (In order to send this POST properly it requires authentication with the web app from Part 1.)
Everything here is done through Java.
Problem:
So the problem I am running into is that Part 1 and Part 2 seems to be treated as mutually exclusive. Once I authenticate with the web application using Selenium, the plain Java code is not using that session. I am having to copy the cookie from the HTTP Headers to directly insert it into the POST in Part 2 from Part 1. This seems to be a very manual process, in getting Part 2 to work.
So I was wondering if there was a way in Part 1 to have Selenium store the cookie somewhere after it authenticates and log ins. (maybe store the cookie into an object or something)
So that in Part 2 I can use Java to call that object and fill in the cookie into the required field, and complete a 2nd POST to the web application without having to manually give it a valid cookie.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
