testng同时使用@Parameter和DataProvider
selenium跑case的时候使用testng驱动,想在testng.xml中配置多个test,对应不同的浏览器,然后在具体的test中使用DataProvider来获取测试数据,但是在运行过程中报参数没有在testng.xml中定义,这个搞不定了。难道是testng不支持这样使用么。报错信息如下:
Parameter 'browserType' is required by @Configuration on method before but has not been defined in C:cygwin64homevictorworkspaceselenium-spoon-samplersrctestresourcestestng.xml at org.testng.internal.Parameters.createParameters(Parameters.java:109) at org.testng.internal.Parameters.createParameters(Parameters.java:264) at org.testng.internal.Parameters.createConfigurationParameters(Parameters.java:69) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:135) at org.testng.internal.Invoker.invokeMethod(Invoker.java:427) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:607) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:874) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.runWorkers(TestRunner.java:689) at org.testng.TestRunner.privateRun(TestRunner.java:566) at org.testng.TestRunner.run(TestRunner.java:466) at org.testng.SuiteRunner.runTest(SuiteRunner.java:301) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:296) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:276) at org.testng.SuiteRunner.run(SuiteRunner.java:191) at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:808) at org.testng.TestNG.runSuitesLocally(TestNG.java:776) at org.testng.TestNG.run(TestNG.java:701) at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:178)
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="Suite"> <test name="Browser Compatibility Test Cases--firefox" thread-count="1" preserve-order="false"> <parameter name="browserType" value="firefox" /> <classes> <class name="com.yeetrack.selenium.test.ParameterTest" /> </classes> </test> <test name="Browser Compatibility Test Cases--chrome" thread-count="1" preserve-order="false"> <parameter name="browserType" value="chrome" /> <classes> <class name="com.yeetrack.selenium.test.ParameterTest" /> </classes> </test> </suite>
package com.yeetrack.selenium.test; import com.yeetrack.selenium.data.KeywordData; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Parameters; import org.testng.annotations.Test; /** * Created by xuemeng.wang on 2014/8/4. */ public class ParameterTest { @Parameters("browserType") @BeforeMethod public void before(String browser) { System.out.println(browser); } @Test(dataProvider = "KeywordDataProvider", dataProviderClass = KeywordData.class) public void test(String keyword) { System.out.println(keyword); } }
package com.yeetrack.selenium.data; import org.testng.annotations.DataProvider; /** * Created by xuemeng.wang on 2014/7/29. */ public class KeywordData { @DataProvider(name="KeywordDataProvider") public static Object[][] keywordProvider() { return new Object[][] {{"apache"}, {"tomcat"}}; } }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
@Parameters({"browserType"}) 这个和@Parameters("browserType")是等价的。
@Parameters({"browserType"})
呃,仔细检查了,原来我pom.xml 中testng引错了。一切正常。thx
刚刚试了一下,毫无压力