2

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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for fast answear .. one more thing, my TestCases are in separete classes ex. TestLogin is in TestLogin.java, TestSendEmail in TestSendEmail.java and all that classes extendeds my GenericClass where i have stuff like BeforeClass AfterClass .. I could not manage to have one browser instance for all this classes .. is there way to restart browser instance, delete cookies and run next TestCase in same instance?
Couldn't you try the method described in this answer in a test suite instead of a test case? You would just call all your test cases from the test suite. The test cases could access the driver from the test suite statically. The test suite call the BeforeClass method before running the test cases. You could also use a AfterClass method to quit the driver.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.