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
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;
Click Next and select the checkbox for skipping the archetype selection based on the below screenshot;
Click Next and Enter the Group Id, Artifact Id, Name and description based on the below screenshot;
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;
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″ 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>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″
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd”>
<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.
Go to the Run configuration and enter the name package in the Goals based on the below screenshot;
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;
You could see the build success message if everything is perfectly mapped in the POM.XML file;
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;
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,.
my build is failing my i tried to run using maven build?please help me.
LikeLike
Please share me the exception to diagnose the same.
LikeLike
If a test is failing, how to create build?
LikeLike
http://stackoverflow.com/questions/4174696/making-maven-run-all-tests-even-when-some-fail
LikeLike