Reuse web session between 'test cases'

I have not been able to find out how I can share a single web browser session between Test Cases, in a Test Suite. Can you help?

… Something like tracking the web browser session a Profiles>default variable.
Then using a test called connect to start a web browser, and logging in, before the rest of the test suite’s tests .

In Selenium-IDE, I used a single web browser because I ran ‘test suites’ for a given web application panel. A ‘test suite’ would contain many ‘tests’ but all tests would share the same web browser (with occasional refreshes).

This helps me because our complex web app requires a login, stores data over time, and there were some web browser persistence issues. Many ‘test suites’ shared common ‘tests’ to cut down on the redundancy. I understand that best practice might be to open a session for every test.

Can you use a single browser ? I mean you can remove the WebUI.closeBrowser() and WebUI.openBrowser() at the end of each test case (except for the first one and the last one would contain WebUI.openBrowser() and WebUI.closeBrowser() respectively). This way the test cases in between will be executed on the current browser session.

For something more sophisticated, shoutout to @Russ_Thomas to share some experiences.

1 Like

you can put WebUI.closeBrowser() in test listener, after suite is executed

That description covers my AUT too.

I don’t know about “best practice” here - not even sure I’d agree with one best practice if it were offered. My approach is to try to test “user stories”. A user story is a clearly defined workflow that moves through the app from a clearly defined beginning to a clearly defined end point. In that sense, a user story is a test case.

Sometimes, a collection of test steps might be repeated in a few Test Cases along the way. I make a judgement call as to whether they should be encapsulated as a notional sub-test-case, or repeated verbatim - perhaps I will encapsulate as a Keyword, other times I may create a TC which is designed to be called via callTestCase. It really depends on the specifics in effect at the time. And hey, this is software, not hardware, you can change your mind later :wink:

When a bug/issue is logged in our bugtracker, my first reaction is to treat it as a missed test case. I try to find the nearest matching user story covered by a test case. If it’s extremely close to an existing story, the extra steps are added to the TC. If it’s not matched by any existing story, a new user story is written to cover the bug, a new TC is created to cover it and to ensure it truly exposes the issue to guard against future regressions.

Now to your question: A user story, as I’ve defined it above, always includes a login and always uses a fresh new browser.

Best practice? I honestly don’t know. It works for me, for my AUT and my infrastructure.

HTH.