QA's approach 2 Java - Build Tools - Maven

Build Management Tools 

Maven

Its a Build & Dependency management tool

Maven POM is an acronym for Project Object Model.
The pom.xml file contains information of project and configuration information for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin, goals etc.
Maven reads the pom.xml file, then executes the goal.

POM.xml

This file will contain all the instruction which we wanted to do
Maven reads instructions from POM.xml file 
1. Verifies the resources
2. Compiles the tests
3. Package the test to jar file

========================================================================
<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>com.automation.maven</groupId>
<artifactId>com.automation.maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Create Maven build</name>
<description>Create Maven build</description>

<!-- Change from here -->
<packaging>jar</packaging>


<!--properties are like variables holding the path, in here suiteXmlFile holds the location of testng.xml file path-->

<!-- should be declared before the Build tag-->

<!--Integrating TestNG with Maven:-->

<properties>
<suiteXmlFile>src/main/resources/testng.xml</suiteXmlFile>
</properties>

<!-- Define external Dependencies to be downloaded from external to maven repository as follows-->

<repositories>

     <repository> 
             <id>JBoss repository</id>
                     <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url> 
     </repository> 

</repositories>

<!-- Define Dependencies to be dowloaded from Maven central repository-->

<dependencies>
<!-- Adding testng dependency -->

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.1.1</version>
</dependency>

<!-- Adding Selenium dependency -->

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.47.1</version>
</dependency>

</dependencies>

<build>
<plugins>

<!-- Adding maven compiler plugin, Compiles Java sources -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>

<!-- maven-surefire-plugin, Run the TestNG unit tests in an isolated classloader.-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>

<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>

</plugins>
</build>
</project>
========================================================================
mvn clean install test
clean target will clear all the dependencies
install target will install all the dependencies
test target will start executing the test
========================================================================

How do we get the Maven dependencies


Assume we require TestNG dependencies for Maven, Google it like "TestNG Maven dependencies, the Launching page, we will be able to see a list of links available
TestNG - Maven
testng.org/doc/maven.htmlclick on the link, we will see the below

<dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>6.8</version>
  <scope>test</scope>
</dependency

How to create a Simple Maven project

Launch eclipse ->File->New->Project->Select Maven->Maven project->Create

a Simple Project->The below page will be launched



Now how do we choose a proper Group ID, Artifact ID ->

The general convention followed is as follows:

Group ID should be -> com.Organizationname.ClientName
Artifact ID should be -> GroupId.ProductNam, hence it will be
com.Organizationname.ClientName.ProductName

This will be the Root folder Name of the Project & the project will be packaged with this name.

Click here to Working with Version Control

Comments

Popular posts from this blog

QA's approach 2 Java - Understanding Static context

Selenium 4 absolute beginners - How to create Batch execution file

Technologies - Log4J - Create Log4j Configuration File - Where ? How ? What ?