TestNG - 如果测试时间太长,执行方法或失败? [英] TestNG - execute method or fail if tests take too long?

查看:29
本文介绍了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)

这篇关于TestNG - 如果测试时间太长,执行方法或失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