How to Integrate Apache Maven with Appium, Java and JUnit in Eclipse IDE?

You have already seen the section of “How to automate Android mobile application using Appium?” and now the below information is going to help you in the Apache Maven integration with Appium + Java + JUnit in Eclipse IDE.

What is Apache Maven?

Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information.

Right from the beginning, we are using Eclipse IDE to automate the mobile application using Appium & Selenium libraries. This time, we have to install the Maven plug-in in Eclipse IDE using the below market place URL;

http://download.eclipse.org/technology/m2e/releases

Maven in Eclipse

Once the Maven plug-in installed in the Eclipse IDE and now you have to create a new Maven Project in Eclipse IDE based on the below screenshot;

New Project

Click Next and select the checkbox for skipping the archetype selection based on the below screenshot;

New Project 2

Click Next and Enter the Group Id, Artifact Id, Name and description based on the below screenshot;

New Project 3

Click Finish.

Now create a new class in the name AppiumTest(user defined) and package in the name of appiumDemo(user defined) file under the AppiumTest – src/main/java based on the below screenshot;

New Class

Now use the same source code available in the below link by copy and paste it in the AppiumTest.java created by you;

https://gopekannan.wordpress.com/2015/08/26/how-to-automate-android-mobile-application-using-appium/

Now open the POM.XML file available in the explorer window and copy & paste the below data(Taken from the Maven Repository http://search.maven.org/#search%7Cga%7C1%7Cselenium);

<project xmlns=”http://maven.apache.org/POM/4.0.0&#8243; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”&gt;
<modelVersion>4.0.0</modelVersion>
<groupId>AppiumTest</groupId>
<artifactId>AppiumTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>AppiumMaven</name>
<description>Appium and Java Integrated with Maven</description>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.46.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>src/main/java/appiumDemo</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>zip-with-dependencies</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/zip.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Create a folder assembly under the main folder and create a file zip.xml then copy & paste the below data in that xml file;

<assembly
xmlns=”http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0&#8243;
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
xsi:schemaLocation=”http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd”&gt;
<id>zip</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>./</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>./</outputDirectory>
<includes>
<include>/dependency-jars/</include>
</includes>
</fileSet>
</fileSets>
</assembly>

You can ask, what is the purpose of zip.xml because POM.XML only helps to integrate the supporting jars from central repository and make the code to run.

zip.xml will generate a zip file which comprised of source code information and its supporting jar information. This zip file can be used to utilize our automation test script in the cloud based testing tool such as Amazon Device Farm, which will be explained in another thread.

Ensure the JDK environment based on the below screenshot; I am using Eclipse Mars with JDK 1.8.

JDK Environment

Go to the Run configuration and enter the name package in the Goals based on the below screenshot;

Run Configurations

Now everything is ready at your end, go to the POM.XML and Right click the mouse button. Select the Run as option and select the Maven Clean option based in the below screenshot;

Run as Maven Clean

You could see the build success message if everything is perfectly mapped in the POM.XML file;

Maven Clean Success

As already discussed in the Appium setup section, make the Appium server UP including the Android Emulator installed with testing mobile application;

Now select the Maven build option based on the below screenshot to make your test script run under the maven project;

Run as Maven build

Once the test script executed in the Android Emulator via Appium server, all the required jar files will be fetched from the Maven central repository and the build success message will be displayed in the Eclipse console window including the test run details of failures, errors, skipped etc,.

Maven Build Success

 

4 thoughts on “How to Integrate Apache Maven with Appium, Java and JUnit in Eclipse IDE?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s