Issue
I have:
onView(withId(R.id.login_email_textview)).perform(clearText(), closeSoftKeyboard());
onView(withId(R.id.password_edittext)).perform(clearText(), closeSoftKeyboard());
onView(withId(R.id.login_email_textview)).perform(typeText(email), closeSoftKeyboard());
onView(withId(R.id.password_edittext)).perform(typeText(password), closeSoftKeyboard());
onView(withId(R.id.email_sign_in_button)).perform(click());
intended(hasComponent(new ComponentName(getTargetContext(), MainActivity.class)));
After the login button is pressed a Loading dialog shows up and Async task calls the server to check the credentials. After response the LoginActivity, witch I'm testing called finish() and MainActivity is started.
The test hangs after the login button is pressed. Also using:
@Rule
public IntentsTestRule<LoginActivity> mActivityRule = new IntentsTestRule<>(LoginActivity.class);
Also in my code after I/m calling startActivity(), I'm calling finish() on the LoginActivity.
On sign_in_button I'm calling Volley request.
Solution
How to fix your issue
I assume, that the LoadingDialog is showing an animated ProgressBar.
Using a ProgressBar and Volley together is actually not a bad idea. The ProgressBar will force Espresso to wait until Volley has finished its work in the background.
I assume, that your tests "hang" because you do not dismiss the LoadingDialog. So, to fix the issue, dismiss the LoadingDialog when you receive the response from Volley. But do not use Espresso to dismiss the LoadingDialog.
More Information
There are "known issues" when using ProgressBar and Volley individually:
Issues with ProgressBar
If the LoadingDialog shows an animated ProgressBar, the animation blocks Espresso. The animation keeps the app's main thread busy and Espresso waits until it times out.
Issues with Volley
Espresso does not know about Volley. If Volley executes requests in a background thread (I hope it does), Espresso does not wait, and your test will probably end before Volley returns a response.
An IdlingResource can be used to make Espresso wait for anything.
Answered By - thaussma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.