selenium-webdriver - 如何通过 Listener 类为 TestNG 的 @BeforeSuite 方法设置超时
问题描述
我想通过 Listener 类为 BeforeSuite 方法设置一些超时。我找不到这方面的帮助。(我正在使用 Selenium WebDriver)我有很多测试套件,我们为每个测试设置了超时时间,并且还想限制 BeforeSuite 方法的时间。我想通过一个监听器来设置它,而不是在每个套件中添加它。
@BeforeSuite(groups = {"aa-bb-cc"})
public void abcdef(ITestContext context) throws Exception {
....}
@AfterSuite(groups = {"aa-bb-cc"})
public void cleanup() {
quitDriver();
}
如何使用侦听器为上述 2 种方法设置超时(而不是像 @BeforeSuite(groups = {"aa-bb-cc"}, timeOut=600000) 那样对超时进行硬编码)
解决方案
您可以使用 org.testng.IAnnotationTransformer2
文档, Java 文档 IAnnotationTransformer2
如果要修改除 @Test 之外的任何 TestNGannotation,请使用此接口而不是 IAnnotationTransformer。
您将需要覆盖具有参数 IConfigurationAnnotation 的方法
@Override
public void transform(IConfigurationAnnotation annotation, Class testClass,
Constructor testConstructor, Method testMethod) {
annotation.setTimeOut(10);
}
推荐阅读
- java - Docker java api , java - docker
- python - imagenet 分类错误
- javascript - Javascript查找第N位数字算法性能
- react-native - 调试签名的反应本机apk
- laravel - 如何在 Laravel 导入期间跳过 csv 文件中的空白行
- sql - 如何交叉检查有 2 个重复条目的 2 个表
- java - 如何使用 PDFBox 2 密集合并 PDF 文件,而分页符附近没有空格?
- angular - 如何使用 Angular 或 Django 制作可打印的报告(几个图表)
- ios - 如何在没有中间目录的画廊中编写视频?
- android - 将数据片段传递给活动时出错