【问题标题】:how to pass testng.xml parameter value through mvn command line如何通过 mvn 命令行传递 testng.xml 参数值
【发布时间】:2017-09-11 23:58:34
【问题描述】:

testng.xml 文件下面有三个参数。我不希望参数customerCode 被硬编码。我想将不同/不同的customerCode 传递给以下testng.xml 文件,但我也想将Peter 作为默认customerCode,以防万一我不通过mvn 命令行提供一个,如下所示:

mvn test -DcustomerCode=customer1 -Ptestng.xml

下面是testng.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TestSuite" parallel="false">

    <test name="someTest">
        <parameter name="browserType" value="chrome_win"></parameter>
        <parameter name="Url" value="http://regression.mytest.com/?customerCode=" />
        <parameter name="customerCode" value="Peter"/>

        <groups>
            <run>
                <exclude name="navigateToHomePage" />
            </run>
        </groups>
        <classes>
            <class name="com.automation.customermanagement.createTest.myIntegrationTest" >
            <methods>
                <exclude name="deleteCustomer" />
            </methods>
            </class>
        </classes>
    </test>
</suite>

我如何做到这一点?有没有办法做到这一点?

以下是我的 POM 文件。我应该将customerCode 属性放在配置文件中的什么位置?

<profile>
    <id>AddMgmtTest</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>admgmttestng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
    </build>
</profile>

【问题讨论】:

    标签: java xml maven selenium-webdriver


    【解决方案1】:

    这是我实施的解决方案,它运行良好!

    1) 将以下属性添加到POM.xml 文件

                        <systemProperties>
                            <property>
                                <name>customerCode</name>
                                <value>Subaru</value>
                            </property>
                        </systemProperties>
    

    2) 将此行添加到测试方法中

    String customerCode= System.getProperty("customerCode"); 
    

    3) 上面的行拉取下面 mvn 命令行中提供的customerCode=customer1

    mvn test -DcustomerCode=customer1 -Ptestng.xml

    如果您不在命令行中提供customerCode,它将采用POM.xml 文件中上述属性中提供的默认值Subaru

    【讨论】:

    • 注意 systemProperties 语法已弃用,doc
    猜你喜欢
    • 2012-11-28
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多