我创建了一个testng.xml文件来运行我的selenium webdriver测试套件。从eclipse我可以运行它作为testNG Suite,但是从命令中我得到以下错误。
的testng.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "testng.org/testng-1.0.dtd">;
<suite name="CATS Regression Suite">
<test name="WEB UI">
<parameter name="uid" value="TestAccount"/>
<parameter name="pid" value="Test123"/>
<classes>
<class name="VerifyLogin"/>
</classes>
</test>
<!-- Test -->
</suite>
<!-- Suite -->
命令运行:
java org.testng.TestNG testng.xml
异常追踪:
[Error] org.testng.TestNGException:
Cannot inject @Test annotated Method [main] with [class [Ljava.lang.String;].
For more information on native dependency injection please refer to http://testng.org/doc/documentation-main.html#native-dependency-injection
at org.testng.internal.Parameters.checkParameterTypes(Parameters.java:244)
at org.testng.internal.Parameters.createParameters(Parameters.java:172)
at org.testng.internal.Parameters.createParameters(Parameters.java:458)
at org.testng.internal.Parameters.handleParameters(Parameters.java:568)
at org.testng.internal.Invoker.handleParameters(Invoker.java:1293)
at org.testng.internal.Invoker.createParameters(Invoker.java:1020)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1110)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:756)
at org.testng.TestRunner.run(TestRunner.java:610)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
at org.testng.TestNG.runSuites(TestNG.java:1133)
at org.testng.TestNG.run(TestNG.java:1104)
at org.testng.TestNG.privateMain(TestNG.java:1434)
at org.testng.TestNG.main(TestNG.java:1403)
代码(在评论中共享)
public class VerifyLogin extends TestBase {
@Parameters({"uid","pid"})
@Test
public void verifyLogin(String uid, String pid) throws IOException, Exception {
String userName = uid;
String passWord = pid;
// new instance
ExtentReports extent = new ExtentReports("C:\\Users\\AdvancedReport.html", true);
//starting test
ExtentTest test = extent.startTest("Login Test", "Regression");
// log step
test.log(LogStatus.PASS, "Browser Running");
TestBase login=new TestBase();
login.testLogin(userName, passWord);
}
}
答案 0 :(得分:2)
只需在main方法中删除String uid
,String pid
,然后再次运行
public void verifyLogin(String uid, String pid)
到
public void verifyLogin()