如何使用 TestNG 侦听器从测试方法中获取变量值

编程入门 行业动态 更新时间:2024-10-08 01:24:00
本文介绍了如何使用 TestNG 侦听器从测试方法中获取变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在使用 TestNG 运行自动化测试.我还实现了 TestNG Listener 以某种格式保存测试结果.

I'm using TestNG to run automation tests. I also implemented TestNG Listener to save the test results in a certain format.

对于某些特定场景,我需要执行以下操作:当测试运行时,一个值被分配给一个变量(局部方法变量).我需要将变量的值传递给我实现的 TestNG Listener 类.有多种方法(ontestStart、onTestFinish、onTestSuccess/Failure/Skipped),但我无法弄清楚如何在运行时获取变量.我在 TestNG 文档中没有找到它.

For some specific scenario I need to do the following: When a test runs, a value is assigned to a variable (local method variable). I need to pass the value of the variable to the TestNG Listener class I implemented. There are various methods (ontestStart, onTestFinish, onTestSuccess/Failure/Skipped), but I cannot figure out how to get the variable at run time. And I didn't find it in TestNG documentation.

有人可以帮忙吗?或者分享他/她在类似问题上的经验.

Can anyone please help? Or share his/her experience with a similar issue.

谢谢!

推荐答案

你可以试试通过 监听方法调用并将值设置到 [ITestResult](http://testng/javadocs/org/testng/IAttributes.html#setAttribute(java.lang.String, java.lang.Object)).然后您会发现 ITestResult 中的值到 您的自定义记者.

You can try by listening to the method invocations and set values into the [ITestResult](http://testng/javadocs/org/testng/IAttributes.html#setAttribute(java.lang.String, java.lang.Object)). Then you'll find the values from ITestResult into your custom reporter.

这篇关于如何使用 TestNG 侦听器从测试方法中获取变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 22:05:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1400882.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:侦听器   如何使用   测试   方法   变量值

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!