1

I have created an automation framework where I am reading values from a property file say "config.properties".

My config.propertioes file contains following :

BrowserName=${browser}
Environment=${env}

I am reading browser value from the property file and passing it to my selenium script to run it.

Now I wants to replace "${browser}" && "${env}" with value "ie" && "IT" using pom.xml. Is there any way/plugin using which I can edit a property file using pom.xml.

Please suggest.

@Keshava I am putting whole example below as suggested below : 1.Have 2 property files: ◦project.properties: This is the file that we commit in the repository. It consists data as follows: ◾project.connection.username=@@DB_USERNAME@@ project.connection.password=@@DB_PASSWORD@@

◦build.properties: This is the file that we do not commit in the repository and is maintained at each of the deployment environments, be it the developers env., UAT env or Production env. The contents of this file are as follows: ◾db.username=mydbuser db.password=mydbpassword

2.In the project’s pom.xml add the following plugin and a execution:

<plugin>
                <groupId>com.google.code.maven-replacer-plugin</groupId>
                <artifactId>maven-replacer-plugin</artifactId>
                <version>1.3.5</version>
                <executions>
                    <execution>
                        <id>replaceTokens</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>replace</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <file>target/classes/project.properties</file>
                    <replacements>
                        <replacement>
                            <token>@@DB_USERNAME@@</token>
                            <value>${db.username}</value>
                        </replacement>
                        <replacement>
                            <token>@@DB_PASSWORD@@</token>
                            <value>${db.password}</value>
                        </replacement>
                    </replacements>
                </configuration>
</plugin>

from above, I understand that "@@DB_USERNAME@@" is from "project.properties". But, from which properties file this "${db.username}" value will be taken?. how my pom will understand from where to take "${db.username}" .

Do I need to pass this value in maven goal like below :

mvn clean install -Ddb.username=myuserid
montu
  • 13
  • 1
  • 4
  • https://stackoverflow.com/questions/11740618/is-there-a-way-to-use-maven-property-in-java-class-during-compilation – Ashish Mathew Jan 15 '18 at 09:23
  • Possible duplicate of [Is there a way to use maven property in Java class during compilation](https://stackoverflow.com/questions/11740618/is-there-a-way-to-use-maven-property-in-java-class-during-compilation) – L. Guthardt Jan 15 '18 at 09:32

2 Answers2

4

Hello you can use the maven resource plugin.

This plugin implement "Maven Filtering".

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.0.2</version>
        <executions>
          <execution>
            <id>selenium-profile-chrome</id>
            <!-- here the phase you need -->
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/selenium</outputDirectory>
              <resources>          
                <resource>
                  <directory>src/non-packaged-resources</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>              
            </configuration>            
          </execution>
        </executions>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>
1

you could tryin using the maven replacer plugin See https://code.google.com/archive/p/maven-replacer-plugin/

See an example here

Keshava
  • 702
  • 1
  • 7
  • 20