0

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.

Dhanesh
  • 63
  • 1
  • 13

3 Answers3

0

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.

anonygoose
  • 741
  • 3
  • 11
  • 1
    Can you please read my question again? **Tests are not dependent**. Methods which are present inside test are bit dependent like there is login in 1st method and operations are in another method. – Dhanesh Sep 06 '19 at 10:36
  • "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. " Still sounds like you've got a suite with multiple test methods in it that are dependent. I misread that Test1, Test2, and Test3 are 3 separate suites. The advice still applies, you have test methods that are dependent on others. The third test method failed, but it's dependent on test methods 1 and 2, which didn't fail. – anonygoose Sep 06 '19 at 10:52
  • correct, but my first method is login. So if I run testng-failed.xml it tries to perform operation and fails because it executes 3rd method and login is required which is in 1st method. I can use depends on annotations but I don't want that – Dhanesh Sep 06 '19 at 11:28
0

I don't think there is a direct way of doing this in TestNG, but I think this will help you getting the idea.

0xM4x
  • 460
  • 1
  • 8
  • 19
0

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.