Re: [selenium-users] Reusing browser session across multiple test cases

1,614 views
Skip to first unread message

Brijesh Yadav

unread,
May 23, 2013, 7:50:47 AM5/23/13
to seleniu...@googlegroups.com
Hi Ambika

you make your webdriver as static then all execution will be done with signle browser.


On Thu, May 23, 2013 at 5:09 PM, Ambika Kuppusamy <ambikak...@gmail.com> wrote:
Boxbe This message is eligible for Automatic Cleanup! (ambikak...@gmail.com) Add cleanup rule | More info

Hi All,

I am using Junit 4 and Selenium webdriver in my automation process. I have multiple test cases (more than 100)  and each test case requires login functionality.

I want to run all the test cases in the same browser window and maintain the login session instead of opening the new browser for each test case and do login everytime. (In my current scripts, am initiating webdriver in each test script and it opens a new window for each test case and do login every time)

I want to run a test suite, in which i want to run all my test cases in the same browser window. Please provide me a solution.

Thanks in advance,
Ambika.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/aff929d2-3e33-4e6b-b499-7aa9713a1262%40googlegroups.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


Oscar Rieken

unread,
May 23, 2013, 8:04:54 AM5/23/13
to seleniu...@googlegroups.com
The reason this is not a good idea.

Every test changes the state of the browser cookies, cache, things in the profile and such. now test may pass or fail depending on the browser being in a state where it was left by another test.
I would suggest that instead of trying to speed up your tests by running them in one browser that perhaps you may want to explore running them on the grid. this will speed up your execution time and allow you to now have your tests dependent on the state the browser was left in by the previous test


   


Krishnan Mahadevan

unread,
May 23, 2013, 8:16:19 AM5/23/13
to Selenium Users
To add to what Oscar said, there is one more additional headache here.. All your tests would now have to run in "Sequence" and CANNOT run in parallel, because they all now would try to compete with the same browser.

If you let them run in parallel and are using the same browser instance, then its as good as "organized chaos" :)



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/


Ambika Kuppusamy

unread,
May 23, 2013, 1:43:19 PM5/23/13
to seleniu...@googlegroups.com
Thanks for the replies.

I will try using the selenium grid..

Is it possible to maintain the browser session across multiple test cases if the test cases run in different browser in sequnces?

I want to maintain the browser session across the test cases to avoid executing the login action in each test class. 
All my test cases contain the below methods:
1. @Before setup() - Webdriver instantiation
2. Test() - Login action and test case related actions
3. @After tearDown()

Please provide me a solution to maintain the browser session for login action for all the test cases. Please share sample code for the same. 

Thanks in Advance,
ambika.

Krishnan Mahadevan

unread,
May 24, 2013, 1:58:29 AM5/24/13
to Selenium Users
Ambika,

If you basically want to leverage a pre-logged in session in your downstream tests, then you are left with no other choice but to just sequence them as sequential tests and all of them would run in the same browser.

A Browser session CANNOT be shared across multiple browser sessions, unless and until you manage to recreate "an already logged in user" state via your code.

Your web application may be tracking "logged in" users via either cookies or via some server side mechanism, which ONLY you would be knowing.

If its based on cookies, then you could write code which basically does the following:

1. After a user logs in, your code sniffs up the cookies that are created and via code adds those cookies into the other browser sessions which need a user to be logged in.

Since my web programming skills are close to "zilch" I have no idea if all of this is even possible.

So I will strongly recommend that you tweak your tests such that each of them can run on their own. Not sure what exactly would you be saving here by just having one login and then have rest of your tests try to bank on that session to proceed ahead. To me personally that sounds like a recipe for chaos.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/


Mayank Agarwal

unread,
Feb 4, 2019, 12:55:09 AM2/4/19
to Selenium Users
Hi Ambika,

Did you finally got the solution for it? I am working exactly on the same thing.

Thanks,
Mayank
Reply all
Reply to author
Forward
0 new messages