1
votes

After running my script, I am getting the screen shown here:

enter image description here

When i am trying to actually launch the selenroid app, can anyone please let me know why the app that i have called from the following script is not launching?

testthis.java code(under second package name):

package demolaunchtest;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
public class testthis {
public static AndroidDriver driver;
@BeforeClass
public void setUP() throws MalformedURLException {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("device", "Android");
    capabilities.setCapability("deviceName", "Lokesh Gangaiah");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("platformVersion", "5.0");


    capabilities.setCapability("appPackage", "io.selendroid.testapp");
    capabilities.setCapability("appActivity", "io.selendroid.testapp.HomeScreenActivity");

    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
 @Test
public void Sel_Button_Test() throws InterruptedException {

    System.out.println("Test Started");

    WebElement ButtonElement = driver.findElementById("io.selendroid.testapp:id/buttonStartWebview");
    ButtonElement.click();

    Thread.sleep(3000L);

    System.out.println("Test has been completed");

}


@AfterClass
public void tearDown()
{
    driver.quit();
}

}

MainActivity.java - under first package :

package com.example.demo;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

AndroidMainfest.xml code:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demo"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="21" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Appiumg logs: it does not have any error reported:

info: Welcome to Appium v1.4.16 (REV ae6877eff263066b26328d457bd285c0cc62430d) info: Appium REST http interface listener started on 127.0.0.1:4723 info: [debug] Non-default server args: {"address":"127.0.0.1","logNoColors":true,"deviceName":"Lokesh Gangaiah","platformName":"Android","platformVersion":"21","automationName":"Appium","language":"en","locale":"AU"} info: Console LogLevel: debug

The logs in the eclipse console:

Android Launch! adb is running normally. Performing com.example.myapp1.MainActivity activity launch Uploading myapp1.apk onto device '00bd9781' Installing myapp1.apk... Success! Starting activity com.example.myapp1.MainActivity on device 00bd9781 ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.myapp1/.MainActivity }

1
In your appium gui, did you give any app path??sunder kandasamy
the activity launched is not your expected activity, is it? also the logs from appium are not complete, could you share more of thoseNaman
Check your package name in menifest file , activity name etc.. Both name should match in menifest file and activity class name.AmeeJoshi
@sunderkandasamy No path is specified in the appium guiLokesh
@AmeeJoshi I have two packages under src, Frist: com.example.demo->MainActivity.java and the Second: demolaunchfirst->testthis.java. What i feel is it runs the First MainActivity.java(The default) one always. When i try to Run as->Run Configuration,Under Android Tab the radio button launch does not list the second .java file(activity),so i am unable to select that. Think so if i select the second i should be able to resolve this. Looking forward to any help plsLokesh

1 Answers

0
votes

While providing capabilities to your AppiumDriver(in your case AndroidDriver) the application you want to create the automation test suite for is specified using the following capabilities, mentioned in comments assuming the value you provided are correct :

capabilities.setCapability(MobileCapabilityType.APP, "<path to the application>"); // adding this should help
// Specific to Android application
capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, "<package name of the app>"); // your case 'io.selendroid.testapp'
capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, "<activity name you want to launch on the app to start>"); // your case 'io.selendroid.testapp.HomeScreenActivity'

For further details on the capabilities you shall go through Docs on appium.io for capabilities.

So here is the cause of the problem, you have been using the sample package from selendroid to run your test while expecting your own built apk to show up. You can correct the following -

MobileCapabilityType.APP_PACKAGE : com.example.demo (line 1 from MainActivity.java and line 2 from AndroidManifest.xml)
MobileCapabilityType.APP_ACTIVITY : com.example.demo.MainActivity (from manifest file again <activity android:name=".MainActivity"..../>

and I am expecting as you do that, you would also provide the correct path to your application directory and use the elements from the same package.