简体   繁体   中英

Change .properties values from maven command line TestNG

My project is a maven+TestNG+Selenium based, our requirement is to edit values of properties file present in src/test/resources/collector.properties from maven command line. Note we have multiple properties file and have to edit only below property file

Ex: mvn test -Dtest=ScenarioLogin#Login -Dreport.host=http://10.120.100.70:2023/api/reports/ -Dreport.token=akjfs3425645XXXX

With above command I should be able to update below values

collector.properties:

report.host = http://10.123.123.70:8080/api/

report.token= XXXXXXXX

POM.XML

        <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>${org.apache.maven.plugins.maven-compiler-plugin.version}</version>
                        <configuration>
                            <encoding>UTF-8</encoding>
                            <source>${source.and.target.JVM.version}</source>
                            <target>${source.and.target.JVM.version}</target>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>${org.apache.maven.plugins.maven-surefire-plugin.version}</version>
                        <executions>
                            <execution>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                              
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
        </build>

Please help how to achieve it, what changes required in pom.xml

It looks that you want to override property value through system property. If so your implementation should support/take care while resolving properties. For example, QAF-Testng-extension supports different ways of providing prop .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM