user1697675
user1697675

Reputation: 21

Selenium 2 - How to run multiple JUnit tests with one WebDriver Instance in Java?

my TestCases (TestClasses) like TestLogIn, TestLogOut, TestSendEmail, TestDeleteEmail etc are starting everytime new ChromeDriver instance .. How can I run multiple tests with one WebDriver instance? Can anyone provide me some example?

My structure in java:

GenericClass.java:

public class GenericClass extends TestCase
//some code

TestLogin.java:

public class TestLogin extends GenericClass
//code

Upvotes: 2

Views: 2709

Answers (1)

Maria Lingo
Maria Lingo

Reputation: 131

My idea for solving this was to make the WebDriver static.

public class ProjectTests { 
static WebDriver driver;
@BeforeClass
public static void setStuff() 
{   
    driver = new FirefoxDriver();
}
@Test
public void testOne(){}

Then, you can pass the driver instance to each of the test methods. The tests will be performed in the same instance of the WebDriver. Maybe it's not the most elegant method of doing it, but for me it works.

Upvotes: 2

Related Questions