如何从命令行和eclipse运行testng

时间:2018-04-20 09:16:38

标签: maven testng pom.xml

通过使用下面的代码,我可以从命令行运行。这里我从命令行传递浏览器变量: mvn test -DsuiteXmlFile=testng.xml -Dbrowsers=chrome

<systemPropertyVariables>
    <environment>${browsers}</environment>
</systemPropertyVariables>

但是我尝试从eclipse testng.xml文件运行的方式相同。我无法跑。我收到了以下错误

java.io.FileNotFoundException: .\data\null.xlsx (The system cannot find the file specified) at java.io.FileInputStream.open0(Native Method) at java.io.FileInputStream.open(Unknown Source) at java.io.FileInputStream.(Unknown Source) at utils.DataInputProvider.getAllSheetData(DataInputProvider.java:17) at wrappers.LoopCommerce.getData(project.java:48) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85) at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:136) at org.testng.internal.Parameters.handleParameters(Parameters.java:441) at org.testng.internal.Invoker.handleParameters(Invoker.java:1300) at org.testng.internal.Invoker.createParameters(Invoker.java:1015) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1104) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108) at org.testng.TestRunner.privateRun(TestRunner.java:771) at org.testng.TestRunner.run(TestRunner.java:621) at org.testng.SuiteRunner.runTest(SuiteRunner.java:357) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310) at org.testng.SuiteRunner.run(SuiteRunner.java:259) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1199) at org.testng.TestNG.runSuitesLocally(TestNG.java:1124) at org.testng.TestNG.run(TestNG.java:1032) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)

Pom.xml:

   <build>
  <!-- To define the plugin version in your parent POM -->
  <pluginManagement>
   <plugins>
   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>2.21.0</version>
     <configuration>
                <systemPropertyVariables>
                    <environment>${browsers}</environment>
                </systemPropertyVariables>
      <suiteXmlFiles>
            <suiteXmlFile>src/main/resources/${suiteXmlFile}</suiteXmlFile>
      </suiteXmlFiles>
    </configuration>
   </plugin>
 </plugins>

      

班级档案:

@BeforeClass
@Parameters({"environment", "saksurl"})
public void setData(String environment, String saksurl) {
    browserName = environment;
    url = saksurl;
    dataSheetName="TC001";
}

0 个答案:

没有答案