相关疑难解决方法(0)

Android Espresso:PerformException

我得到了

android.support.test.espresso.PerformException:在视图上执行'send keyCode:4,metaState:0 key event'时出错'目标设备上启用了动画或转换.

我读的文章有相同的错误,但没有找到答案.

我有简单的Android应用程序,我尝试测试简单的事情:

  1. 加载RecyclerView
  2. 单击RecyclerView的项目
  3. 打开活动
  4. 按活动中的按钮
  5. 按下
  6. 从第1部分开始重复

代码非常简单:

@Test
public void getOver500Products() {
    onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
    onView(withId(R.id.layout2)).perform(click());
    clickExactItem(2);
    for (int i = 0; i< 501; i++) {
        clickRandomItem();
        addedToCart();
        Espresso.pressBack();
    }
}

public void clickRandomItem() {
    try {
        int x = getRandomRecyclerPosition(R.id.list);
        clickExactItem(x);
    } catch (NoMatchingViewException e) {
    }
}

public void clickExactItem(int position) {
    onView(withId(R.id.list))
            .perform(RecyclerViewActions
                    .actionOnItemAtPosition(position, click()));
}

public boolean addedToCart() {
    try {
        onView(withId(R.id.product_add_in_cart)).perform(click());
    } catch (NoMatchingViewException e) {
        return false;
    } …
Run Code Online (Sandbox Code Playgroud)

java android android-espresso

21
推荐指数
3
解决办法
9779
查看次数

Espresso - 使用异步加载的数据断言TextView

我正在使用谷歌Espresso for Android编写UI测试,我一直坚持如何断言TextView文本,这些内容是从Web服务异步加载的.我目前的代码是:

public class MyTest extends BaseTestCase<MyActivity>{
    public void setUp() throws Exception {
        // (1) Tell the activity to load 'element-to-be-loaded' from webservice
        this.setActivityIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("data://data/element-to-be-loaded")));
        getActivity();

        super.setUp();
    }

    public void testClickOnReviews(){
        // (2) Check the element is loaded and its name is displayed
        Espresso
            .onView(ViewMatchers.withId(R.id.element_name))
            .check(ViewAssertions.matches(ViewMatchers.withText("My Name")));

        // (3) Click on the details box
        Espresso
            .onView(ViewMatchers.withId(R.id.details_box))
            .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
            .perform(ViewActions.click());

        // (4) Wait for the details screen to open
        Espresso
            .onView(ViewMatchers.withId(R.id.review_box));

        // Go back to element screen
        Espresso.pressBack();
    }
} …
Run Code Online (Sandbox Code Playgroud)

android android-testing android-espresso

14
推荐指数
1
解决办法
2万
查看次数

是否可以使用 Espresso 的 IdlingResource 等待某个视图出现?

在我的测试中,我有一个阶段,在按下按钮后,应用程序会执行大量异步计算并向云服务发出请求,之后它会显示某个视图。

是否可以使用 Espresso 的IdlingResource实现来等待某个视图出现?

我在这里阅读了一个答案,评论似乎表明您可以使用它IdlingResource,但我不明白如何使用。Espresso 似乎没有任何内置的方法来处理长时间的操作,但是必须编写自己的等待循环感觉就像一个黑客。

有什么方法可以解决这个问题,还是我应该按照链接线程中的答案进行操作?

java android automated-tests android-espresso

11
推荐指数
3
解决办法
8533
查看次数

意式浓缩咖啡执行点击

我试图用'espresso'编写简单的测试

@RunWith(AndroidJUnit4.class)
@LargeTest
public class EspressoTest {
    @Rule
    public ActivityRule<IntroActivity> mActivityRule = new ActivityRule(IntroActivity.class);

    public EspressoTest() {
        IdlingPolicies.setMasterPolicyTimeout(1000, TimeUnit.SECONDS);
    }

    @Test
    public void testShouldClickEmailButton() {
            onView(withText(R.string.in_email)).perform(click());
    }


}
Run Code Online (Sandbox Code Playgroud)

但我得到一个错误:

PerformException: Error performing 'single click' on view 'with string from resource id: <2131099761>[in.email] value: Login With Email'.
Run Code Online (Sandbox Code Playgroud)

我正在尝试不同的测试框架,robotium目前为止对我来说是最好的,但是如果有人可以解决此错误,我将不胜感激

UPD更详细的日志

