How to use withText method of android.support.test.espresso.matcher.ViewMatchers class

Best Appium-espresso-driver code snippet using android.support.test.espresso.matcher.ViewMatchers.withText

FinalFullTest.kt

Source:FinalFullTest.kt Github

copy

Full Screen

...185 Espresso.onView(ViewMatchers.withId(R.id.main_Ranking))186 .perform(ViewActions.click())187 Thread.sleep(1000)188 Espresso.onView(ViewMatchers.withId(R.id.ranking_PlayerRanking))189 .check(matches(withText("Player Ranking")))190 Espresso.pressBack()191 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))192 .perform(ViewActions.click())193 Espresso.onView(ViewMatchers.withId(R.id.main_Bank))194 .perform(ViewActions.click())195 Espresso.onView(withId(R.id.bank_GOLDvalue))196 .check(matches(not(withText("0.0"))))197 Espresso.onView(ViewMatchers.withId(R.id.bank_GOLDvalue))198 .check(matches(withText("123.4")))199 Thread.sleep(500)200 Espresso.onData(anything())201 .inAdapterView(withId(R.id.bank_coinzGridView))202 .atPosition(0)203 .onChildView(withId(R.id.coinExchange))204 .perform(ViewActions.click())205 Thread.sleep(2000)206 Espresso.onView(ViewMatchers.withId(R.id.bank_GOLDvalue))207 .check(matches(not(withText("123.4"))))208 Espresso.onData(anything())209 .inAdapterView(withId(R.id.bank_coinzGridView))210 .atPosition(0)211 .onChildView(withId(R.id.coinExchange))212 .perform(ViewActions.click())213 Thread.sleep(500)214 Espresso.onData(anything())215 .inAdapterView(withId(R.id.bank_coinzGridView))216 .atPosition(0)217 .onChildView(withId(R.id.coinExchange))218 .perform(ViewActions.click())219 Thread.sleep(500)220 Espresso.onView(withId(R.id.bank_exchangedTextView))221 .check(matches(withText(containsString("back tomorrow to exchange"))))222 Espresso.onView(withId(R.id.bank_coinzGridView))223 .check(matches(withGridSize(3)))224 Espresso.onView(withId(R.id.bank_transferButton))225 .perform(ViewActions.click())226 Espresso.onView(withId(R.id.bank_transferEmail))227 .perform(ViewActions.replaceText("EspressoEmailFinal2@gmail.com"))228 Espresso.onData(anything())229 .inAdapterView(withId(R.id.bank_coinzGridView))230 .atPosition(0)231 .onChildView(withId(R.id.coinExchange))232 .perform(ViewActions.click())233 Espresso.onView(ViewMatchers.withId(R.id.bank_transferEmail))234 .check(matches(hasErrorText("You cannot transfer Coinz to yourself")))235 Espresso.onView(withId(R.id.bank_transferEmail))236 .perform(ViewActions.replaceText("JustTesting"))237 Espresso.onData(anything())238 .inAdapterView(withId(R.id.bank_coinzGridView))239 .atPosition(0)240 .onChildView(withId(R.id.coinExchange))241 .perform(ViewActions.click())242 Espresso.onView(ViewMatchers.withId(R.id.bank_transferEmail))243 .check(matches(hasErrorText("This email address is invalid")))244 Espresso.onView(withId(R.id.bank_transferEmail))245 .perform(ViewActions.replaceText("EspressoEmailFinal3@gmail.com"))246 Espresso.onData(anything())247 .inAdapterView(withId(R.id.bank_coinzGridView))248 .atPosition(0)249 .onChildView(withId(R.id.coinExchange))250 .perform(ViewActions.click())251 Thread.sleep(500)252 Espresso.onData(anything())253 .inAdapterView(withId(R.id.bank_coinzGridView))254 .atPosition(0)255 .onChildView(withId(R.id.coinExchange))256 .perform(ViewActions.click())257 Thread.sleep(500)258 Espresso.onData(anything())259 .inAdapterView(withId(R.id.bank_coinzGridView))260 .atPosition(0)261 .onChildView(withId(R.id.coinExchange))262 .perform(ViewActions.click())263 Thread.sleep(5000)264 Espresso.onView(withId(R.id.bank_coinzGridView))265 .check(matches(withGridSize(1)))266 Espresso.pressBack()267 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))268 .perform(ViewActions.click())269 Espresso.onView(ViewMatchers.withId(R.id.main_Race))270 .perform(ViewActions.click())271 Espresso.onView(ViewMatchers.withId(R.id.race_TimeSpinner))272 .perform(ViewActions.click())273 Espresso.onData(Matchers.hasToString(startsWith("30")))274 .perform(ViewActions.click())275 Espresso.onView(ViewMatchers.withId(R.id.race_WagerButton))276 .perform(ViewActions.click())277 Thread.sleep(2000)278 Espresso.onView(ViewMatchers.withId(R.id.main_WagerTextView))279 .check(matches(isDisplayed()))280 Espresso.onView(ViewMatchers.withId(R.id.main_WagerTextView))281 .check(matches(withText(startsWith("Time Left:"))))282 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))283 .perform(ViewActions.click())284 Espresso.onView(ViewMatchers.withId(R.id.main_Transfer))285 .perform(ViewActions.click())286 Espresso.onView(ViewMatchers.withId(R.id.transferHistory_TransferHistoryTextView))287 .check(matches(withText("Transfer History")))288 Espresso.pressBack()289 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))290 .perform(ViewActions.click())291 Espresso.onView(ViewMatchers.withId(R.id.main_Quest))292 .perform(ViewActions.click())293 Espresso.onData(anything())294 .inAdapterView(withId(R.id.quest_listView))295 .atPosition(0)296 .onChildView(withId(R.id.quest_rerollButton))297 .perform(ViewActions.click())298 Thread.sleep(500)299 Espresso.onData(anything())300 .inAdapterView(withId(R.id.quest_listView))301 .atPosition(0)302 .onChildView(withId(R.id.quest_rerollButton))303 .check(matches(Matchers.not(isEnabled())))304 Espresso.pressBack()305 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))306 .perform(ViewActions.click())307 Espresso.onView(ViewMatchers.withId(R.id.main_SignOut))308 .perform(ViewActions.click())309 Thread.sleep(500)310 Espresso.onView(ViewMatchers.withId(R.id.login_email))311 .perform(ViewActions.replaceText("EspressoEmailFinal2@gmail.com"))312 Espresso.onView(ViewMatchers.withId(R.id.login_password))313 .perform(ViewActions.replaceText("EspressoPasswordFinal2"))314 Espresso.onView(ViewMatchers.withId(R.id.email_sign_in_button))315 .perform(ViewActions.click())316 Thread.sleep(5000)317 Espresso.onView(ViewMatchers.withId(R.id.main_WagerTextView))318 .check(matches(isDisplayed()))319 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))320 .perform(ViewActions.click())321 Espresso.onView(ViewMatchers.withId(R.id.main_SignOut))322 .perform(ViewActions.click())323 Thread.sleep(500)324 Espresso.onView(ViewMatchers.withId(R.id.login_email))325 .perform(ViewActions.replaceText("EspressoEmailFinal3@gmail.com"))326 Espresso.onView(ViewMatchers.withId(R.id.login_password))327 .perform(ViewActions.replaceText("EspressoPasswordFinal3"))328 Espresso.onView(ViewMatchers.withId(R.id.email_sign_in_button))329 .perform(ViewActions.click())330 Thread.sleep(5000)331 Espresso.onView(ViewMatchers.withId(R.id.main_OpenMenu))332 .perform(ViewActions.click())333 Espresso.onView(ViewMatchers.withId(R.id.main_Transfer))334 .perform(ViewActions.click())335 Thread.sleep(500)336 Espresso.onView(ViewMatchers.withId(R.id.transferHistory_listView))337 .check(matches(withListSize(2)))338 Espresso.onData(anything())339 .inAdapterView(withId(R.id.transferHistory_listView))340 .atPosition(1)341 .onChildView(withId(R.id.transferHistory_DeleteButton))342 .perform(ViewActions.click())343 Thread.sleep(250)344 Espresso.onView(ViewMatchers.withId(R.id.transferHistory_listView))345 .check(matches(withListSize(1)))346 Espresso.onData(anything())347 .inAdapterView(withId(R.id.transferHistory_listView))348 .atPosition(0)349 .onChildView(withId(R.id.transferHistory_DeleteAllButton))350 .perform(ViewActions.click())351 Thread.sleep(250)352 Espresso.onView(ViewMatchers.withId(R.id.transferHistory_listView))353 .check(matches(withListSize(0)))354 Espresso.pressBack()355 Espresso.onView(withId(R.id.main_OpenMenu))356 .perform(ViewActions.click())357 Espresso.onView(withId(R.id.main_Bank))358 .perform(ViewActions.click())359 Espresso.onView(withId(R.id.bank_GOLDvalue))360 .check(matches(not(withText("567.8"))))361 Espresso.onView(withId(R.id.bank_GOLDvalue))362 .check(matches(not(withText("0.0"))))363 Espresso.pressBack()364 Espresso.onView(withId(R.id.main_OpenMenu))365 .perform(ViewActions.click())366 Espresso.onView(withId(R.id.main_SignOut))367 .perform(ViewActions.click())368 Thread.sleep(2500)369 }370}...

