我正在为“注册”屏幕编写一个带有espresso的测试用例,我的屏幕上有一个字段,当用户点击从给定列表中选择建议的位置后,当用户点击打开另一个包含Google自动完成编辑文本的活动(即LocationActivity)用户导航回到“注册”屏幕,并根据他/她的选择邮政编码,填写郊区和州,并且用户必须点击“提交”按钮才能点击API。
以下是有关我的测试的代码:
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.ansible.racq.Activity.RegisterDetailActivity;
import com.ansible.racq.Util.Constants;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.matcher.RootMatchers.withDecorView;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
@LargeTest
@RunWith(AndroidJUnit4.class)
public class RegisterDetailActivityTest {
private String mFirstname, mLastname,mLearnerLicenseNumber,mMobileNumber,mStreetAddress;
@Rule
public ActivityTestRule<RegisterDetailActivity> mActivityTestRule = new ActivityTestRule<>(RegisterDetailActivity.class);
@Before
public void prepareData() {
mFirstname = "siddharth";
mLastname = "khindri";
mLearnerLicenseNumber="123456789";
mMobileNumber="8600032384";
mStreetAddress="sebiz square master software solutions";
}
@Test
public void registerDetailActivityTest() {
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try {
onView(withId(R.id.et_first_name)).perform(typeText(mFirstname), closeSoftKeyboard());
onView(withId(R.id.et_last_name)).perform(typeText(mLastname), closeSoftKeyboard());
onView(withId(R.id.et_learner_number)).perform(typeText(mLearnerLicenseNumber), closeSoftKeyboard());
onView(withId(R.id.et_mobile_number)).perform(typeText(mMobileNumber), closeSoftKeyboard());
onView(withId(R.id.et_street)).perform(typeText(mStreetAddress), closeSoftKeyboard());
onView(withId(R.id.et_suburb)).perform(click());
Thread.sleep(Constants.ONE_SEC_DELAY);
onView(withId(R.id.et_search_location))
.perform(typeText("canberra"), closeSoftKeyboard());
onView(withText("canberra ACT"))
.inRoot(withDecorView(not(is(mActivityTestRule.getActivity().getWindow().getDecorView()))))
.perform(click());
Thread.sleep(Constants.THREE_SEC_DELAY);
onView(withId(R.id.btn_register)).perform(click());
} catch (Exception e) {
e.printStackTrace();
}
}
}
我的问题是,每当用户导航到Google自动完成屏幕时,应用程序都会通过“测试通过”通知关闭,如何使应用程序返回注册屏幕并点击“注册”按钮?
有人可以帮我吗?
致谢