TestNG - 如果测试时间太长,执行方法或失败?

TestNG - 如果测试时间太长,执行方法或失败?

问题描述:

我有一组使用 TestNG 框架的大约 500 个 selenium 测试.

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.

我最好的猜测是一个计时器,如果某个特定测试的执行时间超过 15 分钟,我可以杀死浏览器,但我找不到一种方法来持续监控该触发器的每个测试.

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.

可以使用timeOut注解,见教程,例如:

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

@Test(timeOut = 2000)