sangmingming / robotium

Automatically exported from code.google.com/p/robotium
0 stars 0 forks source link

Android Phone.apk test with Robotium #83

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,
I am newbie in Java programming and Android-testing. i will like to test the 
android Phone.apk application with robotium-solo-2.2.jar.   
I follow all the steps on this links successfully: 
http://code.google.com/p/robotium/wiki/RobotiumForPreInstalledApps.

my test application:

package com.android.contacts.phoneTesting;
import android.app.Activity;
import com.jayway.android.robotium.solo.Solo;

import android.test.ActivityInstrumentationTestCase2;

@SuppressWarnings("unchecked")
public class PhonecallTest extends ActivityInstrumentationTestCase2{

private static final String TARGET_PACKAGE_ID = "com.android.contacts";

    private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = 
        "com.android.contacts.DialtactsActivity";

    private static Class<?> launcherActivityClass;

    static {

        try {

            launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);

        } catch (ClassNotFoundException e) {

            throw new RuntimeException(e);

        }

    }

        @SuppressWarnings("unchecked")  

    public PhonecallTest() throws ClassNotFoundException {

        super(TARGET_PACKAGE_ID, launcherActivityClass);

    }

    private Solo solo;
    private Activity activity;

    @Override
    protected void setUp() throws Exception {

               setUp();
        activity = getActivity();
        solo = new Solo(getInstrumentation(), activity);
    }

    public void testDial()throws Exception  {
        solo.enterText(0, "5");
        solo.enterText(1, "3");
        solo.enterText(3, "7");
        solo.enterText(4, "3");
        solo.enterText(5, "9");
        solo.enterText(6, "1");
        solo.clickOnButton("Dial");
        assertTrue(solo.searchEditText("537391"));
        }

    @Override
    public void tearDown() throws Exception {

        try {

            solo.finalize();

        } catch (Throwable e) {

            e.printStackTrace();

        }

        activity.finish();

        super.tearDown();

    }

}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.android.contacts.phoneTesting"
      android:versionCode="1"
      android:versionName="1.0"
      android:sharedUserId="android.uid.phone" >

    <uses-sdk android:minSdkVersion="7" />
    <instrumentation android:targetPackage="com.android.contacts" android:name="android.test.InstrumentationTestRunner" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">

    <uses-library android:name="android.test.runner" />
    </application>
</manifest>

What is the expected output? What do you see instead?

chinco@chinco-desktop:~/android/dev$ adb shell am instrument -w 
com.android.contacts.phoneTesting/android.test.InstrumentationTestRunner

INSTRUMENTATION_RESULT: shortMsg=Process crashed.
INSTRUMENTATION_CODE: 0

adb logs

W/dalvikvm(12449): Exception Ljava/lang/RuntimeException; thrown during 
Lcom/android/contacts/phoneTesting/PhonecallTest;.<clinit>
E/dalvikvm(12449): Class lookup Ljava/lang/Object; attemped while exception 
Ljava/lang/ExceptionInInitializerError; pending
I/dalvikvm(12449): DALVIK THREADS:
I/dalvikvm(12449): "main" prio=5 tid=3 RUNNABLE
I/dalvikvm(12449):   | group="main" sCount=0 dsCount=0 s=N obj=0x4001b2d0 
self=0xbd40
I/dalvikvm(12449):   | sysTid=12449 nice=0 sched=0/0 cgrp=unknown 
handle=-1343997288
I/dalvikvm(12449):   at java.lang.Class.getDeclaredConstructors(Native Method)
I/dalvikvm(12449):   at java.lang.Class.getConstructors(Class.java:509)
I/dalvikvm(12449):   at 
android.test.suitebuilder.TestGrouping$TestCasePredicate.hasValidConstructor(Tes
tGrouping.java:226)
I/dalvikvm(12449):   at 
android.test.suitebuilder.TestGrouping$TestCasePredicate.apply(TestGrouping.java
:215)
I/dalvikvm(12449):   at 
android.test.suitebuilder.TestGrouping$TestCasePredicate.apply(TestGrouping.java
:211)
I/dalvikvm(12449):   at 
android.test.suitebuilder.TestGrouping.select(TestGrouping.java:170)
I/dalvikvm(12449):   at 
android.test.suitebuilder.TestGrouping.selectTestClasses(TestGrouping.java:160)
I/dalvikvm(12449):   at 
android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.jav
a:154)
I/dalvikvm(12449):   at 
android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:11
5)
I/dalvikvm(12449):   at 
android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java
:103)
I/dalvikvm(12449):   at 
android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:3
23)
I/dalvikvm(12449):   at 
android.app.ActivityThread.handleBindApplication(ActivityThread.java:3982)
I/dalvikvm(12449):   at 
android.app.ActivityThread.access$2900(ActivityThread.java:119)
I/dalvikvm(12449):   at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1901)
I/dalvikvm(12449):   at android.os.Handler.dispatchMessage(Handler.java:99)
I/dalvikvm(12449):   at android.os.Looper.loop(Looper.java:123)
I/dalvikvm(12449):   at 
android.app.ActivityThread.main(ActivityThread.java:4363)
I/dalvikvm(12449):   at java.lang.reflect.Method.invokeNative(Native Method)
I/dalvikvm(12449):   at java.lang.reflect.Method.invoke(Method.java:521)
I/dalvikvm(12449):   at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
I/dalvikvm(12449):   at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
I/dalvikvm(12449):   at dalvik.system.NativeStart.main(Native Method)

