我正在尝试使用TestNG为并发跨浏览器测试框架工作。但似乎我无法从父类中获取@Parameters并继续获取
Parameter 'browsername' is required by @Configuration on method setup but has not been marked @Optional or defined
at org.testng.internal.Parameters.createParameters(Parameters.java:155)
at org.testng.internal.Parameters.createParameters(Parameters.java:358)
at org.testng.internal.Parameters.createConfigurationParameters(Parameters.java:86)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:199)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:348)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)
at org.testng.SuiteRunner.run(SuiteRunner.java:254)
的testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="1265_Suite" parallel="tests" verbose="2" thread-count="2" preserve-order="true">
<test name="92" parallel="false" preserve-order="true">
<classes>
<class name="com.javacodegeeks.testng.maven.BaseTest"/>
<class name="com.javacodegeeks.testng.maven.ChildTest"/>
<parameter name="browsername" value="chrome"/>
</classes>
</test>
<test name="93" parallel="false" preserve-order="true">
<classes>
<class name="com.javacodegeeks.testng.maven.BaseTest"/>
<class name="com.javacodegeeks.testng.maven.ChildTest"/>
<parameter name="browsername" value="firefox"/>
</classes>
</test>
</suite>
BaseTest
public class BaseTest extends Assert {
protected String browser;
@BeforeClass
@Parameters({"browsername"})
public void setup(String browsername) {
System.err.println("Browser name in @BeforeClass is " + browsername);
this.browser = browsername;
}
}
ChildTest
public class ChildTest extends BaseTest {
@Test
public void test() {
System.out.println(browser);
}
}
我没有找到足够的信息来说明如何让它工作,所以如果你有任何想法我想听听它们。
已经检查但信息不足: TestNG Annotations in a Superclass
答案 0 :(得分:0)
再次尝试使用<parameter>
节点上的<test>
个节点(并且BaseTest
应该没用):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="1265_Suite" parallel="tests" verbose="2" thread-count="2" preserve-order="true">
<test name="92" parallel="false" preserve-order="true">
<parameter name="browsername" value="chrome"/>
<classes>
<!--class name="com.javacodegeeks.testng.maven.BaseTest"/-->
<class name="com.javacodegeeks.testng.maven.ChildTest"/>
</classes>
</test>
<test name="93" parallel="false" preserve-order="true">
<parameter name="browsername" value="firefox"/>
<classes>
<!--class name="com.javacodegeeks.testng.maven.BaseTest"/-->
<class name="com.javacodegeeks.testng.maven.ChildTest"/>
</classes>
</test>
</suite>