HOWTO: Cookie manipulation with Selenium and Cloud Testing
As the Cloud Testing service uses Selenium RC, and real browsers such as Firefox, Internet Explorer, Safari, Chrome and Opera, cookie handling while running your test should be taken care of automatically. If however you want to do something special, you can override the default behaviour as follows:
Create Cookie
You can add cookies by using the ‘Create Cookie’ command.
The first argument is the name=value, e.g.
PHPSessionID=1213121
The second argument contain options for the cookie. Currenly ‘path’ and ‘max_age’ are supported.
The format is:
“path=/directory/, max_age=3600″

Create Cookie example
For example:
Delete Cookie
Cookies can also be deleted using the ‘Delete Cookie’ command. This take the cookie name as the first argument and the path as the second.
Delete Cookie example.
Full Example
In the following example, we visit a page, from which we get some cookies set by the server, we then add two cookies of our own, before deleting one of them.

Script with cookie create / delete
When we run the test, we get the following results:

Results of a test run
You are always able to view the cookies on any step that has interaction with the web server. After we have visited the page at step 1, we have the following cookies set:

Original cookies - set by server
After we set our own cookies at step 3 and 4 (CT and CT2), the next server interaction results in us having the following cookies set:

After manually added cookies
Note that the original cookies are still set, any new ones are just added.
In step 7 we delete one of the cookies we added (CT), we are left with the original ones from the server plus CT2:

After deleting the manual cookie CT
For full details of the services and features available from Cloud testing see www.cloudtesting.com
Did you enjoy this post? Why not subscribe to our feed and get articles like this delivered automatically to your feed reader.

Comments
No comments yet.
Leave a comment