我想从游戏市场测试一个应用程序。我尝试使用时遇到问题
solo.clickOnView(solo.getView(cn.wps.moffice_eng.R.id.writer_edittoolbar_saveBtn));
cn - cn 无法解析为变量
我该如何解决这个问题?据我了解,robotium 不能使用 R.id 因为我的测试应用程序没有 R.id 文件?
我的代码
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();
}
}
并表现出来
<?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>
我的解决方案:我找到了解决方案——我反编译了 apk 文件并最终将 R.id 文件拉到了机器人项目中——这是我提出问题的关键时刻