gpt4 book ai didi

android - Espresso - 检查使用按下按钮的 Intent 打开了哪个 Activity ?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:07:15 25 4
gpt4 key购买 nike

是否可以跟踪按下某个按钮后打开了哪个 Activity?
我有一个测试,单击/按下按钮时,它向服务器发送请求。在发送请求之前,它会打开一个 Activity 为了验证测试是否成功执行,我需要检查打开的 Activity 是什么。

我的测试示例:

检查在 Espresso 中打开了哪个 Intent ---

 private void startTest() {
recreateAuthData(InstrumentationRegistry.getTargetContext(), "d78269d9-9e00-4b8d-9242-815204b0a2f6", "3f32da21-914d-4adc-b6a1-891b842a2972");

InstrumentationRegistry.getTargetContext().getSharedPreferences(ActivitySplashScreen.class.getSimpleName(),
Context.MODE_PRIVATE).edit().putInt(ActivitySplashScreen.PROPERTY_APP_VERSION, ActivitySplashScreen.getAppVersion(InstrumentationRegistry.getTargetContext())).commit();
InstrumentationRegistry.getTargetContext().getSharedPreferences(ActivitySplashScreen.class.getSimpleName(),
Context.MODE_PRIVATE).edit().putString(ActivitySplashScreen.PROPERTY_REG_ID, "testKey").commit();

mActivityRule.launchActivity(setIntent());
// inputPinCode("2794");
}

@Test
public void testIdent() {
startTest();
onView(withText("ПРО")).perform(click());
putDelay(500);
onView(withId(R.id.get_pro)).perform(click());
onView(withText("Авторизация по паспортным данным")).perform(click());
putDelay(500);
closeSoftKeyboard();
onView(withId(R.id.btn_goto_passport)).perform(click());
onView(withHint("Серия и номер паспорта")).perform(replaceText("9894657891"));
onView(withHint("Дата выдачи паспорта")).perform(replaceText("17032014"));
onView(withHint("Дата рождения")).perform(replaceText("31091994"));
onView(withHint("СНИЛС")).perform(replaceText("54665285919"));
putDelay(500);
Log.d("TestWidget", hasComponent(hasShortClassName("ActivityMain")).toString());
onView(withId(R.id.btn_next)).perform(click());
// some code which check which activity is display now
putDelay(500);

}

最佳答案

要将开始的 Activity 与 Espresso Intent 实际匹配,您需要检查新 Intent 的组件:

intended(hasComponent(NewActivity.class.getName()));

确保在设置中调用 Intents.init() 并在拆卸中调用 Intents.release() 以便能够使用 Espresso 记录 Intent 。

关于android - Espresso - 检查使用按下按钮的 Intent 打开了哪个 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39250754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com