Cucumber-JVMとEspressoを使用してAndroid UIテストスイートを実行しています。しかし、私は対話の断片と対話することに問題に直面しています。isDialog()がEspressoのダイアログフラグメントと一致しません
もう1つのフラグメントは、いくつかのビュー要素を含むダイアログフラグメントを上に作成します。私がチェック/これらと対話しようとすると、エスプレッソはビューの階層内でエスプレッソを見つけられないようです。エラーメッセージに表示されるビュー階層は、ダイアログフラグメントではなく、根底にあるフラグメントのビュー階層であり、誤ったルートビューを取得していると考えられます。この問題を解決しようとする
は、私は、ステートメントにinRoot(isDialogを())を追加しました:
onView(withText("Ok")).inRoot(isDialog()).check(matches(isDisplayed()));
これは、結果、次のエラーメッセージ
android.support.test.espresso.NoMatchingRootException: Matcher 'is dialog' did not match any of the following roots: [Root{[email protected], [email protected], has-window-focus=true, layout-params-type=1, layout-params-string=WM.LayoutParams{(0,0)(fillxfill) sim=#20 ty=1 fl=#1810100 wanim=0x10303e5 needsMenuKey=2}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=1080, height=1794, 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) sim=#20 ty=1 fl=#1810100 wanim=0x10303e5 needsMenuKey=2}, decor-view-string=DecorView{id=-1, visibility=INVISIBLE, width=1080, height=1794, has-focus=true, 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, 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=#1810100 wanim=0x10303e5 needsMenuKey=2}, decor-view-string=DecorView{id=-1, visibility=INVISIBLE, width=1080, height=1794, has-focus=true, 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, 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=#1810100 wanim=0x10303e5 needsMenuKey=2}, decor-view-string=DecorView{id=-1, visibility=INVISIBLE, width=1080, height=1794, 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, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}}]
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:580)
ダイアログを作成するためのコード:
public class ServiceItemFragment extends Fragment {
...
public void showASampleDialog() {
DialogFragment newFragment = SampleDialogFragment.newInstance(
R.string.dialog_title);
newFragment.show(getFragmentManager(), "dialog");
}
}
ダイアログフラグメントのコード:
この問題を解決しようとするpublic class SampleDialogFragment extends DialogFragment {
public static SampleDialogFragment newInstance(int title) {
SampleDialogFragment frag = new SampleDialogFragment();
Bundle args = new Bundle();
args.putInt("title", title);
frag.setArguments(args);
return frag;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
int title = getArguments().getInt("title");
return new AlertDialog.Builder(getActivity())
.setTitle(title)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.i(getClass().getSimpleName(), "Positive click");
}
}
)
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.i(getClass().getSimpleName(), "Negative click");
}
}
)
.create();
}
}
当面はUIAutomatorの問題を回避しています: UiDeviceデバイス= UiDevice.getInstance(getInstrumentation());UiObject uiObject = device.findObject(new UiSelector()。text( "Ok")); { uiObject.click(); } catch(UiObjectNotFoundException e){ throw new RuntimeException( "UIオブジェクトが見つかりません"、e); } – slarbu