I just wanted the test  to start the Phone  application and dial some number.
please can you help me out of this problem ?

what is wrong on my implementation? 

thank You 
Chindji

Original issue reported on code.google.com by feu...@gmail.com on 9 Mar 2011 at 11:00

GoogleCodeExporter commented 9 years ago
Have you installed the test project on device before trying to run the test 
suite?

Original comment by renasr...@gmail.com on 9 Mar 2011 at 11:33

GoogleCodeExporter commented 9 years ago
yes I install it on /data/app 

Original comment by feu...@gmail.com on 9 Mar 2011 at 12:30

GoogleCodeExporter commented 9 years ago
I am not sure what the problem is. Have you tried to run the test project from 
development tools instead?

http://www.youtube.com/watch?v=v1z39IIA7kY

Original comment by renasr...@gmail.com on 9 Mar 2011 at 1:13

GoogleCodeExporter commented 9 years ago
yes I run the test project from development tools. but it was not working. i 
have the same error.
 adb log.

I/ActivityManager(  805): Start proc com.android.contacts for restart 
com.android.contacts: pid=1418 uid=1001 gids={1015}
W/ActivityManager(  805): Crash of app com.android.contacts running 
instrumentation 
ComponentInfo{com.android.contacts.phoneTesting/android.test.InstrumentationTest
Runner}
I/instrumentation(  981): INSTRUMENTATION_RESULT: shortMsg=Process crashed.
I/instrumentation(  981): INSTRUMENTATION_CODE: 0
D/ActivityManager(  805): Uninstalling process com.android.contacts
D/ActivityManager(  805): Force removing process ProcessRecord{439ac520 
1418:com.android.contacts/1001} (com.android.contacts/1001)
I/Process (  805): Sending signal. PID: 1418 SIG: 9
D/Zygote  (  761): Process 1412 terminated by signal (11)
I/ActivityManager(  805): Start proc com.android.contacts for added application 
com.android.contacts: pid=1419 uid=1001 gids={1015}
D/ddm-heap( 1419): Got feature list request

Original comment by feu...@gmail.com on 9 Mar 2011 at 2:31

GoogleCodeExporter commented 9 years ago
Others have had problems with the contacts applicaiton. Try with the 
pre-installed calculator instead. I see nothing wrong in how you have created 
your test case. 

Original comment by renasr...@gmail.com on 9 Mar 2011 at 4:16

GoogleCodeExporter commented 9 years ago
I test already the pre-installed calculator. the test was successful. My next 
steps was the contacts application. 
Thank you for your support. 

Original comment by feu...@gmail.com on 10 Mar 2011 at 8:07

GoogleCodeExporter commented 9 years ago
Can somebody provide solution for it. I am also facing the same issue 

Original comment by mydreams...@gmail.com on 26 Jun 2012 at 12:02

GoogleCodeExporter commented 9 years ago
This is what you need to do:

I tested the Contacts.apk with Robotium in emulator.

If you want to test native applications(e.g. Contacts.apk, Settings.apk) then 
you have to use test key that is in android 
source(/build/target/product/security). There is README file in that place. 
Contacts.apk use 'shared' key.

Original comment by renasr...@gmail.com on 26 Jun 2012 at 1:01

GoogleCodeExporter commented 9 years ago
Any one tell me, in case of pre-installed app Calculator. When i use to adb 
push the calculator then the icon in emulator goes invisible. 

Original comment by mrawat...@gmail.com on 9 Aug 2012 at 5:30

GoogleCodeExporter commented 9 years ago
Can some one tell me how to add test project without having the complete 
Package and source code for the application. Like I don't have the complete 
source code for contacts.apk and while creating test project it asks for the 
package to browse.

Original comment by d.mishr...@gmail.com on 3 Oct 2012 at 1:49

GoogleCodeExporter commented 9 years ago
Please see:

http://code.google.com/p/robotium/wiki/RobotiumForPreInstalledApps

Original comment by renasr...@gmail.com on 3 Oct 2012 at 2:04

GoogleCodeExporter commented 9 years ago
Thanks for the reply.
 But the above link only tells about the pushing the new signed apk. While creating robotium test project it asks for the select test target to select from the existing project but for inbuilt apk we don't have the target project.(File > New > other > Android Test project >do next > Give project name>  Select Test Target ?  here what to select as I don't have the complete code for inbuilt apk).

Original comment by d.mishr...@gmail.com on 4 Oct 2012 at 8:54

GoogleCodeExporter commented 9 years ago
Please download the tutorial test android apk file with Robotium.

http://code.google.com/p/robotium/wiki/RobotiumTutorials

Original comment by renasr...@gmail.com on 4 Oct 2012 at 8:56

GoogleCodeExporter commented 9 years ago
The test android apk(AndroidCalculator) has calculator package and the source 
code for calculator. So I will be able to test only calculator package not 
other packages like settings. I want to test settings package but I don't have 
the source code for it. That's why I was asking what to select in "select Test 
Target" field in my previous comment.  

Original comment by d.mishr...@gmail.com on 4 Oct 2012 at 11:02