Maven Build Profiles Example
Access the URL to learn Maven Basics: http://total-qa.com/advanced-selenium/maven/
Maven is a Build Automation Tool helps in packaging different build types as Jar,War,EAR.
EAR -> Enterprise Archive
JAR -> JAVA Archive
WAR-> Web Archive
Refer to the link for more details: https://stackoverflow.com/questions/1594667/war-vs-ear-file
Sometimes, its require to run the Selenium WebDriver Automation tests against the Multiple Environments as DEV and QA. Maven has a provision of profiles which helps to run the test with multiple environments.
Configure the pom.xml with different profiles as mentioned below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
<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>org.totalqa.pages</groupId> <artifactId>maven_profiles</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>mavenprofiles</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <profiles> <profile> <id>QA</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <configuration> <forkCount>0</forkCount> <suiteXmlFiles> <suiteXmlFile>QA.xml</suiteXmlFile> </suiteXmlFiles> </configuration> </plugin> </plugins> </build> </profile> <profile> <id>DEV</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <configuration> <forkCount>0</forkCount> <suiteXmlFiles> <suiteXmlFile>DEV.xml</suiteXmlFile> </suiteXmlFiles> </configuration> </plugin> </plugins> </build> </profile> </profiles> <dependencies> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.8</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.7.1</version> </dependency> </dependencies> </project> |
Running the Maven Project using Profile Names:
Right-click on the project select Run as->Run Configurations
Provide the maven goals and profile Names:
Executing the Maven Project with maven goals and profile Names from command line:
- Download the Apache Maven Software from the link https://maven.apache.org/download.cgi accordingly as per the Operating System.
- Unzip the file and set the Class-path for the Apache Maven.
- Run the Maven Project from the command line with goals and profile name
1 2 3 |
mvn clean test -P profilename Ex: mvn clean test -P QA |