TestNG - execute method or fail if tests take too

2019-08-24 04:24发布

问题:

I have a set of maybe 500 selenium tests using the TestNG framework.

Occasionally, a particular test will hang for no apparent reason (see my last question) which will stop the tests from proceeding further.

If I manually close the browser, then that test will fail and the tests will resume. I have a way to restart the browser if such an instance occurs, but I need a way for my code to know if it happens.

My best guess would be a timer where if a particular test takes longer than 15 minutes to execute I can just kill the browser, but I can't find a way to continually monitor each test for that trigger.

回答1:

You can use timeOut annotation, see tutorial, for example :

@Test(timeOut = 2000)