由以下原因引起:java.lang.RuntimeException:由于目标视图与以下一个或多个约束不匹配,因此不会执行操作:向用户显示视图区域的至少90%。目标视图:“ DSeparatedButton {id = 2131427459,res-name = button_login,可见性= VISIBLE,宽度= 622,高度= 120,has-focus = false,has-focusable = true,has-window-focus = true,is- clickable = true,is-enabled = true,is-focused = false,is-focusable = true,is-layout-requested = false,is-selected = false,root-is-layout-requested …

android android-espresso

6
推荐指数
1
解决办法
7982
查看次数

是否可以禁用Toasts或等待吐司在测试时消失

我正在测试一个应用程序Espresso.我有一个问题是可能要等到目前没有吐司出现.我在我的应用程序中有很多不同的吐司,但是在测试时我遇到了问题,因为据我所知,焦点已经转向吐司,我正在获得另一个视图层次结构,我可以在错误日志中看到.
所以我的问题是可以隐藏所有(系统范围内的root访问权限)或只是等到屏幕上有任何toast,或者是否可以手动将焦点设置到活动视图层次结构.
如果对这个问题有任何帮助,我将不胜感激.
谢谢.

PS禁用toast直接在我的应用程序中的某个地方不是一个选项,因为它为应用程序带来了一些额外的逻辑,这只是在测试时需要.

android unit-testing android-toast android-espresso

6
推荐指数
1
解决办法
2597
查看次数

强制浓咖啡不要等待进步

默认情况下,espresso会在执行下一条指令之前等待我的活动​​中的进度条完成加载.

我想强制Espresso不要等待它并在加载进度对话框时执行其余的指令.

关于我应该寻找的任何点击?

经过一些调查后,我认为我必须利用这门IdlingResource课程.

android android-espresso

6
推荐指数
1
解决办法
1527
查看次数

Android Espresso不等待UI完成

我有一个测试需要打开android.support.v7.preference.ListPreference对话框,选择一个选项,打开NavDrawer并从抽屉中选择一个项目.

对话框的定义如下:

<android.support.v7.preference.ListPreference
    android:defaultValue="@string/pref_default_VALUE"
    android:entries="@array/pref_VALUE_entries"
    android:entryValues="@array/pref_VALUE_values"
    android:key="@string/pref_key_VALUE"
    android:negativeButtonText="@null"
    android:positiveButtonText="@null"
    android:title="@string/pref_title_VALUE" />
Run Code Online (Sandbox Code Playgroud)

Espresso打开它像这样:

onView(withText(mActivityRule.getActivity().getResources().getString(R.string.pref_title_VALUE))
    .perform(click());
Run Code Online (Sandbox Code Playgroud)

这会打开ListPreference,但它不会阻塞,测试中的下一行会立即运行.

// click on setting
    onView(withText(VALUE_IN_LIST_PREFERENCE))
            .perform(click());
Run Code Online (Sandbox Code Playgroud)

由于这种情况立即发生,因此没有出现对话框,并且withText(VALUE_IN_LIST_PREFERENCE)不匹配任何内容.

如果我单步执行调试器,暂停上面的行,对话框将及时显示,代码将起作用.

导航抽屉也会出现同样的问题.它像这样打开:

// open the nav drawer
    onView(withId(R.id.drawer_layout))
            .perform(DrawerActions.open());
Run Code Online (Sandbox Code Playgroud)

点击一个项目:

// click on phase 1
    onView(withId(R.id.nav_view))
            .perform(NavigationViewActions.navigateTo(R.id.nav_ITEM));
Run Code Online (Sandbox Code Playgroud)

与ListPreferences一样,测试代码继续而不等待UI完成,因此对onView的调用失败.

我已经尝试将线程置于睡眠状态并按照这里的答案/sf/answers/1579430821/

但是在这两种情况下,只有在Thread完成休眠并且视图测试立即运行之后才会出现对话框.所以,问题只是延迟,而不是解决.

如何在必要的视图可见之前确保不运行Espresso测试?

android android-testing android-espresso

6
推荐指数
1
解决办法
2142
查看次数

Espresso不会等到显示对话框并失败

我正在使用Espresso进行一些简单的测试。其中之一是关于单击视图并检查是否显示对话框。

我的问题是有时有效,有时无效。仅当我在检查对话框之前先入睡时,它才始终有效。有没有不使用睡眠的解决方案?

这是我的代码(非常简单):

onView(withId(R.id.forgot_password)).perform(click());
// only works if use Thread.sleep(ms) here
onView(withText(R.string.reset_password)).check(matches(isDisplayed()));
Run Code Online (Sandbox Code Playgroud)

编辑:

我正在显示带有静态助手的对话框,但是简化了。而且我不在中间执行任何后台任务。

最终的TextInputDialog textInputDialog = new

TextInputDialog.Builder(context)
                .setTitle(titleId)
                .setInputType(inputType)
                .setHint(hintId)
                .setPreFilledText(preFilledText)
                .setNegativeButton(R.string.cancel, null)
                .setPositiveButton(positiveButtonId, onTextSubmittedListener)
                .create();
textInputDialog.show(textInputDialog);
Run Code Online (Sandbox Code Playgroud)

谢谢!

android android-espresso

5
推荐指数
2
解决办法
3370
查看次数

如何使用Esspresso测试创建点击按钮的延迟

我是esspresso问题的新手,我有一个小问题,我需要模仿用户点击按钮,树时间,但有一些延迟.一个人,需要一些时间点击一个按钮,可能有一秒钟的延迟.

什么是更好的方式来进行esspresso测试?其他框架有睡眠,等等...但我认为浓咖啡不是.任何的想法?

- 编辑:我做了这个,但不知道它是否正确:

try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

另一种方式,但更清楚的是,如果你不使用thread.interrupt()是这样的:

SystemClock.sleep(millis)
Run Code Online (Sandbox Code Playgroud)

android wait android-espresso

4
推荐指数
1
解决办法
6924
查看次数

Android Espresso片状withId withText测试

我有这项测试的时间大约是一半。

  @Test
  public void thirdSwipe() {
    onView(withId(R.id.pager)).perform(swipeLeft());
    onView(withId(R.id.pager)).perform(swipeLeft());
    onView(withId(R.id.pager)).perform(swipeLeft());
    onView(allOf(withId(R.id.hint_english_text), withText("dog 0a"))).check(matches(isDisplayed()));
  }
Run Code Online (Sandbox Code Playgroud)

我得到这个失败:

android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'is displayed on the screen to the user' doesn't match the selected view.
Expected: is displayed on the screen to the user
Got: "TextView{id=2131427358, res-name=hint_english_text, visibility=VISIBLE, width=624, height=62, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=20.0, y=20.0, text=dog 0a, input-type=0, ime-target=false, has-links=false}"
Run Code Online (Sandbox Code Playgroud)

因此,看起来好像找到了TextViewwith "dog 0a",但无法识别它。我看了其他问题,并用设置了文本String,这只是我课堂上的几行:

private String  englishText;
englishTextView.setText(englishText);
Run Code Online (Sandbox Code Playgroud)

另外,我正在使用allOf()。任何帮助,将不胜感激。该视图位于ViewPager的视图内,因此我不确定测试是否在ViewPagerid …

android android-espresso

3
推荐指数
1
解决办法
962
查看次数

Android Espresso等待文本出现

我正在尝试使用Espresso自动执行Android应用程序,即聊天机器人。我可以说我是Android应用程序自动化的全新手。现在,我正苦苦等待。如果我使用thread.sleep,它可以很好地工作。但是我想等待特定的文本出现在屏幕上-我该怎么做?

@Rule
public ActivityTestRule<LoginActivity> mActivityTestRule = new ActivityTestRule<>(LoginActivity.class);

@Test
public void loginActivityTest() {
ViewInteraction loginName = onView(allOf(withId(R.id.text_edit_field),
childAtPosition(childAtPosition(withId(R.id.email_field),0), 1)));
loginName.perform(scrollTo(), replaceText("test@test.test"), closeSoftKeyboard());

ViewInteraction password= onView(allOf(withId(R.id.text_edit_field),
childAtPosition(childAtPosition(withId(R.id.password_field),0), 1)));
password.perform(scrollTo(), replaceText("12345678"), closeSoftKeyboard());

ViewInteraction singInButton = onView(allOf(withId(R.id.sign_in), withText("Sign In"),childAtPosition(childAtPosition(withId(R.id.scrollView), 0),2)));
singInButton .perform(scrollTo(), click());
Run Code Online (Sandbox Code Playgroud)

//这里我需要等待文本“ Hi ...” //一些解释:按下按钮签名后,聊天机器人说“ hi”,会提供更多信息,我想等待最后一条消息出现屏幕上。

android chatbot android-espresso

0
推荐指数
2
解决办法
4994
查看次数