【问题标题】:Screenshot capture of Selenium tests when parallel execution is enabled in Junit5在 Junit5 中启用并行执行时 Selenium 测试的屏幕截图
【发布时间】:2019-10-03 06:34:07
【问题描述】:

我正在使用页面对象模式。我在 Watcher 类中实现了 TestWatcher 接口来处理测试用例结果。为了对通过/失败的测试用例进行截图,我需要一个 WebDriver 实例,驱动程序可用。如果我将驱动程序声明为静态,那么它在顺序模式下运行良好,但在打开并行执行时失败。看起来 Junit 对单个类中的所有测试方法使用单线程。如果我没有将驱动程序声明为静态,那么来自 TestWatcher 方法的 ExecutionContext 对象不会给我测试方法失败的类名。我只能获得定义 @Test 的类名。请建议是否有办法实现它,如果我在这里遗漏了什么。谢谢。

我尝试将驱动程序声明为静态和非静态。

【问题讨论】:

    标签: selenium junit5


    【解决方案1】:

    我删除了静态 WebDriver 声明和 ale 以从 ExtensionContext 中获取 WebDriver 的实例。

    Field field = context.getRequiredTestInstance().getClass().getDeclaredField("driver");
    field.setAccessible(true);
    WebDriver driver = (WebDriver) field.get(context.getRequiredTestInstance());
    

    【讨论】:

      猜你喜欢
      • 2021-05-23
      • 2013-12-06
      • 2019-02-08
      • 2018-10-28
      • 1970-01-01
      • 2013-09-02
      • 2015-06-07
      • 2022-08-16
      • 1970-01-01
      相关资源
      最近更新 更多