Dhanesh
Dhanesh

Reputation: 83

Selenium WebDriver: How to execute complete Test in testNG for a failed test case

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

Answers (3)

Durga Prasad Behera
Durga Prasad Behera

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

0xM4x
0xM4x

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

anonygoose
anonygoose

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

Related Questions