Hi All,
I am very new to Appium trying to run Junit Test script on Android emulator using eclipse IDE.
below is my code : Please help me where I am going wrong
package appiumSeminarSession1;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import java.io.File;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class wordpressTest {
public AppiumDriver driver;
@Before
public void setUp() throws Exception {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot,"/app");
File app = new File(appDir,"WorkPress.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("browserName", "");
capabilities.setCapability("deviceName", "emulator-5554");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "org.wordpress.android");
capabilities.setCapability("appActivity", ".Dashboard");
capabilities.setCapability("appWaitActivity", ".Dashboard");
//create a RemoteWebDriver, the default port for Appium is 4723
//driver = new AppiumDriver( new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
//driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities.android());
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities) {
public MobileElement scrollToExact(String arg0) {
// TODO Auto-generated method stub
return null;
}
public MobileElement scrollTo(String arg0) {
// TODO Auto-generated method stub
return null;
}
};
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}
@Test
public void TestUI(){
driver.findElement(By.className(“android.widget.Button”)).click();
}
}
POM File -
4.0.0 Mindfire appiumSeminarSession1 0.0.1-SNAPSHOT io.appium java-client 1.5.0and Jar which I am using are
java-client-1.5.0
junit-4.11
gson-2.2.4
selenium-java-2.42.2
selenium-server-standalone-2.42.2
Error which I am getting is:
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Bad app: C:\JavaPractice\appiumSeminarSession1\app\WorkPress.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat ‘C:\JavaPractice\appiumSeminarSession1\app\WorkPress.apk’) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 105 milliseconds
Build info: version: ‘2.42.2’, revision: ‘6a6995d’, time: ‘2014-06-03 17:42:03’
System info: host: ‘MININT-9RPP4EL’, ip: ‘192.168.1.69’, os.name: ‘Windows 8.1’, os.arch: ‘amd64’, os.version: ‘6.3’, java.version: ‘1.8.0_11’
Driver info: appiumSeminarSession1.wordpressTest$1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:88)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:153)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:44)
at appiumSeminarSession1.wordpressTest$1.(wordpressTest.java:38)
at appiumSeminarSession1.wordpressTest.setUp(wordpressTest.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)