Full Screen

Full Screen

AddAccountCheckInformationFragmentTest.kt

Source:AddAccountCheckInformationFragmentTest.kt Github

copy

Full Screen

...8import android.support.test.espresso.matcher.ViewMatchers9import android.support.test.espresso.matcher.ViewMatchers.isDisplayed10import android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility11import android.support.test.espresso.matcher.ViewMatchers.withId12import android.support.test.espresso.matcher.ViewMatchers.withText13import android.support.test.rule.ActivityTestRule14import android.support.test.runner.AndroidJUnit415import io.crypto.bitstamp.BuildConfig.TEST_ACCOUNT_API_KEY16import io.crypto.bitstamp.BuildConfig.TEST_ACCOUNT_SECRET17import io.crypto.bitstamp.BuildConfig.TEST_ACCOUNT_USER_ID18import io.crypto.bitstamp.R19import io.crypto.bitstamp.activity.PricesActivity20import io.crypto.bitstamp.espresso.OkHttpIdlingResource21import io.crypto.bitstamp.network.BitstampServices22import org.assertj.core.api.Assertions.assertThat23import org.hamcrest.core.AllOf.allOf24import org.junit.After25import org.junit.Before26import org.junit.Rule27import org.junit.Test28import org.junit.runner.RunWith29@RunWith(AndroidJUnit4::class)30class AddAccountCheckInformationFragmentTest {31 @JvmField32 @Rule33 var activityRule = ActivityTestRule(PricesActivity::class.java)34 private lateinit var resource: OkHttpIdlingResource35 @Before36 fun before() {37 this.resource =38 OkHttpIdlingResource("OkHttp", BitstampServices.privateOkHttpClient.dispatcher())39 IdlingRegistry.getInstance().register(this.resource)40 }41 @Test42 fun back() {43 this.displayWrongCheckInformationSection()44 onView(withId(R.id.back)).perform(click())45 onView(withId(R.id.api_key)).check(matches(allOf(isDisplayed(), withText("api_key"))))46 onView(withId(R.id.secret)).check(matches(allOf(isDisplayed(), withText("secret"))))47 onView(withId(R.id.back)).perform(click())48 onView(withId(R.id.user_id)).check(matches(allOf(isDisplayed(), withText("user_id"))))49 }50 @Test51 fun newInstance() {52 val fragment = AddAccountCheckInformationFragment.newInstance()53 assertThat(fragment).isInstanceOf(AddAccountCheckInformationFragment::class.java)54 assertThat(fragment.arguments).isNull()55 }56 @Test57 fun correctInformation_loginNow() {58 this.checkCorrectInformation()59 onView(withId(R.id.login_now)).perform(click())60 onView(withText(R.string.balance)).check(matches(isDisplayed()))61 BitstampServices.account = null62 }63 @Test64 fun correctInformation_saveAccount() {65 this.checkCorrectInformation()66 onView(withId(R.id.save_account)).perform(click())67 onView(withId(R.id.add_account_save_account)).check(matches(isDisplayed()))68 onView(withId(R.id.back)).perform(click())69 onView(withId(R.id.add_account_check_information)).check(matches(isDisplayed()))70 onView(withId(R.id.back)).perform(click())71 onView(withId(R.id.api_key))72 .check(matches(allOf(isDisplayed(), withText(TEST_ACCOUNT_API_KEY))))73 onView(withId(R.id.secret))74 .check(matches(allOf(isDisplayed(), withText(TEST_ACCOUNT_SECRET))))75 onView(withId(R.id.back)).perform(click())76 onView(withId(R.id.user_id))77 .check(matches(allOf(isDisplayed(), withText(TEST_ACCOUNT_USER_ID))))78 }79 @Test80 fun wrongInformation() {81 this.displayWrongCheckInformationSection()82 onView(withId(R.id.login_now)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)))83 onView(withId(R.id.progress)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)))84 onView(withId(R.id.save_account)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)))85 onView(withId(R.id.status)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))86 onView(withId(R.id.status_text)).check(87 matches(88 allOf(89 withText("API key not found"),90 withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)91 )92 )93 )94 }95 @After96 fun after() {97 IdlingRegistry.getInstance().unregister(this.resource)98 }99 private fun checkCorrectInformation() {100 this.displayCorrectCheckInformationSection()101 onView(withId(R.id.login_now)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))102 onView(withId(R.id.progress)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)))103 onView(withId(R.id.save_account)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))...

