Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing TestNG code for the below scenario and do not know how to share browser session between two methods:
1. Creating a data driven testNG suite to login using 10 different usernames
I need to write two methods and both methods should share the same browser session. Any idea how to share browser session between two test methods using TestNG?

share|improve this question

I don't quite get why you would like to share browser session. UI test methods should be run in the own independent browser. In case you insist, you could use @BeforeClass of TestNG and have driver set up done in @BeforeClass method. Now both of your methods should be either in this class or class with extends the set up class. Confused? This might help -

public class TestCase {

  public void setup() {
    // Set up driver here

  public void tearDown() {
    // kill driver here


And you test class here -

public class MyHorribleClassWhichUsesSameBrowserForMultipleTests extends TestCase{

  public void method1() {
    // test code here

  public void method2() {
    // test code here

Here both test methods would be using same browser one after another.

share|improve this answer
Is there not a parameter in @WebTest like "keepBrowserOpen" or "OpenNewSession" (bool) ? – R11G Oct 12 '13 at 17:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.