Created
September 19, 2016 09:05
-
-
Save Ansh1234/7e2b89ba2bbde355eb94546cbeb40539 to your computer and use it in GitHub Desktop.
UI Testing class for LoginActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LoginActivityTest { | |
@Rule | |
public ActivityTestRule mActivityRule = new ActivityTestRule(LoginActivity.class); | |
private Resources resources; | |
@Before | |
public void init() { | |
resources = mActivityRule.getActivity().getResources(); | |
} | |
@Test | |
public void testSuccessfulLOGIN() { | |
//Find a view with id user_name and type "Chandler" on that view. | |
onView(withId(R.id.user_name)).perform(typeText("Chandler")); | |
//Find a view with has hint Password and type "sarcasm" as password. | |
onView(withHint("Password")).perform(typeText("sarcasm")); | |
//Close the keyword, otherwise LoginButton won't be visible to Espresso and it will throw an | |
// exception. | |
closeSoftKeyboard(); | |
//Find the LOGIN button and perform click(). | |
onView(allOf(withText("LOGIN"), isDescendantOfA(withId(R.id.linear_layout)))) | |
.perform(click()); | |
//Assert that the textView of LOGIN TextView has been changed to Success. | |
String loginTxt = resources.getString(R.string.login_success); | |
onView(allOf(withId(R.id.login_result))).check | |
(matches(withText(loginTxt))); | |
} | |
@Test | |
public void testFailedLOGIN() { | |
//Find a view with id user_name and type "Ross" on that view. | |
onView(withId(R.id.user_name)).perform(typeText("Ross")); | |
//Find a view with has hint Password and type "marriage" as password. | |
onView(withHint("Password")).perform(typeText("marriage")); | |
//Close the keyword, otherwise LoginButton won't be visible to Espresso and it will throw an | |
// exception. | |
closeSoftKeyboard(); | |
//Find the LOGIN button and perform click(). | |
onView(allOf(withText("LOGIN"), isDescendantOfA(withId(R.id.linear_layout)))) | |
.perform(click()); | |
//Assert that the textView of LOGIN TextView has been changed to Success. | |
String loginTxt = resources.getString(R.string.login_failure); | |
onView(allOf(withId(R.id.login_result))).check | |
(matches(withText(loginTxt))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment