在活动A上,我单击一个按钮并调用活动B。然后,如果活动B中的addressNickNameView在itemAddressNickNameView上相同,则我匹配
onView(withId(R.id.addressNickNameView))
.check(matches(withId(R.id.itemAddressNickNameView)))`
但是我面临这个问题。
android.support.test.espresso.base.DefaultFailureHandler $ AssertionFailedWithCauseError:'with id:2131363004'与所选视图不匹配。 预期值:id:br.com.fastshop.ecommerce.mock.teste:id / itemAddressNickNameView 得到了:“ TextInputEditText {id = 2131362631,res-name = component_fast_edittext_edit_text_cpf,可见性= VISIBLE,宽度= 998,高度= 72,has-focus = false...。
答案 0 :(得分:1)
我不认为Matcher在所有活动中都能像这样工作。您需要先从第一个活动中获取值,然后再进入第二个活动,例如:
@Rule
public ActivityTestRule<ActivityA> mActivityTestRule = new ActivityTestRule<>(ActivityA.class);
@Test
public void test() {
EditText editTextA = mActivityTestRule.getActivity().findViewById(R.id.itemAddressNickNameView);
String textA = editTextA.getText().toString();
// Move to Activity B
onView(R.id.button).perform(click());
onView(withId(R.id.addressNickNameView)).check(matches(withText(textA)));
}