I am having an issue with TestNG Selenium Webdriver 2.0, and Java. I set breakpoints and saw the strangest behavior.
I have several class files containing groups of tests. Each class begins with initializing some variables global to all tests in the class, including a call to another class which initializes the webdriver. Next is a @BeforeClass, and next are my @Test tests. I am running the classes from a testng.xml file.
On debugging an issue lately I found that at runtime, testNG does the following:
- Initialize the global variables and webdriver in class1
- Then skips over to the top of class2 and does the same
- Then skips back to class1 @BeforeClass
- Then runs the tests in class1 5 then skips back to class2
@BeforeClass and finishes from there...
Why would testNG behave this way. I have tried stepping through but testNG is compiled code so I can't figure out why it does not finish with class1, before step 2 above. Initializing the webdriver in class2 right after the webdriver in class1 creates an odd problem that I cannot do a driver.close() at the end of class1 without closing the driver of class2. And since class2 has already had its global variables and its webdriver initialized, when testNG finally moves back to class2 after class1 tests are finished, its webdriver initialization is ignored. Also at runtime I can see one webbrowser open up to one path (for class1) then go to another path (for class2). It's just not right. Any ideas why testNG is running in such an order?
@dependsOnMethods
or@dependsOnGroups
annotation. Would a solution to have a driver instance for each class? – Nathan Merrill