Не удается выполнить тест maven из командной строки, используя теги? - PullRequest
0 голосов
/ 29 января 2019

Когда я запускаю следующие команды:

mvn test -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 голосов
/ 29 января 2019

В соответствии с https://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html, существует 2 способа передачи «системных свойств» для безошибочного выполнения (mvn test):

  1. через configuration/systemPropertyVariables
  2. ...или устаревший элемент configuration/systemProperties.

Вы не использовали ни одного из них.

Обратите также внимание, что таким способом можно передавать только свойства со строковым типом.... и:

Некоторые системные свойства должны быть установлены в командной строке разветвленной виртуальной машины и не могут быть установлены после запуска виртуальной машины.Эти свойства должны быть добавлены к параметру argLine плагина Surefire.Например, <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>
...