我是使用Robotium在Android上测试的新手.在运行某些测试之前,我如何以编程方式卸载然后安装应用程序?
例如,为了让我测试登录活动,我需要确保不会从先前运行的应用程序中保存登录凭据.或者还有另一种方法吗?
我正在使用robotium进行测试,无法弄清楚如何点击没有文字的按钮.测试失败并跟踪:
junit.framework.AssertionFailedError:索引为2131034130的按钮不可用!
我使用Robotium作为我的Android应用程序的Junit测试库.我写了一些效果很好的测试.但是当我尝试为本机ActionBar的Up/Home按钮编写测试时,它失败了.
我的测试代码非常简单:
Solo solo = new Solo(getInstrumentation(), getActivity());
...
solo.clickOnActionBarHomeButton(); // I expected it will click the Up/Home button of ActionBar
Run Code Online (Sandbox Code Playgroud)
我预计上面的代码将单击本机ActionBar的Up/Home按钮,但它失败了,操作栏上没有发生任何事情.为什么??
PS我正在使用Android 4.2.1设备.
任何想法为什么将HOME键发送到在Instrumentation下运行的应用程序什么都不做?
import android.app.Instrumentation;
import android.view.KeyEvent;
public class MyInstrumentation extends Instrumentation {
public void sendKeys() {
// Works reliably
this.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
// Does nothing, nothing is printed to logcat
this.sendKeyDownUpSync(KeyEvent.KEYCODE_HOME);
}
}
Run Code Online (Sandbox Code Playgroud)
使用Robotium时以及直接使用Instrumentation时也是如此.模拟器和非root设备上的行为相同.
instrumentation android robotium android-testing android-instrumentation
在我的Android应用程序(平板电脑)中,我想验证在选择按钮后,片段出现在屏幕上.有没有办法做到这一点?
我正在尝试使用Robotium创建一种测试方法,以检查单击按钮后Android应用程序是否完成(在代码中,finish()当用户点击该按钮时便有一个调用)。
public void test_onclickExit_finish() {
String buttonText = resources.getString(R.string.exit);
Button exitButton = solo.getButton(buttonText, true);
solo.clickOnView(exitButton);
// check here that the app has finished
// wait for the activity to finish?
assertTrue(solo.getCurrentActivity() == null);
}
Run Code Online (Sandbox Code Playgroud)
但是这个测试失败了。我不知道如何指示测试要等到活动结束。另外,我不确定使用getCurrentActivity()是否是检查应用程序是否完成的好方法。
如何检查申请/活动是否完成?
谢谢。
我有很多apk文件,我想用robotium为它们编写简单的测试.当我尝试在Dropbox应用程序中找到主要活动时,我遇到了一些问题.在AndroidManifest.xml中,我发现了这个:
</activity>
<provider android:name=".provider.ZipperedMediaProvider" android:exported="false" android:authorities="com.dropbox.android.ZipperedMediaProvider"></provider>
<provider android:name=".provider.CameraUploadsProvider" android:exported="false" android:authorities="com.dropbox.android.CameraUploadsProvider"></provider>
<activity android:theme="@android:01030055" android:name=".activity.DropboxBrowser">
<intent-filter >
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
<intent-filter android:label="Dropbox File Browser">
<action android:name="com.dropbox.BROWSE"></action>
<action android:name="android.intent.action.VIEW"></action>
<action android:name="android.intent.action.EDIT"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<data android:mimeType="vnd.android.cursor.dir/vnd.dropbox.entry"></data>
<data android:mimeType="vnd.android.cursor.item/vnd.dropbox.entry"></data>
</intent-filter>
</activity>
如何理解主要活动的调用方式?我正在使用ApkAnalyser,我尝试了不同的类名和其他字符串,但是机器人测试无法启动应用程序,并写道我的项目中没有测试:/(apk在我的电脑中重新签名)我想了解,如何从apk文件中识别MainActivity?谢谢
我正在使用机器人.今天我遇到了一点问题.点击按钮后,应用程序将转到下一个活动.我需要等待出现一些按钮.
View am = solo.getView(R.id.btn_login);
solo.waitForCondition(am.isShown(), 5000);
Run Code Online (Sandbox Code Playgroud)
此代码不起作用.
如果我被识别为,它也不起作用
Button am = solo.getButton(R.id.btn_login);
Run Code Online (Sandbox Code Playgroud)
帮帮我吧!
我在设置Robotium测试时遇到问题,在Travis上运行时没有随机的假性.
我得到的每一对构建
pl.mg6.agrtt.TestActivityTests > testCanEnterTextAndPressButton[test(AVD) - 4.4.2] FAILED
junit.framework.AssertionFailedError: EditText is not found!
at com.robotium.solo.Waiter.waitForAndGetView(Waiter.java:540)
Run Code Online (Sandbox Code Playgroud)
在我的所有测试中.
我在GitHub上创建了一个简单的项目来显示问题.
你可能会看到它是如何在Travis上构建的.注意构建#7在使用不相关的文件后失败.
我怀疑这是由于模拟器被锁定或其暗淡变暗造成的.我可以通过关闭连接设备的屏幕然后运行来在本地计算机上重现此问题
./gradlew connectedAndroidTest
Run Code Online (Sandbox Code Playgroud)
在modyfing测试之后,我得到了一个不同的错误消息,这有点更丰富,所以我添加它以防万一有人试图找到解决方案:
pl.mg6.agrtt.TestActivityTests > testCanFindViewsEnterTextAndPressButton[test(AVD) - 4.4.2] FAILED
junit.framework.AssertionFailedError: Click at (160.0, 264.0) can not be completed! (java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission)
at com.robotium.solo.Clicker.clickOnScreen(Clicker.java:106)
Run Code Online (Sandbox Code Playgroud) 在安装Android应用程序时是否有允许adb命令行选项的gradle插件?我希望在Android M设备上运行robotium测试,同时忽略弹出要求摄像头,麦克风等权限的权限对话框.