Testng如何将参数传递给侦听器 [英] Testng how to pass parameter to the listener
问题描述
我想知道一种通过我的suite.xml或代码本身在侦听器内部传递参数的方法
I would like to know a way to pass a parameter inside a listener eater from my suite.xml or by the code itself
我需要进行此并行测试,以准确了解我正在哪个设备上运行测试以做出一些报告
I need this in parallel test to know exactly on which device I'm running a test in order to make some reports
这是我想要实现的目标的一个示例
this is an example of what I have / wish to achieve
套件文件
<suite name="SearchButton" parallel="tests" thread-count="5">
<test name="SamsungS6">
<parameter name="deviceUDID" value="04157df40862d02f"/>
<classes>
<class name="MyTestScenario"/>
</classes>
</test>
</suite>
或
@Test
public void researchText (){
String DeviceUDID = "1234";
}
我希望能够在侦听器中找到设备UDID
I want to be able to find device UDID in my listener
public void onTestSkipped(ITestResult result) {
System.out.println("My deviceUDID ");
}
我试图用
System.getProperty("deviceUDID") // or
result.getAttribute() // or
result.getParameters()
没有成功
有什么想法吗?
推荐答案
我终于找到了一种方法. 可以认为它可以解决,但确实可以解决问题.
I did finally found a way to do it. It can maybe be considered as a work around but it does the job.
在ITestListener侦听器中,我已经看到我们有一个onStart
方法,该方法使我可以从.xml文件中访问参数
In the ITestListener listener I've seen that we have a onStart
method that allows me to access the parameter from the .xml file
deviceUDID = context.getCurrentXmlTest().getParameter("deviceUDID");
现在我已经将它保存在侦听器中,我只需要将其保存在变量中并通过onTestSkipped
方法访问它
And now that I have it inside the listener I just had to save it in variable and access it in the onTestSkipped
method
这篇关于Testng如何将参数传递给侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!