相关疑难解决方法(0)

使用withId匹配器时,Espresso NoMatchingViewException

我正在尝试编写一个简单的测试,我只需单击主要活动中的MenuItem:

public class doTest extends ActivityInstrumentationTestCase2<doActivity> {

  public doTest() {
    super(doActivity.class);
  }

  @Override
  public void setUp() throws Exception {
    super.setUp();
    startActivity();

  }

  private void startActivity() {
    Intent intent = new Intent();
    setActivityIntent(intent);
    getActivity();
  }

  public void testOne() {
    Espresso.openContextualActionModeOverflowMenu();
    onView(withId(R.id.create_new)).perform(ViewActions.click());
  }

}
Run Code Online (Sandbox Code Playgroud)

测试失败并显示"NoMatchingViewException".如果我将onView行更改为:

    onView(withText("Add new")).perform(ViewActions.click());
Run Code Online (Sandbox Code Playgroud)

以下是活动的菜单xml:

 <item
        android:id="@+id/create_new"
        android:title="Add new"
        tools:ignore="HardcodedText">
    </item>
Run Code Online (Sandbox Code Playgroud)

测试工作.为什么matcher withText会找到视图,而匹配器却找不到?

android android-espresso

8
推荐指数
1
解决办法
3885
查看次数

使用Android Espresso进行测试时如何点击Action Bar项目?

我正在使用Android Espresso来测试我的活动.我有多个操作栏项,其中大部分都隐藏在溢出中.我试图运行此测试但错误说层次结构中没有视图(不同于不可见):

@MediumTest
public void testClickInsertItem() {
  Espresso.onView(ViewMatchers.withId(R.id.action_insert)).perform(ViewActions.click());
}
Run Code Online (Sandbox Code Playgroud)

而错误:

android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: blogr.vpm.fr.blogr:id/action_insert
If the target view is not part of the view hierarchy, you may need to use Espresso.onData to load it from one of the following AdapterViews:android.widget.ListView{5283cfb0 VFED.VC. ........ 2,2-762,973 #7f07000b app:id/allitems}

View Hierarchy:
+>DecorView{id=-1, visibility=VISIBLE, width=768, height=1184, has-focus=true, has-focusable=true, 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=0.0, y=0.0, child-count=1}
|
+->ActionBarOverlayLayout{id=16909075, res-name=action_bar_overlay_layout, visibility=VISIBLE, width=768, height=1184, has-focus=true, has-focusable=true, has-window-focus=true, …
Run Code Online (Sandbox Code Playgroud)

java testing android android-actionbar android-espresso

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