Tôi muốn nhấn nút dưới đây bằng cách sử dụng Espresso, nhưng tôi không chắc chắn như thế nào. Tôi có nên lấy tài nguyên-id không? Hoặc làm thế nào để thiết lập một ID cho AlertDialog ??Làm thế nào để sử dụng espresso để nhấn một nút AlertDialog
@RunWith(AndroidJUnit4.class)
public class ApplicationTest {
@Rule
public ActivityTestRule<LoadingActivity> mActivityRule =
new ActivityTestRule<>(LoadingActivity.class);
@Test
public void loginClickMarker() {
//Doesn't work:
onView(withText("GA NAAR INSTELLINGEN")).perform(click());
}
}
public class PopupDialog {
public static void showGPSIsDisabled(Context context, String msg, final PopupDialogCallback popupDialogCallback) {
new AlertDialog.Builder(context)
.setTitle(context.getString(R.string.location_turned_off))
.setMessage(msg)
.setPositiveButton(context.getString(R.string.go_to_settings), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
popupDialogCallback.hasClicked();
}
}).show();
}
}
android.support.test.espresso.NoMatchingViewException: Không có quan điểm trong phân cấp trùng khớp với: với văn bản: là "GA Naar INSTELLINGEN"
Tôi nghĩ bạn có thể sử dụng phương thức withText() thay vì khớp với id – jeprubio
onView (withText ("GA NAAR INSTELLINGEN")). (Thực hiện (click()); không hoạt động –