相关疑难解决方法(0)

检查Espresso是否显示对话框

我正在尝试用新的android-test-kit(Espresso)编写一些测试.但我找不到任何关于如何检查对话框是否显示并在其上执行某些操作的信息(如单击正负按钮等).请注意,对话框也可以由a显示WebView,而不是由应用程序自己显示.

任何帮助,将不胜感激.我只需要一个链接,或基本的一些示例代码:

  1. 检查是否出现对话框
  2. 执行单击对话框按钮
  3. 与对话框的内部视图交互(如果它是自定义视图)
  4. 预先在对话框外点击,并检查它是否显示(例如,如果setCancelable(false)在对话框构建器上调用,我们要检查它)

谢谢你的建议!

android android-espresso

76
推荐指数
3
解决办法
5万
查看次数

ProgressBars和Espresso

当我在运行一些espresso测试时显示的布局中有ProgressBar时,我会遇到:

Caused by: android.support.test.espresso.AppNotIdleException: Looped for 1670 iterations over 60 SECONDS. The following Idle Conditions failed .
Run Code Online (Sandbox Code Playgroud)

解决这个问题的好方法是什么?找到一些hackish东西,但寻找一个很好的方式

android android-espresso

20
推荐指数
3
解决办法
4376
查看次数

Snackbar和Espresso有时会失败

正如标题所说,它失败了一些,有些则失败了.

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: "AppCompatTextView{id=2131492981, res-name=snackbar_text, visibility=VISIBLE, width=444, height=71, 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=18.0, y=0.0, text=Network Error, input-type=0, ime-target=false, has-links=false}"
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪的第一行表明espresso无法在屏幕上看到Snackbar.但是,第二行指出它实际上是看到了小吃吧与visibility=VISIBLEtext=Network Error它是正确的.

我很困惑,发生了什么事?

这是我的测试代码:

activityRule.launchActivity(new Intent());
onView(withText("Network Error")).check(matches(isDisplayed()));
Run Code Online (Sandbox Code Playgroud)

PS:当我运行整套测试服时,它大多失败了; 但有时当我单独运行此测试时它也会失败.有时它会传递绿色,但没有任何模式,似乎是随机的.

android android-espresso

7
推荐指数
1
解决办法
1975
查看次数

Android Espresso匹配根视图

我在我的一个活动中遇到匹配toast消息的问题.在其他情况下,它的工作没有任何问题,但在这个特殊的情况下却没有.我不知道任何可能导致此行为的特殊布局更改.

我得到以下异常:

java.lang.RuntimeException: Waited for the root of the view hierarchy to have window focus and not be requesting layout for over 10 seconds. If you specified a non default root matcher, it may be picking a root that never takes focus. Otherwise, something is seriously wrong. Selected Root:
Root{application-window-token=android.view.ViewRootImpl$W@40dcb2, window-token=android.view.ViewRootImpl$W@40dcb2, has-window-focus=false, layout-params-type=2, layout-params-string=WM.LayoutParams{(0,0)(wrapxwrap) gr=#11 sim=#20 ty=2 fl=#1820002 pfl=0x8 fmt=-3 wanim=0x7f0a0088 surfaceInsets=Rect(0, 0 - 0, 0) mwfl=0x10}, decor-view-string=DecorView{id=-1, visibility=GONE, width=1002, height=348, has-focus=false, has-focusable=false, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-espresso

7
推荐指数
0
解决办法
3188
查看次数

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

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

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

android unit-testing android-toast android-espresso

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

使用 Espresso 测试 Toast 消息未解决

我无法使用浓缩咖啡测试 Toast 消息。有很多与之相关的问题和答案,但我无法解决该问题。

测试代码

 class ToastMatcher extends TypeSafeMatcher<Root> {

    @Override
    public boolean matchesSafely(Root root) {
        int type = root.getWindowLayoutParams().get().type;
        if ((type == WindowManager.LayoutParams.TYPE_TOAST)) {
            IBinder windowToken = root.getDecorView().getWindowToken();
            IBinder appToken = root.getDecorView().getApplicationWindowToken();
            if (windowToken == appToken) {
                return true;
                //means this window isn't contained by any other windows.
            }
        }
        return false;
    }

     @Override
     public void describeTo(Description description) {

         description.appendText(String.valueOf(R.string.messsage_login_successful));
     }
 }


   @Test
    public void btnLoginClickWithPassingUserNameAndPassword() throws Exception {
        onView(withId(R.id.etUsername)).perform(clearText());
        onView(withId(R.id.etUsername)).perform(typeText(userName));
        onView(withId(R.id.etPassword)).perform(typeText(passWord));
        onView(withId(R.id.btnLogin)).perform(click());

//        onView(withText(R.string.messsage_login_successful)).inRoot(withDecorView(not(mActivityRule.getActivity().getWindow().getDecorView()))).check(matches(isDisplayed()));
     //   onView(withText(R.string.messsage_login_successful)).inRoot(withDecorView(not(is(mActivityRule.getActivity().getWindow().getDecorView())))).check(matches(isDisplayed()));

        onView(withText(R.string.messsage_login_successful)).inRoot(new ToastMatcher())
                .check(matches(isDisplayed())); …
Run Code Online (Sandbox Code Playgroud)

android toast android-espresso

5
推荐指数
1
解决办法
3434
查看次数