java - webdriver,捕获@Test(超时= 10000)

标签 java selenium junit webdriver

我的 webdriver 测试使用 @Test(timeout = 10000) 进行注释,以强制测试在 10000 毫秒后结束。如果出现错误,这可以防止我的测试整夜挂起。

但是,我的测试还将附加信息写入文件,如果测试以这种方式超时,则该行不会写入文件。是否可以捕获这种类型的超时?

@Test(timeout = 100000)
public void testSomething() throws Exception
{
    //Do some stuff
    //If this times out, the line below is never called.
    //print something to a file
}

最佳答案

我建议实现 JUnit Rule .
只需扩展 TestWatcher类并重写 succeeded 方法。

关于java - webdriver,捕获@Test(超时= 10000),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16667882/

相关文章:

java - 用于部署 Web 应用程序的 Infinispan 独特缓存管理器

java - 在 Spring 中解析 MongoRepository 的变量名称

java - 我在哪里可以下载 common-annotations.jar

java - 如何使用 mockito 为同一类的私有(private)方法 stub 返回值

unit-testing - 从另一个 JUnit 测试类运行 JUnit 测试类

java - ExecutorService - 并行运行任务并保存结果

selenium - 使用 Javascript 进行敏捷开发

python - 如何通过 Python 使用 GeckoDriver 和 Selenium 启动使用默认 Firefox 到 68.9.0esr 的 Tor 浏览器 9.5

java - Selenium WD/Java |无法创建 'if' 和 'else if' 语句

java - Spring - 从 JUnit 和 Maven 运行时的不同测试结果