testng - 质量保证 | 在 TestNg 监听器中获取场景标签
问题描述
我想在 TestNg 侦听器中获取 Scenario 标签详细信息,以帮助使用 TestcaseId 和 IntId 为每个场景编写自定义报告。
@priority:1 @TestcaseId:VFF-265 @IntId:615d440932e941018806cfc5 @sit-1
Scenario : Testing login is successfull
我实施的当前解决方法是在场景名称中添加详细信息并在 TestNg 侦听器中使用 result.getTestName() 并将详细信息与场景名称分开。此实现的唯一问题是内部 ID 和 TC id 可见并使测试用例名称变长:
@priority:1 @TestcaseId:VFF-265 @IntId:615d440932e941018806cfc5 @sit-1
Scenario : [VFF-265]_[615d440932e941018806cfc5]_Testing login is successfull
解决方案
When you are using qaf with TestNG runner, it will use TestNGScenario
as ITestNGMethod
implementation. TestNGScenario
is extended TestNGMethod
which has addition method getMetaData()
which will give you meta data of the test case. Any method from testng returning ITestNGMethod
or TestNGMethod
will return TestNGScenario
object.
Below is example
public void onTestSuccess(ITestResult tr) {
TestNGScenario scenario = (TestNGScenario) tr.getMethod();
Map<String, Object> metadata = scenario.getMetaData()
}
If you are working on custom reporting, best way is to implement TestCaseResultUpdator. You can refer qaf inbuilt reporters and qaf-support-elasticsearch.
推荐阅读
- r - RStudio 突然变得异常缓慢(2019 年 3 月 12 日)
- ruby-on-rails - Rails 预编译:如何跳过某些文件类型
- javascript - 如何在茉莉花中测试一个功能
- ios - 手动管理 fastlane match Repo
- python - 在 python 中使用 spacy 进行审查的意图
- java - 在 IntelliJ 中是否可以找到(可能)冗余的 try...catch 块?
- jenkins - 错误 403 No Valid Crumb 包含在请求中
- java - 在 TomEE 中共享公共 EJB JAR 的多个应用程序
- android - 在 Android 上的 Realm 中创建 10000 个对象时崩溃
- cqrs - 自动扩展 Axon 的跟踪事件处理器