Reputation: 1206
I have read many of the articles out here on this topic and have yet to find the one that resolves my issue.
Goal:
Each test class has an init method that initializes the browser, so I understand why I am getting n number of browser windows open right off the bat, one for each test class.
What I'd like to happen is...
Kick off Test Class A Run all methods in Test Class A Clsoe the browser via @AfterTest method in Test Class A Move on to Test Class B ...
I am hoping there is some way that I can get TestNG to do this. Also, I am kicking off the tests from maven command line using 'mvn test -Dbrowser=chrome' with the surefire plugin that calls on my defined TestNG.xml file.
Current TestNG.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<listeners>
<listener class-name="com.infdig.qa.Listeners" />
<listener class-name="com.infdig.qa.resources.ExtentReporterNG" />
</listeners>
<test name="Regression" >
<classes>
<class name="com.infdig.qa.BasicSiteNavigationTests">
<methods>
<include name="openedToDashboard" />
<include name="navigateToActiveReleasePreset" />
<include name="navigateToReleasePresets" />
<include name="navigateToComponentSelections" />
<include name="navigateToOrderSlices" />
<include name="navigateToAbout" />
</methods>
</class>
<class name="com.infdig.qa.AboutPageTests">
<methods>
<include name="validateAboutPageDescriptionText" />
<include name="validateAboutPageLegalText" />
<include name="validateAboutPageHelpText" />
<include name="validateHelpLinkToInfinityPortal" />
</methods>
</class>
<class name="com.infdig.qa.ReleasePresetTests">
<methods>
<include name="deleteAllExistingPresets" />
<include name="createInitialPresets" />
<include name="changeActivePreset" />
<include name="addNewReleasePreset" />
<include name="deletePreset" />
<include name="addMultiplePresets" />
<include name="searchForPresetByName" />
<include name="deleteMultiplePresetsAtOnce" />
<include name="validateHelpTextIsAccurate" />
</methods>
</class>
<class name="com.infdig.qa.OrderSliceTests">
<methods>
<include name="deleteAllSlices" />
<include name="createNewOrderSlice" />
<include name="editExistingOrderSlice" />
</methods>
</class>
</classes>
</test>
</suite>
Upvotes: 0
Views: 1890
Reputation: 1038
Your TestNG xml runner file doesn't have an important parameters
I think you're mixing up the AfterTest method and AfterClass method, after test method will close your browser once, WHY? Because in the xml file you have 1 test tag only , AfterTest method is running accordingly to test tags. As you wrote I understand that you wanna run test methods of class A then of class B, to do that you must put each class tag inside test tag which means you have 4 class tags so that you need 4 test tags.
OR
You can keep the xml like above but you have to change AfterTest method to AfterClass.
Here are the annotations differences:
@AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the tag have run.
@AfterClass: The annotated method will be run after all the test methods in the current class have been run.
@AfterMethod: The annotated method will be run after each test method.
Upvotes: 2