天道酬勤,学无止境

robotium

如何使用 Android UiAutomation.injectInputEvent 注入点击事件(How to inject click event with Android UiAutomation.injectInputEvent)

问题 我在安装设备管理员的应用程序中自动测试流程。 要在大多数设备上激活设备管理员(假设我没有一些企业 API 可以让我像三星提供的那样执行此操作),系统会向用户显示一个弹出窗口,然后用户必须单击“激活”按钮。 我正在使用 Robotium 和 Android JUnit 来驱动我的测试。 在正常的测试案例中,您只能与被测应用程序和进程交互,而不能与出现的任何系统活动交互。 UiAutomation 声称允许您通过利用 Accessibility Framework 与其他应用程序交互,然后允许注入任意输入事件。 所以 - 这就是我想要做的: public class AbcTests extends ActivityInstrumentationTestCase2<AbcActivity> { private Solo mSolo @Override public void setUp() { mSolo = new Solo(getInstrumentation(), getActivity()); } ... public void testAbc(){ final UiAutomation automation = getInstrumentation().getUiAutomation(); MotionEvent motionDown = MotionEvent

2021-11-28 06:05:44    分类:技术分享    android   testing   ui-automation   robotium

Unable to get Robotium to work in Android Studio

I'm struggling to get Robotium to work on the gradle-based Android Studio and I can't find the way to do it This is my build.gradle file buildscript { dependencies { repositories { mavenCentral() mavenLocal() } classpath 'com.android.tools.build:gradle:0.5.+' } } apply plugin: 'android' repositories { mavenCentral() /* maven { url "https://oss.sonatype.org/content/repositories/snapshots" }*/ } sourceSets { testLocal { java.srcDir file('src/test/java') resources.srcDir file('src/test/resources') } } android { compileSdkVersion 17 buildToolsVersion "17.0.0" defaultConfig { minSdkVersion 15

2021-11-27 19:41:30    分类:问答    android   gradle   robotium   android-testing   ui-testing

(Robotium) 操作栏向上/主页按钮单击((Robotium) Action bar up/home button click)

问题 我使用 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 我希望上面的代码会点击原生 ActionBar 的 Up/Home 按钮,但它失败了,操作栏上什么也没发生。 为什么?? PS我使用的是 Android 4.2.1 设备。 回答1 我使用这个功能: public void clickOnActionBarHomeButton(Solo solo) { View homeView = solo.getView(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? android.R.id.home : R.id.home); solo.clickOnView(homeView); } 也许这不是一个完美的决定,但它有效。 回答2

2021-11-26 14:23:45    分类:技术分享    android   android-layout   robotium

遍历列表并单击 Robotium 中的列表项(Iterating through a List and clicking on list items in Robotium)

问题 我试图通过遍历列表并单击每个列表元素来启动另一个活动,在 Robotium 中运行一些自动化测试。 我的测试方法中有以下代码: 代码: solo.assertCurrentActivity("Wrong activity", MainActivity.class); //Clicks on the action bar tab solo.clickOnText("Charts"); ArrayList<ListView> list = solo.getCurrentListViews(); for(int i = 0; i < list.size(); i++) { //Clicks on the list item assert that the new activity is started solo.clickInList(chartPosition); solo.assertCurrentActivity("Json Class", JsonActivity.class); //Go back to the list solo.goBack(); } 上面的代码没有点击任何列表项,JUnit测试结果显示所有测试都通过了,这很令人困惑。 有没有人如何成功遍历 Robotium 中的列表? 我看到了另一个与此类似的问题,但答案建议查看 jMock,这无济于事。 回答1

2021-11-26 08:21:50    分类:技术分享    android   robotium

使用robotium滚动时单击所有列表视图元素(Click all the list view elements while scrolling using robotium)

问题 我有一个包含很多元素的 listView,即我们必须向下滚动才能看到所有元素。 现在我想要做的是,单击所有 listView 元素。 我怎样才能做到这一点。 现在,我正在使用以下代码,但它不会自动滚动。 请帮忙。 ListView l = solo.getCurrentListViews().get(0); assertNotNull("No list views!", l); assertTrue("No items in list view!", l.getChildCount() > 0); // Get the last list item View v = l.getChildAt(l.getChildCount()); System.out.println("getChildCount: " + l.getChildCount()); int i = 1; while (i <= l.getChildCount()) { solo.clickInList(i); solo.goBack(); i++; } 回答1 我以前在稍微不同的状态下使用这些辅助函数来处理我们需要的大部分列表视图: public View getViewAtIndex(final ListView listElement, final int indexInList

2021-11-26 04:56:31    分类:技术分享    android   listview   robotium

Robotium: Please install a compatible Android API level (15 or higher)

Trying to run a new robotium test I get this error. Does anyone know how to fix it? I've all the APIs needed. (15 and a lot of higher APIs). What am I missing? This is part of my gradle file: android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { applicationId "com.centervue.exam" minSdkVersion 19 targetSdkVersion 25 // DO NOT PUT HERE VERSION NAME, THX. Change the Manifest testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" ndk { moduleName "exam_filter" ldLibs "log", "jnigraphics" } renderscriptTargetApi 18 renderscriptSupportModeEnabled true } [...]

2021-11-25 00:37:47    分类:问答    android   robotium   robotium-recorder

(Robotium) Action bar up/home button click

I use Robotium as the library for Junit test for my Android application. I wrote some tests which works well. But when I try to write a test for native ActionBar's Up/Home button click, it failed. My test code is very simple: Solo solo = new Solo(getInstrumentation(), getActivity()); ... solo.clickOnActionBarHomeButton(); // I expected it will click the Up/Home button of ActionBar I expected the above code will click the Up/Home button of native ActionBar, but it is failed, nothing was happening on action bar. Why?? P.S. I am using an Android 4.2.1 device.

2021-11-23 02:18:19    分类:问答    android   android-layout   robotium

How to inject click event with Android UiAutomation.injectInputEvent

I'm automating the testing of a flow in my app where I install a device administrator. To activate a device administrator on most devices (let's assume here I don't have some enterprise API that lets me do this like what Samsung offers) the system displays a popup to the user who then has to click the "Activate" button. I'm using Robotium and Android JUnit to drive my tests. In a normal testing case one can only interact with the app and process under test and not any system activities that come up. The UiAutomation claims to allow you to interact with other applications by leveraging the

2021-11-22 01:53:27    分类:问答    android   testing   ui-automation   robotium

Iterating through a List and clicking on list items in Robotium

I'm trying to run some automated tests in Robotium by iterating through a list and clicking on each list element to start another activity. I have the code below in my test method: Code: solo.assertCurrentActivity("Wrong activity", MainActivity.class); //Clicks on the action bar tab solo.clickOnText("Charts"); ArrayList<ListView> list = solo.getCurrentListViews(); for(int i = 0; i < list.size(); i++) { //Clicks on the list item assert that the new activity is started solo.clickInList(chartPosition); solo.assertCurrentActivity("Json Class", JsonActivity.class); //Go back to the list solo.goBack

2021-11-20 14:43:19    分类:问答    android   robotium

Click all the list view elements while scrolling using robotium

I have a listView that contains lots of elements i.e. we have to scroll down to see all the elements. Now what i want to do is, click all the listView elements. How can I do that. Right now,I am using the following code but it doesn't scroll automatically. Please help. ListView l = solo.getCurrentListViews().get(0); assertNotNull("No list views!", l); assertTrue("No items in list view!", l.getChildCount() > 0); // Get the last list item View v = l.getChildAt(l.getChildCount()); System.out.println("getChildCount: " + l.getChildCount()); int i = 1; while (i <= l.getChildCount()) { solo

2021-11-19 22:31:52    分类:问答    android   listview   robotium