无法使用标签从命令行执行Maven测试?

时间:2019-01-28 21:18:32

标签: java maven selenium-webdriver junit cucumber

当我运行以下命令时:

  

MVN测试-Dcucumber.options =“-tags @UserAuthentication”

然后出现以下错误:

Unknown lifecycle phase 
".options=src/test/java/Feature --tags @@UserAuthentication". 
You must specify a valid lifecycle phase or a goal in the format 
<plugin-prefix>:<goal> or 
<plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>

我的POM文件如下:

  

http://maven.apache.org/xsd/maven-4.0.0.xsd“>             4.0.0             com.test.org             测试             0.0.1-SNAPSHOT

      <properties>
          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
          <maven.compiler.source>1.8</maven.compiler.source>
          <maven.compiler.target>1.8</maven.compiler.target>
        </properties>

      <build>
          <pluginManagement>
            <plugins>
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M3</version>
              </plugin>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <version>3.8.0</version>
              </plugin>
            </plugins>
          </pluginManagement>
       </build>

      <dependencies>
          <dependency>
              <groupId>org.seleniumhq.selenium</groupId>
              <artifactId>selenium-java</artifactId>
              <version>3.7.1</version>
          </dependency>
          <dependency>
              <groupId>junit</groupId>
              <artifactId>junit</artifactId>
              <version>4.12</version>
              <scope>test</scope>
          </dependency>
          <dependency>
              <groupId>info.cukes</groupId>
              <artifactId>cucumber-java</artifactId>
              <version>1.2.5</version>
          </dependency>
          <dependency>
              <groupId>info.cukes</groupId>
              <artifactId>cucumber-jvm-deps</artifactId>
              <version>1.0.5</version>
              <scope>provided</scope>
          </dependency>
          <dependency>
              <groupId>info.cukes</groupId>
              <artifactId>cucumber-junit</artifactId>
              <version>1.2.5</version>
              <scope>test</scope>
          </dependency>
          <dependency>
              <groupId>com.vimalselvam</groupId>
              <artifactId>cucumber-extentsreport</artifactId>
              <version>3.0.2</version>
          </dependency>
          <dependency>
              <groupId>com.aventstack</groupId>
              <artifactId>extentreports</artifactId>
              <version>3.1.2</version>
          </dependency>       
      </dependencies>  </project>

我的跑步者类如下:

  @RunWith(Cucumber.class)
    @CucumberOptions(
            features ="src/test/java/Feature",
            glue= "stepDefinitions",
            tags= {"@Pagination,@UserAuthentication"},
            plugin = { "com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html"}, 
            monochrome = true)

    public class RunnerTest {
        @AfterClass
        public static void writeExtentReport() {
            Reporter.loadXMLConfig(new File("config/report.xml"));
        }
    }

我不知道要使用标记从命令行运行测试的目标是什么。

1 个答案:

答案 0 :(得分:0)

根据https://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html,有两种方法可以将“系统属性”传递给surefire(MVN测试)执行:

  1. 通过configuration/systemPropertyVariables
  2. ...或已弃用的configuration/systemProperties元素。

您没有使用任何这些。

请注意,只能以这种方式传递“字符串类型”属性。 ...并且:

  

某些系统属性必须在分支的VM的命令行上设置,并且在VM启动后不能设置。这些属性必须添加到Surefire插件的argLine参数中。例如<argLine>-Djava.endorsed.dirs=...</argLine>

因此,在您的情况下,最安全的方法(假设是分叉执行)是

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M3</version>
    <configuration>
        <argLine>-Dcucumber.options="--tags @UserAuthentication"</argLine>
    </configuration>
</plugin>

...也可能:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M3</version>
    <configuration>
        <systemPropertyVariables>
            <cucumber.options>--tags @UserAuthentication</cucumber.options>
        </systemPropertyVariables>
    </configuration>
</plugin>