Unable to run appium maven project from as maven test


#1

Hi,
I am trying to run an appium script as a maven project with TestNG using Java. When I run it as a Java application/TestNG Test, it is working fine but when I run it as ‘maven test’ from pom.xml, script is not running and no logs in appium server also.

Here is my eclipse logs:

[INFO] Scanning for projects…
[INFO]
[INFO] ------------------------< GCR:FrameworkGCReddy >------------------------
[INFO] Building FrameworkGCReddy 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for org.apache.maven.doxia:doxia-sink-api:jar:1.0-alpha-10 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO]
[INFO] — maven-resources-plugin:2.6:resources (default-resources) @ FrameworkGCReddy —
[INFO] Using ‘UTF-8’ encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] — maven-compiler-plugin:3.1:compile (default-compile) @ FrameworkGCReddy —
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] — maven-resources-plugin:2.6:testResources (default-testResources) @ FrameworkGCReddy —
[INFO] Using ‘UTF-8’ encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] — maven-compiler-plugin:3.1:testCompile (default-testCompile) @ FrameworkGCReddy —
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to D:\Users\kdabbara\Desktop\Kamesh\Testing\workspace\FrameworkGCReddy\FrameworkGCReddy\target\test-classes
[INFO]
[INFO] — maven-surefire-plugin:2.12.4:test (default-test) @ FrameworkGCReddy —
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.350 s
[INFO] Finished at: 2018-08-08T16:51:22+05:30
[INFO] ------------------------------------------------------------------------

POM.XML

4.0.0

<groupId>GCR</groupId>
<artifactId>FrameworkGCReddy</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>FrameworkGCReddy</name>
<url>http://maven.apache.org</url>

<properties>
	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	<appium.version>3.3.0</appium.version>
	<testng.version>6.9.10</testng.version>
</properties>

<dependencies>

	<!-- https://mvnrepository.com/artifact/org.testng/testng -->
	<dependency>
		<groupId>org.testng</groupId>
		<artifactId>testng</artifactId>
		<version>6.13.1</version>
		<scope>test</scope>
	</dependency>

	<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
	<dependency>
		<groupId>org.seleniumhq.selenium</groupId>
		<artifactId>selenium-server</artifactId>
		<version>3.11.0</version>
	</dependency>

	<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
	<dependency>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-surefire-plugin</artifactId>
		<version>2.20</version>
	</dependency>

	<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
	<dependency>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-compiler-plugin</artifactId>
		<version>3.6.0</version>
	</dependency>

	<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
	<dependency>
		<groupId>io.appium</groupId>
		<artifactId>java-client</artifactId>
		<version>6.0.0-BETA1</version>
	</dependency>

	<dependency>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-failsafe-plugin</artifactId>
		<version>2.12</version>
	</dependency>

</dependencies>

Appium script:
package TestScripts;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;

public class SnapItSample
{
public static DesiredCapabilities cap;
public static AndroidDriver driver;
public static WebDriverWait wait;

	@BeforeTest
	public void before() throws MalformedURLException {
		System.out.println("Hello");
		
		cap = new DesiredCapabilities();
		cap.setCapability(MobileCapabilityType.DEVICE_NAME, "VIBE K5 Note");
		//cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Nexus5X");
		cap.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");	
		cap.setCapability(MobileCapabilityType.PLATFORM_VERSION,"6.0");
		//cap.setCapability(MobileCapabilityType.APP,fs.getAbsolutePath());
		
		cap.setCapability("appPackage","com.orgname.AusPost");
		cap.setCapability("appActivity", "com.orgname.AusPost.SnapIt");
		cap.setCapability(MobileCapabilityType.NO_RESET, true);
		cap.setCapability(MobileCapabilityType.FULL_RESET, false);
			
		driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"),cap);
		
	}
	@Test
	public void snapItTest() throws MalformedURLException, InterruptedException
	{
	// TODO Auto-generated method stub
				

	
		AndroidElement custEnq = driver.findElement(By.xpath("//android.widget.TextView[@text='Customer enquiry']"));
		WebDriverWait wait = new WebDriverWait(driver,5);
		wait.until(ExpectedConditions.elementToBeClickable(custEnq));      
		Thread.sleep(3000);
		custEnq.click();
	}
	@AfterTest
	  public void afterClass() {
		  	driver.quit();
	  }

}