2017-01-22 3 views
1

У меня есть проект Maven TestNG, и я пытаюсь передать пару аргументов командной строки в файл testng.xml.Проект Maven TestNG, передайте аргументы командной строки в файл testng.xml

Файл testng.xml выглядит, как показано ниже:

<suite name="Test Suite" parallel="classes" thread-count="100" > 
    <test name="VIP Tests"> 
    <parameter name="browser" value="${browser}" /> 
    <groups> 
     <run> 
      <include name="${test.scope}" /> 
     </run> 
    </groups> 
    <packages> 
     <package name="com.tests.*" /> 
    </packages> 
    </test> 
</suite> 

Файл pom.xml выглядит, как показано ниже:

<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>Test_Project</groupId> 
<artifactId>TP_X</artifactId> 
<version>1.0-SNAPSHOT</version> 
    <build> 
    <resources> 
     <resource> 
      <directory>src/test/resources</directory> 
     </resource> 
    </resources> 
    <sourceDirectory>${src.dir}</sourceDirectory> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.19.1</version> 
      <configuration> 
       <suiteXmlFiles> 
        <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile> 
       </suiteXmlFiles> 
      </configuration> 
     </plugin> 
    </plugins> 
    </build> 
</project> 

Теперь, каждый раз, когда я пытаюсь выполнить тестовую команду Maven

mvn clean test -U -Dtest.scope=smoke -Dbrowser=chrome 

В командной строке появляется следующая ошибка:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project VIP_QE: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test failed: There was an error in the forked process 
[ERROR] java.util.regex.PatternSyntaxException: 
[ERROR] Illegal repetition near index 0 
[ERROR] ${test.scope} 

Может кому-то помочь? Я застрял в этой проблеме около недели.

+0

Команда Maven, что я использую «МВН чистый тест -U -Dtest.scope = дым -Dbrowser = хром». Извините за отсутствие параметра браузера. – jsmith

+0

@nullpointer Спасибо. – jsmith

ответ

2

TestNG и верный огонь не поддерживают обозначение ${var}.

Но вы можете использовать the filtering feature of Maven. Тогда вам придется выбрать модифицированную ресурс:

<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>Test_Project</groupId> 
<artifactId>TP_X</artifactId> 
<version>1.0-SNAPSHOT</version> 
    <build> 
    <testResources> 
     <testResource> 
      <directory>src/test/resources</directory> 
      <filtering>true</filtering> 
     </testResource> 
    </testResources> 
    <sourceDirectory>${src.dir}</sourceDirectory> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.19.1</version> 
      <configuration> 
       <suiteXmlFiles> 
        <suiteXmlFile>target/test-classes/testng.xml</suiteXmlFile> 
       </suiteXmlFiles> 
      </configuration> 
     </plugin> 
    </plugins> 
    </build> 
</project> 

Обратите внимание на разницу между testResources и resources: How do I filter test resources in maven?

+0

Это сработало. Спасибо. – jsmith

Смежные вопросы