Full Screen

Full Screen

BaseRobot.kt

Source:BaseRobot.kt Github

copy

Full Screen

...29 }30 }31 fun assertText(@IdRes id: Int, message: String): ViewInteraction =32 Espresso.onView(CoreMatchers.allOf(ViewMatchers.withId(id), ViewMatchers.isDisplayed()))33 .check(ViewAssertions.matches(ViewMatchers.withText(message)))34 fun componentInList(component: Matcher<View>, list: Matcher<View>, index: Int): ViewInteraction {35 return Espresso.onView(Matchers.allOf(component, ViewMatchers.isDescendantOfA(childAtPosition(list, index))))36 }37 fun componentInTagged(component: Matcher<View>, tagValue: Matcher<Any>): ViewInteraction {38 return Espresso.onView(Matchers.allOf(component, ViewMatchers.isDescendantOfA(ViewMatchers.withTagValue(tagValue))))39 }40 fun componentInTagged(component: Matcher<View>, key: Int, tagValue: Matcher<Any>): ViewInteraction {41 return Espresso.onView(Matchers.allOf(component, ViewMatchers.isDescendantOfA(ViewMatchers.withTagKey(key, tagValue))))42 }43 fun scrollTo(list: Matcher<View>, item: Matcher<View>) {44 Espresso.onView(list).perform(RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(item))45 }46 fun scrollTo(item: Matcher<View>) {47 scrollTo(ViewMatchers.withId(R.id.list), item)48 }49 fun scrollToPosition(list: Matcher<View>, position: Int) {50 Espresso.onView(list).perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(position))51 }52 fun scrollToPosition(position: Int) {53 scrollToPosition(ViewMatchers.withId(R.id.list), position)54 }55 fun getTextByTag(@IdRes id: Int, tag: String) = componentInTagged(ViewMatchers.withId(id), R.id.tag_test, Matchers.equalTo(tag))56 fun assertDialogText(title: Matcher<String>, message: Matcher<String>) {57 Espresso.onView(ViewMatchers.withId(R.id.md_title)).check(ViewAssertions.matches(ViewMatchers.withText(title)))58 Espresso.onView(ViewMatchers.withId(R.id.md_content)).check(ViewAssertions.matches(ViewMatchers.withText(message)))59 }60 fun assertDialogText(title: Int, message: Matcher<String>) {61 Espresso.onView(ViewMatchers.withId(R.id.md_title)).check(ViewAssertions.matches(ViewMatchers.withText(title)))62 Espresso.onView(ViewMatchers.withId(R.id.md_content)).check(ViewAssertions.matches(ViewMatchers.withText(message)))63 }64 fun assertDialogText(title: Int, message: Int) {65 Espresso.onView(ViewMatchers.withId(R.id.md_title)).check(ViewAssertions.matches(ViewMatchers.withText(title)))66 Espresso.onView(ViewMatchers.withId(R.id.md_content)).check(ViewAssertions.matches(ViewMatchers.withText(message)))67 }68 fun assertNeutralText(text: Matcher<String>) {69 Espresso.onView(ViewMatchers.withId(R.id.md_buttonDefaultNeutral)).check(ViewAssertions.matches(ViewMatchers.withText(text)))70 }71 fun assertNeutralNotVisible() {72 Espresso.onView(ViewMatchers.withId(R.id.md_buttonDefaultNeutral)).check(ViewAssertions.matches(Matchers.not(ViewMatchers.isDisplayed())))73 }74 fun clickDialogPositive() {75 clickButton(R.id.md_buttonDefaultPositive)76 }77 fun clickDialogNeutral() {78 clickButton(R.id.md_buttonDefaultNeutral)79 }80 fun clickDialogNegative() {81 clickButton(R.id.md_buttonDefaultNegative)82 }83 fun clickPromptCheckbox() {...

Full Screen

Full Screen

ViewMatchersTest.kt

Source:ViewMatchersTest.kt Github

copy

Full Screen

...34import android.support.test.espresso.matcher.ViewMatchers.withContentDescription35import android.support.test.espresso.matcher.ViewMatchers.withHint36import android.support.test.espresso.matcher.ViewMatchers.withId37import android.support.test.espresso.matcher.ViewMatchers.withParent38import android.support.test.espresso.matcher.ViewMatchers.withText39import org.hamcrest.CoreMatchers.allOf40import org.hamcrest.CoreMatchers.`is`41import org.hamcrest.CoreMatchers.not42/**43 * Lists all ViewMatchers. ViewMatchers here are without functional load.44 * This is done for demonstration purposes.45 */46@RunWith(AndroidJUnit4::class)47class ViewMatchersTest {48 @Test49 fun userProperties() {50 onView(withId(R.id.fab_add_task))51 onView(withText("All TO-DOs"))52 onView(withContentDescription(R.string.menu_filter))53 onView(hasContentDescription())54 onView(withHint(R.string.name_hint))55 }56 @Test57 fun uiProperties() {58 onView(isDisplayed())59 onView(isEnabled())60 onView(isChecked())61 onView(isSelected())62 }63 @Test64 fun objectMatcher() {65 onView(not<View>(isChecked()))66 onView(allOf<View>(withText("item 1"), isChecked()))67 }68 @Test69 fun hierarchy() {70 onView(withParent(withId(R.id.todo_item)))71 onView(withChild(withText("item 2")))72 onView(isDescendantOfA(withId(R.id.todo_item)))73 onView(hasDescendant(isChecked()))74 .check(matches(isDisplayed()))75 .check(matches(isFocusable()))76 onView(hasSibling(withContentDescription(R.string.menu_filter)))77 }78 @Test79 fun input() {80 onView(supportsInputMethods())81 onView(hasImeAction(EditorInfo.IME_ACTION_SEND))82 }83 @Test84 fun classMatchers() {85 onView(isAssignableFrom(CheckBox::class.java))86 onView(withClassName(`is`(FloatingActionButton::class.java.canonicalName)))87 }88 @Test89 fun rootMatchers() {90 onView(isFocusable())91 onView(withText(R.string.name_hint)).inRoot(isTouchable())92 onView(withText(R.string.name_hint)).inRoot(isDialog())93 onView(withText(R.string.name_hint)).inRoot(isPlatformPopup())94 }95 @Test96 fun preferenceMatchers() {97 onData(withSummaryText("3 days"))98 onData(withTitle(R.string.pref_title_send_notifications))99 onData(withKey("example_switch"))100 onView(isEnabled())101 }102 @Test103 fun layoutMatchers() {104 onView(hasEllipsizedText())105 onView(hasMultilineText())106 }107}...

Full Screen

Full Screen

HighscoreFragmentTest.kt

Source:HighscoreFragmentTest.kt Github

copy

Full Screen

2import android.support.test.espresso.Espresso.onView3import android.support.test.espresso.assertion.ViewAssertions.matches4import android.support.test.espresso.matcher.ViewMatchers5import android.support.test.espresso.matcher.ViewMatchers.isDisplayed6import android.support.test.espresso.matcher.ViewMatchers.withText7import android.support.test.rule.ActivityTestRule8import com.jakelaurie.colormemory.base.DBTest9import com.jakelaurie.colormemory.base.FragmentTestActivity10import com.jakelaurie.colormemory.model.Score11import com.jakelaurie.colormemory.ui.highscore.HighscoreFragment12import com.jakelaurie.colormemory.ui.highscore.HighscorePresenter13import com.jakelaurie.colormemory.ui.highscore.list.HighscoreAdapter14import org.junit.Rule15import org.junit.Test16class HighscoreFragmentTest: DBTest() {17 val fragment = HighscoreFragment()18 private val playerName = "test"19 private val playerScore = 10020 @get:Rule21 val rule = object : ActivityTestRule<FragmentTestActivity>(FragmentTestActivity::class.java) {22 override fun afterActivityLaunched() = runOnUiThread {23 activity.startFragment(fragment, this@HighscoreFragmentTest::inject)24 }25 }26 fun inject(fragment: HighscoreFragment) {27 initDb()28 val scoreDAO = db.scoreDao()29 val score = Score("$playerScore")30 score.score = playerScore31 score.playerName = playerName32 scoreDAO.addScore(score)33 fragment.presenter = HighscorePresenter(HighscoreAdapter(), scoreDAO)34 }35 /**36 * Test actionbar37 */38 @Test39 fun testActionbar() {40 onView(ViewMatchers.withId(R.id.highscoreActionbarTitle))41 .check(matches(ViewMatchers.isDisplayed()))42 .check(matches(ViewMatchers.withText("Top 10 high scores")))43 }44 /**45 * Test header and recycler visibility46 */47 @Test48 fun testHeader() {49 onView(ViewMatchers.withId(R.id.titleHighScoreRank))50 .check(matches(ViewMatchers.isDisplayed()))51 .check(matches(ViewMatchers.withText("Rank")))52 onView(ViewMatchers.withId(R.id.titleHighScoreName))53 .check(matches(ViewMatchers.isDisplayed()))54 .check(matches(ViewMatchers.withText("Name")))55 onView(ViewMatchers.withId(R.id.titleHighScoreScore))56 .check(matches(ViewMatchers.isDisplayed()))57 .check(matches(ViewMatchers.withText("Points")))58 }59 /**60 * Test the 'score' we put in the Db is actually shown in recycler61 */62 @Test63 fun testRecyclerContent() {64 onView(ViewMatchers.withId(R.id.highScoreRecyclerView))65 .check(matches(ViewMatchers.isDisplayed()))66 onView(withText("#1")).check(matches(isDisplayed()))67 onView(withText(playerName)).check(matches(isDisplayed()))68 onView(withText("$playerScore")).check(matches(isDisplayed()))69 }70}...

Full Screen

Full Screen

MainActivityTest.kt

Source:MainActivityTest.kt Github

copy

Full Screen

...6import android.support.test.espresso.assertion.ViewAssertions.matches7import android.support.test.espresso.matcher.ViewMatchers8import android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility9import android.support.test.espresso.matcher.ViewMatchers.withId10import android.support.test.espresso.matcher.ViewMatchers.withText11import android.support.test.rule.ActivityTestRule12import android.support.test.runner.AndroidJUnit413import org.junit.Rule14import org.junit.Test15import org.junit.runner.RunWith16/**17 * Instrumentation tests for [MainActivity].18 */19@RunWith(AndroidJUnit4::class)20class MainActivityTest {21 @get:Rule22 val activityRule = ActivityTestRule<MainActivity>(MainActivity::class.java)23 private val context = InstrumentationRegistry.getTargetContext()24 @Test25 fun whenActivityStarted_shouldCheckIfAllViewsAreVisible() {26 onView(withId(R.id.textView)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))27 onView(withId(R.id.image)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))28 }29 @Test30 fun whenOverflowButtonPressed_chooseGrayScaleItem() {31 Espresso.openActionBarOverflowOrOptionsMenu(context)32 onView(withText(context.resources.getString(R.string.action_gray_scale))).perform(click())33 }34 @Test35 fun whenOverflowButtonPressed_chooseGaussianBlurItem() {36 Espresso.openActionBarOverflowOrOptionsMenu(context)37 onView(withText(context.resources.getString(R.string.action_gaussian_blur))).perform(click())38 }39 @Test40 fun whenOverflowButtonPressed_chooseCannyEdgeItem() {41 Espresso.openActionBarOverflowOrOptionsMenu(context)42 onView(withText(context.resources.getString(R.string.action_canny))).perform(click())43 }44 @Test45 fun whenOverflowButtonPressed_chooseThresholdItem() {46 Espresso.openActionBarOverflowOrOptionsMenu(context)47 onView(withText(context.resources.getString(R.string.action_threshold))).perform(click())48 }49 @Test50 fun whenOverflowButtonPressed_chooseAdaptiveThresholdItem() {51 Espresso.openActionBarOverflowOrOptionsMenu(context)52 onView(withText(context.resources.getString(R.string.action_adaptive_threshold))).perform(click())53 }54 @Test55 fun whenOverflowButtonPressed_chooseResetItem() {56 val context = InstrumentationRegistry.getTargetContext()57 Espresso.openActionBarOverflowOrOptionsMenu(context)58 onView(withText(context.resources.getString(R.string.action_reset))).perform(click())59 }60}...

