詹金斯无法检查参数testng

时间:2016-03-17 17:50:24

标签: maven jenkins testng

我正在尝试使用testng在jenkins中构建我的测试。所以我配置了一个可以运行我的测试的testng.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TestRun">
    <test name="TestRunFireFox">
        <parameter name="browser" value="firefox"/>
        <classes>
            <class name="Data.Tests.TestRun" />
        </classes>
    </test>
</suite>

如果我只是在本地运行它将获得firefox浏览器没有任何问题。但如果我试图建立它扔jenkins它会给我以下错误

Exception org.testng.TestNGException

Message: Parameter 'browser' is required by @Configuration on method startup but has not been marked @Optional or defined
Stacktrace:




at org.testng.internal.Parameters.createParameters(Parameters.java:165)
at org.testng.internal.Parameters.createParameters(Parameters.java:372)
at org.testng.internal.Parameters.createConfigurationParameters(Parameters.java:90)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:199)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:140)
at org.testng.TestRunner.beforeRun(TestRunner.java:645)
at org.testng.TestRunner.run(TestRunner.java:613)
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.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:70)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:158)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:98)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:111)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)

我认为它与我的参数有关,但我看不出它是什么。这也是我的pom文件,我认为它是正确配置的

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>intix</groupId>
    <artifactId>automation</artifactId>
    <version>1.1-SNAPSHOT</version>


    <properties>
        <testng.version>6.9.4</testng.version>
        <selenium.version>2.46.0</selenium.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>${testng.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.52.0</version>
        </dependency>
        <dependency>
            <groupId>org.uncommons</groupId>
            <artifactId>reportng</artifactId>
            <version>1.1.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.7</version>
        </dependency>
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>4.0</version>
        </dependency>
    </dependencies>

    <build>
    <defaultGoal>integration-test</defaultGoal>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
            <suiteXmlFiles>
                <suiteXmlFile>TestRun.xml</suiteXmlFile>
            </suiteXmlFiles>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

2 个答案:

答案 0 :(得分:0)

你有没有提到

9007206
你的java测试文件上的

?你在哪里接受测试的浏览器参数?

答案 1 :(得分:0)

问题是如果你运行没有testng的xml文件的类,他的浏览器出了问题。 因此,要使其正常工作,您必须使用

public void method(@Optional("firefox")){}

通过这样做,即使运行没有testng xml文件的方法,也会始终填充参数。