How to use R.id in robotium if I have only the apk file

0
0

I want to test an app from play market. I have a problem when I`m trying to use

solo.clickOnView(solo.getView(cn.wps.moffice_eng.R.id.writer_edittoolbar_saveBtn));

cn – cn cannot be resolved to a variable

How can i solve this poblem? As I understand, robotium can’t use R.id because I don’t have R.id file from my tested app?

my code

    package com.example.android.apis.test;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ListView;
import com.jayway.android.robotium.solo.Solo;
@SuppressWarnings("unchecked")
public class Test extends ActivityInstrumentationTestCase2 {
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "cn.wps.moffice.documentmanager.PreStartActivity";
private static Class<?> launcherActivityClass;
static{
try {
launcherActivityClass
= Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
@SuppressWarnings("unchecked")
public Test() throws ClassNotFoundException {
super(launcherActivityClass);
}
private Solo solo;
@Override
protected void setUp() throws Exception {
solo
= new Solo(getInstrumentation(), getActivity());
}
public void testSimple() {
solo
.sleep(2000);
solo
.clickOnButton(1);
solo
.sleep(2000);
solo
.clickOnImage(6);
solo
.sleep(2000);
solo
.clickInList(0);
solo
.sleep(5000);
solo
.sendKey(KeyEvent.KEYCODE_P);
solo
.sendKey(KeyEvent.KEYCODE_R);
solo
.sendKey(KeyEvent.KEYCODE_O);
solo
.sendKey(Solo.ENTER);
solo
.sleep(2000);
solo
.clickOnView(solo.getView(cn.wps.moffice_eng.R.id.writer_edittoolbar_saveBtn));
}
@Override
public void tearDown() throws Exception {
solo
.finishOpenedActivities();
}
}

and manifest

<?xml version="1.0" encoding="utf-8" standalone="no"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.example.android.apis.test">
<uses-sdk android:minSdkVersion="13"/>
<instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="cn.wps.moffice_eng"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
<uses-library android:name="android.test.runner"/>
</application>
</manifest>

MY SOLUTION: I found the solution – I decompiled apk file end pull R.id file to the robotium project – that was the key moment of my question

  • You must to post comments
0
0

As a @Renas suggested, getView(String id) is what you need.

In robotium 5.0.1 you should use just id string, not the whole name. It should look like this:

solo.clickOnView(solo.getView("resourceId"));
  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website