如何使用Espresso单击Android Gallery [英] How to click on Android Gallery with Espresso

查看:63
本文介绍了如何使用Espresso单击Android Gallery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前有一个正在与Espresso一起测试的Android应用程序.我们要测试的功能之一是从本地图片库中选择图片/图像.我们可以一路调出图库视图,但是无法在结果窗口中从最近",下载",图库"中进行选择.以下是关于我们如何达到目标的摘要.

We currently have an Android application that we are testing with Espresso. One of the features we want to test is selecting a picture/image from the local image gallery. We can get all the way to bringing up the Gallery view, but then cannot select from Recent, Downloads, Gallery in the resulting window. A snippet as to how we got as far as we did is included below.

public void testShouldBeAbleToSelectPhotoFromGallery() {

    getActivity();

    // given
    onView(withId(launch_gallery_button)).perform(click());
    onView(withText("Gallery")).perform(click());  // this is a button in our app
    // then we get stuck :(
}

谢谢!

推荐答案

对于Robotium或Espresso,这是不可能的,因为它们仅适用于被测应用程序的活动".

This is not possible with with either Robotium or Espresso, as they only work on Activities of the app under test.

要编写适用于不同应用程序和Android内置应用程序的集成测试,可以使用

To write integration tests that work across different apps and Android built-in apps, you can use the UiAutomator framework provided by Google.

基本上,您将在uiautomator视图中分析gallery应用程序,以了解如何选择测试用例所需的ui元素,然后对它们进行操作,这与Espresso不同.

Basically you would analyse the gallery app in the uiautomatorview to learn how to select the ui elements your test case needs and then act on them, not unlike Espresso.

这篇关于如何使用Espresso单击Android Gallery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