Eclipse 如何在if条件的函数中使用testng测试名称

Eclipse 如何在if条件的函数中使用testng测试名称,eclipse,function,selenium,testng,Eclipse,Function,Selenium,Testng,假设我有三个testng xml文件可用。如何使用它的名称或其中的变量在函数内进行验证。如果某个特定的testng xml文件已经运行,我必须在函数中使用if条件来运行某些行。下面的示例显示了如何访问名称,甚至当前的名称,以及在级别或级别定义的参数 import org.testng.ITestResult; 导入org.testng.Reporter; 导入org.testng.annotations.Test; 导入org.testng.xml.XmlSuite; 导入org.testng.

假设我有三个testng xml文件可用。如何使用它的名称或其中的变量在函数内进行验证。如果某个特定的testng xml文件已经运行,我必须在函数中使用if条件来运行某些行。下面的示例显示了如何访问
名称,甚至当前的
名称,以及在
级别或
级别定义的参数

import org.testng.ITestResult;
导入org.testng.Reporter;
导入org.testng.annotations.Test;
导入org.testng.xml.XmlSuite;
导入org.testng.xml.XmlTest;
公共类SampleTestClass{
@试验
public void sampleTestMethod(){
ITestResult result=Reporter.getCurrentTestResult();
XmlTest XmlTest=result.getTestContext().getCurrentXmlTest();
XmlSuite XmlSuite=xmltest.getSuite();
System.err.println(“名称为:”+xmltest.getName());
System.err.println(“名称为:”+xmlsuite.getName());
System.err.println(“在级别定义的参数”);
xmltest
.getLocalParameters()
弗雷奇先生(
(key,value)->System.err.println(String.format(“[key:%s,value:%s]”,key,value));
System.err.println(“在级别定义的参数”);
XML套件
.getParameters()
弗雷奇先生(
(key,value)->System.err.println(String.format(“[key:%s,value:%s]”,key,value));
}
}
下面是xml套件


这是执行输出

...
... TestNG 7.0.0-beta1 by Cédric Beust (cedric@beust.com)
...
The <test> name is : Question_53317518_test
The <suite> name is :Question_53317518_suite
Parameters defined at <test> level
[Key: test_param_two, Value: 2]
[Key: test_param_three, Value: 3]
[Key: test_param_one, Value: 1]
Parameters defined at <suite> level
[Key: suite_param_two, Value: b]
[Key: suite_param_one, Value: a]
[Key: suite_param_three, Value: c]
PASSED: sampleTestMethod

===============================================
    Question_53317518_test
    Tests run: 1, Failures: 0, Skips: 0
===============================================

===============================================
Question_53317518_suite
Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
===============================================


Process finished with exit code 0
。。。
... Cédric Beust的TestNG 7.0.0-beta1(cedric@beust.com)
...
名字是:问题号:53317518
名字是:Question_53317518_suite
在级别定义的参数
[键:测试参数二,值:2]
[键:测试参数三,值:3]
[键:测试参数1,值:1]
在级别定义的参数
[键:套件参数二,值:b]
[键:套件参数一,值:a]
[键:suite_param_三,值:c]
已通过:sampleTestMethod
===============================================
问题_53317518 _测试
测试运行:1,失败:0,跳过:0
===============================================
===============================================
问题_53317518 _套房
运行的测试总数:1,通过:1,失败:0,跳过:0
===============================================
进程已完成,退出代码为0