03 Aug 2016

About Maven- It’s Usage and setup in Automation

12:55 PM MongoDB 0 Comment

                        Before starting about Maven.. Want to share this with all..when i was in the initial stage of learning Automation, i always had a question?..How does the real time Automation framework looks like and what steps should i follow? This is a common question for each of us who starts learning QA Automation..

while learning and doing practice i usually use to do.. Create a java project from the IDE (Eclipse) and writing a test in selenium and execute it from the IDE..
After working for a client i came up knowing how it’s actually looks like..

Here I am going to show you from scratch how to Make a Automation project using Maven

About Maven – Description

  • Maven – a build tool which is distributed under Apache Software Foundation. It is mainly used for java projects. It makes build consistent with other project.
  • Maven downloades all project Library jars which ever are mentioned in pom.xml
  • Maven is used to manage the dependencies. For example if you are using selenium version 2.46 and any later point of time you have to use some other version, then same can be managed easily by Maven i.e just by giving the latest version
  • Maven provides pom.xml which is the core to any project. This is the configuration file where all required information’s are kept
  • Downloaded libraries are stored in local repository called m2. Maven uses the libraries available in m2 folder and if any new dependency added then maven downloads from central repository to local repository

Build Life Cycle:

Basic maven phases are used as below.

clean: deletes all artifacts and targets which are created already.
compile: used to compile the source code of the project.
test: test

the compiled code and these tests do not require to be packaged or deployed.
package: package is used to convert your project into a jar or war etc.
install: install the package into local repository for use of other project.

Maven Setup:

Step 1: To setup Maven, download the maven’s latest version form Apache depending upon  different OS.
Step 2: Unzip the folder and save it on the local disk.
Step 3: Create environment variable for MAVEN_HOME. Follow the below step:

Navigate to System Properties ->Advanced System Setting->Environment Variable ->System Variable ->New ->Add path of Maven folder

pic1

pic2

Step 4: Edit path variable and provide the bin folder path.

pic3

Step 5: Now verify the maven installation using command prompt and don’t forget to setup JAVA_HOME

Use mvn –version to verify maven version and output comes like below.

pic4

After successful installation of Maven and configuring it’s path..  Now we have to Install Eclipse

Download and install Eclipse
Url to Download : https://eclipse.org/downloads/packages/release/Helios/SR1
Eg : eclipse-jee-helios-SR1-win32-x86_64

After successful installation.. Open the eclipse and add maven plugin into eclipse

  • In Eclipse: Help -> Install New Software…
  • Type the following URL in field Work with: http://m2eclipse.sonatype.org/sites/m2e
  • Click Add…
  • Give a name for the repository, such as: m2eclipse
  • Click OK
  • Select the checkbox Maven Integration for Eclipse
  • Click Next etc. to move forward and choose to restart Eclipse when prompted.Now Maven is all set in your local and as well integrated with Eclipse

    Create Maven project:
    Step 1:
    Navigate to File-> new->others->Maven->Maven Project->Click Next


    pic5


    Step 2:
    Check Use Default workspace Location and click Nextpic6

    Step 3:
    Provide Group Id and Artifact Id .You can change the version of Jar as per your wish. Then  Click Finish.

    pic7

    step 4:
    After finish you will find the project structure is created like below.
    pom.xml is created which is used to download all dependencies.

    pic8

    pom.xml file looks like below:

    pic9

    Step 5:  Add dependencies for Selenium.
    Step 6:  Final pom.xml will be like below:

    pic10
    Step 7:  Maven will download all the dependency jars in to local repository called .m2.

    Build the Project:

  • Project can be built by both using IDE and command prompt.
    Using IDE you have to right click on POM-Run As-Maven Build
  • Enter goals like clean install etc. and click Run.
    Same can be done using command prompt. Navigate to project folder where pom.xml lies.
    And use below commands to clean, compile and installFor clean: mvn clean
    For compile: mvn compile
    For Install: mvn install

Leave a Reply