Full Screen

Full Screen

HeroesDetailActivityTest.kt

Source:HeroesDetailActivityTest.kt Github

copy

Full Screen

...6import android.support.test.espresso.assertion.ViewAssertions7import android.support.test.espresso.assertion.ViewAssertions.matches8import android.support.test.espresso.matcher.ViewMatchers9import android.support.test.espresso.matcher.ViewMatchers.withId10import android.support.test.espresso.matcher.ViewMatchers.withText11import android.support.test.rule.ActivityTestRule12import android.support.test.runner.AndroidJUnit413import com.dloprodu.marvelheroes.R14import com.dloprodu.marvelheroes.domain.model.MarvelHeroEntity15import com.dloprodu.marvelheroes.presentation.FakeData16import com.dloprodu.marvelheroes.presentation.heroedetail.MarvelHeroeDetailActivity17import org.junit.Test18import org.junit.runner.RunWith19/**20 * Created by dloprodu on 18/03/2018.21 */22@RunWith(AndroidJUnit4::class)23class HeroesDetailActivityTest {24 val activityTestRule = ActivityTestRule<MarvelHeroeDetailActivity>(MarvelHeroeDetailActivity::class.java, false, false)25 @Test26 fun testBasicInitialization() {27 activityTestRule.launchActivity(Intent())28 Espresso.onView(ViewMatchers.withText(R.string.app_name)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))29 }30 @Test31 fun testDataIsLoadedSuccessfully() {32 val intent = Intent(33 InstrumentationRegistry.getTargetContext(),34 MarvelHeroeDetailActivity::class.java35 ).apply {36 putExtra(MarvelHeroeDetailActivity.PARAM_HEROE, FakeData.IRON_MAN)37 }38 activityTestRule.launchActivity(intent)39 onView(withId(R.id.heroDetailName)).check(matches(withText(FakeData.NAME)))40 onView(withId(R.id.heroDetailRealName)).check(matches(withText(FakeData.REAL_NAME)))41 onView(withId(R.id.heroDetailHeight)).check(matches(withText(FakeData.HEIGHT)))42 onView(withId(R.id.heroDetailPower)).check(matches(withText(FakeData.POWER)))43 onView(withId(R.id.heroDetailAbilities)).check(matches(withText(FakeData.ABILITIES)))44 }45}...

