My first program in Android using Appium

I am not able to connect to my app. Not getting what to enter in appPack and appActivity.

Steps :

  1. Started Appium Server and connected node appium
  2. Executed the below script

My device is connected and showing online too. When I executed this code it is not showing any error.

Please let me know where my script is incorrect.

public class testApp {

/**

  • @param args
    */
    public class movein {
    // TODO Auto-generated method stub

    WebDriver dr;
    @Test
    public void testApp() throws MalformedURLException, InterruptedException{

     File app = new File("F:\\Mobile-testing\\apps\abc.apk");
      DesiredCapabilities capabilities = new DesiredCapabilities();
         capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
         capabilities.setCapability("deviceName","Nexus 5");
         capabilities.setCapability("platformVersion", "4.4.4");
         capabilities.setCapability("platformName","Android");
      capabilities.setCapability("app", app.getAbsolutePath());
    
        capabilities.setCapability("appPackage", "com.abc");
        capabilities.setCapability("appActivity", "com.abc");
    
        dr = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        dr.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    
        // clicking
    
         } }}
    

My Appium settings :

Server : 127.0.0.1 Port :4723

Appium Info :
info: [debug] Non-default server args: {“address”:“127.0.0.1”,“logNoColors”:true,“platformName”:“Android”,“platformVersion”:“18”,“automationName”:“Appium”}

Few question on this:

  1. what kind of running container you are using ? Junit or TestNG ?
  2. If you are using TestNG, have you assigned the testing.xml in the project’s properties ?
  3. If you are testing .apk, no need to specify the CapabilityType.BROWSER_NAME. This is just a suggestion, if you do this, it will not cause any error as well.
  4. The appActivity property, i don’t know if yours is correct. In general, the activity should start with “.”
    For example, “.com.abc.XXXX”

The code looks like no problem, please try again and post the error log please.

I am using TestNG and I got appPackage and appActivity from adb logs.

Commented for Browser_Name and runned the script.
Showing error :

org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.

Well, this doesn’t make sense. Please try to do some actions after initialise the driver.

You can get some hints from below sample code:

https://github.com/appium/sample-code/blob/master/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium/AndroidContactsTest.java

please tell me if it is still not work.

Thanks, it works.
But I am getting now this error :

error: Failed to start an Appium session, err was: Error: ‘java -version’ failed. Error: spawn ENOENT
info: Client User-Agent string: Apache-HttpClient/4.4.1 (Java/1.7.0_79)
info: [debug] Didn’t get app but did get Android package, will attempt to launch it on the device
info: [debug] Creating new appium session 008a6e68-5c85-48dd-bc8b-378ed29a73e5
info: Starting android appium
info: [debug] Getting Java version
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: [debug] Error: ‘java -version’ failed. Error: spawn ENOENT
at [object Object]. (D:\Appium\node_modules\appium\lib\devices\android\android-common.js:1057:17)
at exithandler (child_process.js:633:7)
at ChildProcess.errorhandler (child_process.js:649:5)
at ChildProcess.EventEmitter.emit (events.js:95:17)
at Process.ChildProcess._handle.onexit (child_process.js:795:12)
info: [debug] Responding to client with error: {“status”:33,“value”:{“message”:“A new session could not be created. (Original error: ‘java -version’ failed. Error: spawn ENOENT)”,“origValue”:“‘java -version’ failed. Error: spawn ENOENT”},“sessionId”:null}
info: ← POST /wd/hub/session 500 12.433 ms - 208

Create JAVA_HOME and ANDROID_HOME variables. Close and re-open appium app for them to reload paths.

@Telmo_Cardoso That I have already done for JAVA_HOME and ANDROID_HOME. Even I have configure on Path for both, below is the path which I have enter :

%ANDROID_HOME%\tools;%ANDROID_HOME%\platforms;C:\Program Files (x86)\Java\jre7\bin;C:\Program Files (x86)\Java\jdk1.7.0_75\bin;

You have java on jdk1.7.0_75 and appium is receiving version 1.7.0_79

You have several java there. Try to remove the JRE path there.

Look around, there are several people with that problem, so it shouldn’t be hard to solve.

I have removed JRE from the path. Script is running but it is showing me error.
error: Failed to start an Appium session, err was: Error: Permission to start activity denied.
.
.
.

info: [debug] Responding to client with error: {“status”:33,“value”:{“message”:“A new session could not be created. (Original error: Permission to start activity denied.)”,“origValue”:“Permission to start activity denied.”},“sessionId”:null}

How did you install the appium ?

Downloaded from Appium website, this file AppiumForWindows_1_4_13_1.zip and install from the installer.