简体   繁体   中英

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 ie 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.

It sounds like you have created a test suite where the tests rely upon earlier ones to get into a certain state. ie 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.

我认为TestNG中没有直接的方法,但是我认为将帮助您理解。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM