2017-04-13 3 views
1

アプリのUIをテストするためにEspressoを使用するアンドロイドテストテストがいくつかあります。私は、最近失敗し始めたことに気付きました。その理由は意味をなさないようです。Androidエスプレッソ.inRoot(isDialog())間違ったルートを選択

EditTextのパスワードをとるAlertDialogが起動します。テストの開始は次のようになります。

// click the icon that launches the dialog 
    onView(withId(R.id.action)) 
      .perform(click()) 

    onView(withText("Enter Password")) 
      .inRoot(isDialog()) 
      .check(matches(isDisplayed())) 

    onView(withId(R.id.passwordInput)) 
      .inRoot(isDialog()) 
      .perform(typeText("test password")) 

    onView(withText("Ok")) 
      .inRoot(isDialog()) 
      .perform(click()) 

    ... 

このテストでは、ダイアログが開き、テキストを入力します。それは(あなたがそれらのサイズに基づいて、違いを見分けることができます)の代わりに焦点ダイアログウィンドウの非集中アクティビティウィンドウを選択しているように見えます

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{[email protected], [email protected], has-window-focus=false, layout-params-type=1, layout-params-string=WM.LayoutParams{(0,0)(fillxfill) ty=1 fl=#81810100 wanim=0x103045b needsMenuKey=2}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=1080, height=1920, has-focus=true, has-focusable=true, has-window-focus=false, 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=3}} 
. All Roots: 
Root{[email protected], [email protected], has-window-focus=true, layout-params-type=2, layout-params-string=WM.LayoutParams{(0,0)(wrapxwrap) gr=#11 sim=#20 ty=2 fl=#1800002 fmt=-3 wanim=0x103045c needsMenuKey=2}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=1026, height=468, 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}} 
Root{[email protected], [email protected], has-window-focus=false, layout-params-type=1, layout-params-string=WM.LayoutParams{(0,0)(fillxfill) ty=1 fl=#81810100 wanim=0x103045b needsMenuKey=2}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=1080, height=1920, has-focus=true, has-focusable=true, has-window-focus=false, 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=3}} 

:それは、その後で、「OK」ボタンを見つけようとして失敗しました。最初の2つの.inRootコールが正しいウィンドウを見つけたので、これは意味をなさない。

ルート選択のドキュメントがかなりスリムであるため、なぜこれが動作しないのか分かりませんが、これはバグですか?

答えて

0

私はエスプレッソの専門家ではありません。あなたのコードを見直すのは遠いですが、のinRoot呼び出しがあなたのコードで過度に使用されていると思われます。 inRootメソッドの仕様では、「与えられたルートマッチャーによって選択されたルートにスコープされた相互作用を変更/作成する」ことを意図しています。あなたはそれがあなたのダイアログコンテキストでアクションを実行していることを確認するためにそれを使用しているようです。だから、おそらく最後のプリフォームメソッド呼び出しは、適切なビューを対象としていない可能性があります。それが役に立つと願っています。

+0

問題は、 'inRoot'呼び出しがなければ、要素が見つからないということです。 – bj0

+0

AndroidデバイスモニタでHierarchy Viewを分析しようとしましたか? – utom

関連する問題