Reputation: 83
I have test automation framework with a page object model.
Scenario:
In my testng.xml I mentioned 3 tests (Test1, Test2, Test3) which are in same package. Each Test contains 3 methods
I ran my testng.xml file and say like in Test1 only 3rd method failed. So when I'm running testng-failed.xml it tries to run only 3rd method.
But in my case I need to run complete Test i.e Test1 again.
I ran testng-failed.xml from test-output folder and verified the result but no luck.
Expected:
If any method fails (from a Test) then complete Test should be executed
Actual:
After running testng-failed.xml only failed method from a class is executed.
Upvotes: 0
Views: 431
Reputation: 337
Try implementing ITestListener and override onFinish(ITestContext context) method.
Probably you can check if @test is failing then change the status of all the passed methods and rerun again by overriding retry method of IRetryAnalyzer.
Upvotes: 0
Reputation: 470
I don't think there is a direct way of doing this in TestNG, but I think this will help you getting the idea.
Upvotes: 0
Reputation: 739
It sounds like you have created a test suite where the tests rely upon earlier ones to get into a certain state. i.e. you cannot run Test3 on its own as it relies on Test1 to do something first.
This is a bad pattern to follow.
Each of your tests should be able to be run independently. If there is setup required, it should be carried out as part of the life-cycle for that individual test, meaning in the test itself, or during BeforeEach.
It may take a little more time for the test suite to execute, but you'll avoid the issue you're currently facing.
Upvotes: 0