Full Screen

Full Screen

SearchActivityInstrumentedTest.kt

Source:SearchActivityInstrumentedTest.kt Github

copy

Full Screen

...5import android.support.test.espresso.Espresso.onView6import android.support.test.espresso.assertion.ViewAssertions.matches7import android.support.test.espresso.matcher.ViewMatchers8import android.support.test.espresso.matcher.ViewMatchers.withId9import android.support.test.espresso.matcher.ViewMatchers.withText10import android.support.test.rule.ActivityTestRule11import com.example.sky.helper.TestUtils12import com.example.sky.search.SearchActivity13import org.junit.Rule14import android.support.test.espresso.matcher.ViewMatchers.withParent15import android.widget.TextView16import junit.framework.Assert.assertEquals17import org.hamcrest.CoreMatchers.allOf18import org.hamcrest.CoreMatchers.instanceOf19@RunWith(AndroidJUnit4::class)20class SearchActivityInstrumentedTest {21 @Suppress("unused") // actually used by Espresso22 @get:Rule23 val activityRule = ActivityTestRule<SearchActivity>(SearchActivity::class.java)24 @Test25 fun toolbarShouldBeShown() {26 onView(withText("Edinburgh - London")).check(matches(ViewMatchers.isDisplayed()))27 onView(withText("19 Feb - 20 Feb, 1 adult, Economy")).check(matches(ViewMatchers.isDisplayed()))28 }29}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful