Last active
January 30, 2018 09:50
-
-
Save AjeshRPai/8cf80f51fb944ffd20b1d2ae859436ef to your computer and use it in GitHub Desktop.
This is the MainActivity Intstrumentation Test Class
This file contains hidden or 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
| import android.support.test.rule.ActivityTestRule | |
| import android.support.test.runner.AndroidJUnit4 | |
| import org.junit.runner.RunWith | |
| import android.support.test.espresso.Espresso; | |
| import android.support.test.espresso.action.ViewActions | |
| import android.support.test.espresso.assertion.ViewAssertions.matches | |
| import android.support.test.espresso.matcher.ViewMatchers.* | |
| @RunWith(AndroidJUnit4::class) | |
| class MainActivityInstrumentationTest { | |
| @Rule | |
| @JvmField | |
| public val rule = ActivityTestRule(MainActivity::class.java) | |
| private val username_tobe_typed="Ajesh" | |
| private val correct_password ="password" | |
| private val wrong_password = "passme123" | |
| @Test | |
| fun login_success(){ | |
| Log.e("@Test","Performing login success test") | |
| Espresso.onView((withId(R.id.user_name))) | |
| .perform(ViewActions.typeText(username_tobe_typed)) | |
| Espresso.onView(withId(R.id.password)) | |
| .perform(ViewActions.typeText(correct_password)) | |
| Espresso.onView(withId(R.id.login_button)) | |
| .perform(ViewActions.click()) | |
| Espresso.onView(withId(R.id.login_result)) | |
| .check(matches(withText(R.string.login_success))) | |
| } | |
| @Test | |
| fun login_failure(){ | |
| Log.e("@Test","Performing login failure test") | |
| Espresso.onView((withId(R.id.user_name))) | |
| .perform(ViewActions.typeText(username_tobe_typed)) | |
| Espresso.onView(withId(R.id.password)) | |
| .perform(ViewActions.typeText(wrong_password)) | |
| Espresso.onView(withId(R.id.login_button)) | |
| .perform(ViewActions.click()) | |
| Espresso.onView(withId(R.id.login_result)) | |
| .check(matches(withText(R.string.login_failed))) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment