答案 0 :(得分:2)
您可以在“运行配置”屏幕中通过两种方法将值传递给TestNG
以下示例显示了如何从“运行”配置中读取这些值
import org.testng.annotations.Test;
public class HelloWorldTestClass {
@Test
public void testMethod() {
//This is how we read values provided via the Environment tab section of the run configuration.
String environment = System.getenv("env");
//This is how we read values provided via the VM arguments section
String browser = System.getProperty("browser");
System.err.println("Running on [" + browser + "] in the environment [" + environment + "]");
}
}
下面是执行的输出:
[RemoteTestNG] detected TestNG version 6.14.3
Running on [Opera] in the environment [Production]
PASSED: testMethod
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================