Tag: android espresso

控制自动化测试何时结束 – Espresso

我正在测试一个不寻常的情况。 我正在使用Espresso来编写我的测试。 我知道Espresso和InstrumentationTestCase不是为了做到这一点。 我有一个我在其中一个课程中创​​建的监听器,它会通知我某个值的变化。 我在我的测试套件中使用了监听器。 当我从侦听器获取值时,我需要声明值已更改为此类。 我的问题是测试将在我收到监听器的值之前结束。 private void sendSpeedChanges() { setStaticSpeed(new Random().nextInt(10) + 2); try { runTestOnUiThread(new Runnable() { @Override public void run() { consoleActivity.onSpeedChanged(getStaticSpeed(), false); } }); } catch (Throwable throwable) { throwable.printStackTrace(); } } private void createSpeedDelegate() { EspressoMachineValues.setOnSpeedChangeListener(new EspressoMachineValues.OnSpeedChangeListener() { @Override public void onSpeedChanged(double speed) { //assert speed is correct. assertTrue(getStaticSpeed() […]

Espresso onData在视图上执行“加载适配器数据”时出错

我有一个应用程序,有ListView,我想找到LinearLayout,id = order_untake_jijia_listview_jia 代码是: onData(withClassName(endsWith(“ListView”))) .inAdapterView(allOf(withId(R.id.order_untake_jijia_listview_ll), hasSibling(withText(“9.0”)))) .atPosition(0).onChildView(withId(R.id.order_untake_jijia_listview_jia)); dataInteraction.perform(ViewActions.click()); 但我有错误: Error performing ‘load adapter data’ on view ‘(with id: com.edaixi:id/order_untake_jijia_listview_ll and has sibling: with text: is “9.0”)’. Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints: (is assignable from class: class android.widget.AdapterView […]

预validation类中的Android错误类ref解析为意外实现

我在Android Espresso测试中遇到过这个问题。 但是这在运行/编译时运行良好。 我知道这个错误有几个线程,但我找不到符合我情况的修复程序。 我目前正在处理一个 “java.lang.IllegalAccessError:预validation类中的类ref解析为意外实现”。 我已经添加了 androidTestCompile(‘com.android.support.test.espresso:espresso-contrib:2.2’) { exclude group: ‘com.android.support’, module: ‘support-v4’ } 但它仍然无法正常工作。 有人可以帮我解决这个问题。 谢谢。 这是我的依赖 dependencies { compile fileTree(dir: ‘libs’, include: [‘*.jar’]) /*Android Testing*/ androidTestCompile ‘com.android.support.test:runner:0.3’ androidTestCompile ‘com.android.support.test:rules:0.3’ androidTestCompile ‘com.android.support.test.espresso:espresso-core:2.2’ androidTestCompile ‘com.android.support.test.espresso:espresso-idling-resource:2.2.1’ androidTestCompile ‘com.android.support:support-annotations:23.0.1’ androidTestCompile(‘com.android.support.test.espresso:espresso-contrib:2.2’) { exclude group: ‘com.android.support’, module: ‘support-v4’ } compile ‘com.google.android.gms:play-services:8.3.0’ compile ‘com.android.support:support-v4:23.0.+’ compile ‘com.android.support:appcompat-v7:23.0.1’ compile ‘com.mcxiaoke.volley:library:1.0.18’ compile […]

浓咖啡:选择后为什么纺纱厂不关门?

我有一个关于在Spinners with Espresso中选择商品的问题。 或者更确切地说:选择有效,但之后视图断言失败,因为微调器仍处于打开状态。 假设我有一个非常简单的活动,其中包含一个微调器和一个显示选择的textview,如下所示: 现在,我写了一个Espresso测试,选择’狗’并validationtextview是否相应更新: @Test public void selectDogs() throws Exception { onData(allOf(is(instanceOf(String.class)), is(“dogs”))) .inAdapterView(withId(R.id.spinner)) .perform(click()); onView(withId(R.id.selected)).check(matches(withText(“dogs”))); } 该测试失败,因为onData()…perform(click()); 没有关闭旋转器,它只是让它打开。 通过调试validation: 例外是: android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: org.flinc.app:id/selected If the target view is not part of the view hierarchy, you may need to use Espresso.onData to load it from one […]

在Dalvik运行时设备上运行Espresso仪器测试的问题

我遇到类似的问题, FragmentActivity无法通过ActivityInstrumentationTestCase2进行测试 顶级解决方案存在的问题仅适用于使用Eclipse构建系统。 我正在使用Gradle作为我的项目。 在运行ART运行时的Nexus 5上,我的Espresso仪器测试运行完美。 当我在Dalvik运行时或模拟器上使用Nexus 4时,我遇到了在测试框架之外运行应用程序时不会发生的exception。 java.lang.NoClassDefFoundError: com.packagename.fragment.ProgressDialogFragment 在日志中,我发现这些可疑消息类似于链接的问题: Class resolved by unexpected DEX: Landroid/support/v4/app/DialogFragment2;(0x41e969d8):0x76064000 ref [Landroid/support/v4/app/DialogFragment;] Landroid/support/v4/app/DialogFragment;(0x41e969d8):0x75883000 (Landroid/support/v4/app/DialogFragment2; had used a different Landroid/support/v4/app/DialogFragment; during pre-verification) Unable to resolve superclass of Landroid/support/v4/app/DialogFragment2; (271) Link of class ‘Landroid/support/v4/app/DialogFragment2;’ failed Unable to resolve superclass of Lcom/packagename/fragment/ProgressDialogFragment; (270) Link of class ‘Lcom/packagename/fragment/ProgressDialogFragment;’ failed Could not find […]

第二个活动上的单击按钮在视图上执行“单击”或“滚动到”时出错

单击Espresso测试中的按钮会出现问题。 假设我有两个活动“Activity1”和“Activity2”。 单击Activity1中的对话框确定按钮启动Activity2,其中无法单击Activity2中的按钮。 // The current activity in testing // ….. onView(withText(R.string.dialog_btn_ok)).perform(click()); // go to the second activity // The button on the second activity onView(withId(R.id.btnMP)).check(matches(isDisplayed())); // this is ok onView(withId(R.id.btnMP)).perform(click()); // got error here android.support.test.espresso.PerformException:在视图’上执行’单击’时出错,ID为:………. 引发者:java.lang.RuntimeException:将不执行操作,因为目标视图与以下一个或多个约束不匹配:至少90%的视图区域显示给用户。 目标视图:“按钮{id = 2131296390,res-name = btnMP,visibility = VISIBLE,width = 652,height = 160,has-focus = false,has-focusable = true,has-window-focus = true,is- clickable […]