How to use onData method of android.support.test.espresso.Espresso class

Best Appium-espresso-driver code snippet using android.support.test.espresso.Espresso.onData

FinalFullTest.kt

Source:FinalFullTest.kt Github

copy

Full Screen

...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"))))...

Full Screen

Full Screen

WebViewTest.kt

Source:WebViewTest.kt Github

copy

Full Screen

1package com.example.android.architecture.blueprints.todoapp.test.chapter62import android.preference.PreferenceActivity3import android.support.test.espresso.Espresso.onData4import android.support.test.espresso.Espresso.onView5import android.support.test.espresso.action.ViewActions6import android.support.test.espresso.action.ViewActions.click7import android.support.test.espresso.matcher.ViewMatchers.withId8import android.support.test.espresso.matcher.ViewMatchers.withText9import android.support.test.espresso.web.assertion.WebViewAssertions.webMatches10import android.support.test.espresso.web.sugar.Web.onWebView11import android.support.test.espresso.web.webdriver.DriverAtoms.*12import android.support.test.espresso.web.webdriver.Locator13import android.view.KeyEvent14import com.example.android.architecture.blueprints.todoapp.R15import com.example.android.architecture.blueprints.todoapp.test.BaseTest16import com.example.android.architecture.blueprints.todoapp.test.chapter3.click17import com.example.android.architecture.blueprints.todoapp.test.chapter3.sleepAndPressKey18import com.example.android.architecture.blueprints.todoapp.test.helpers.CommonElements.openDrawer19import org.hamcrest.CoreMatchers.*20import org.junit.Test21/**22 * Contains tests for a WebView pages inside the TO-DO sample app.23 */24class WebViewTest : BaseTest() {25 @Test26 fun updatesLabelAndOpensNewPage() {27 openDrawer()28 onView(allOf(withId(R.id.design_menu_item_text),29 withText(R.string.settings_title))).perform(click())30 onData(instanceOf(PreferenceActivity.Header::class.java))31 .inAdapterView(withId(android.R.id.list))32 .atPosition(3)33 .perform(click())34 onWebView()35 .forceJavascriptEnabled()36 // Find edit text and type text.37 .withElement(findElement(Locator.ID, "text_input"))38 .perform(webKeys("Espresso WebView testing"))39 // Find button by id and click.40 .withElement(findElement(Locator.ID, "submit_btn"))41 .perform(webClick())42 // Find element by id and check its text.43 .withElement(findElement(Locator.ID, "response"))44 .check(webMatches(getText(), equalTo("Espresso+WebView+testing")))45 }46 @Test47 fun selectsRadioButtonWithCss() {48 openDrawer()49 onView(allOf(withId(R.id.design_menu_item_text),50 withText(R.string.settings_title))).perform(click())51 onData(instanceOf(PreferenceActivity.Header::class.java))52 .inAdapterView(withId(android.R.id.list))53 .atPosition(3)54 .perform(click())55 onWebView()56 // Find radio button by CSS.57 .withElement(findElement(Locator.CSS_SELECTOR, "input[value=\"rb1\"]"))58 .perform(webClick())59 }60 @Test61 fun findsElementsByXpath() {62 openDrawer()63 onView(allOf(withId(R.id.design_menu_item_text),64 withText(R.string.settings_title))).perform(click())65 onData(instanceOf(PreferenceActivity.Header::class.java))66 .inAdapterView(withId(android.R.id.list))67 .atPosition(3)68 .perform(click())69 onWebView()70 // Find label XPATH and check its text.71 .withElement(findElement(Locator.XPATH, "//label[@id=\"selection_result\"]"))72 .perform(webScrollIntoView())73 .check(webMatches(getText(), equalTo("Select option")))74 }75 @Test76 fun opensModal() {77 openDrawer()78 onView(allOf(withId(R.id.design_menu_item_text),79 withText(R.string.settings_title))).perform(click())80 onData(instanceOf(PreferenceActivity.Header::class.java))81 .inAdapterView(withId(android.R.id.list))82 .atPosition(3)83 .perform(click())84 onWebView()85 // Find button and click.86 .withElement(findElement(Locator.ID, "updateDetails"))87 .perform(webClick())88 // Find edit text field and input text in the popped up dialog.89 .withElement(findElement(Locator.ID, "modal_text_input"))90 .perform(webKeys("Text from modal"))91 // Find and click Confirm button.92 .withElement(findElement(Locator.ID, "confirm"))93 .perform(webClick())94 // Verify text from modal is set in label.95 .withElement(findElement(Locator.ID, "modal_message"))96 .check(webMatches(getText(), equalTo("Text from modal")))97 }98 /**99 * This test should fail intentionally.100 */101 @Test102 fun failsToClickSelectDropDown() {103 openDrawer()104 onView(allOf(withId(R.id.design_menu_item_text),105 withText(R.string.settings_title))).perform(click())106 onData(instanceOf(PreferenceActivity.Header::class.java))107 .inAdapterView(withId(android.R.id.list))108 .atPosition(3)109 .perform(click())110 onWebView()111 // Supposed to click on select.112 .withElement(findElement(Locator.ID, "selection_id"))113 .perform(webClick())114 // Select list is not shown, so test fails.115 .withElement(findElement(Locator.ID, "selection_result"))116 .check(webMatches(getText(), equalTo("Item 3")))117 }118 @Test119 fun verifiesSelectDropDown() {120 openDrawer()121 onView(allOf(withId(R.id.design_menu_item_text),122 withText(R.string.settings_title))).perform(click())123 onData(instanceOf(PreferenceActivity.Header::class.java))124 .inAdapterView(withId(android.R.id.list))125 .atPosition(3)126 .perform(click())127 onView(withId(R.id.web_view))128 // Send TAB keys as many times as needed to reach the "select".129 .sleepAndPressKey(KeyEvent.KEYCODE_TAB, 500, 6)130 // Send SPACE key to expand "select".131 .perform(ViewActions.pressKey(KeyEvent.KEYCODE_SPACE))132 /**133 * At this point android platform popup is shown.134 * Use Espresso native methods to select item from the list.135 */136 onView(withText("Item 3")).click()137 onWebView()138 // Check that text from select list is set into the label.139 .withElement(findElement(Locator.ID, "selection_result"))140 .check(webMatches(getText(), equalTo("Item 3")))141 }142 @Test143 fun showsOtherLocatorsSample() {144 openDrawer()145 onView(allOf(withId(R.id.design_menu_item_text),146 withText(R.string.settings_title))).perform(click())147 onData(instanceOf(PreferenceActivity.Header::class.java))148 .inAdapterView(withId(android.R.id.list))149 .atPosition(3)150 .perform(click())151 onWebView()152 // Find element by Locator.NAME153 .withElement(findElement(Locator.NAME, "text_input"))154 .perform(webScrollIntoView())155 // Find element by Locator.LINK_TEXT156 .withElement(findElement(Locator.LINK_TEXT, "Espresso Web."))157 .perform(webScrollIntoView())158 // Find element by Locator.PARTIAL_LINK_TEXT159 .withElement(findElement(Locator.PARTIAL_LINK_TEXT, "Espresso"))160 .perform(webScrollIntoView())161 // Find element by Locator.CLASS_NAME...

Full Screen

Full Screen

ViewMatchersTest.kt

Source:ViewMatchersTest.kt Github

copy

Full Screen

...5import android.widget.CheckBox6import com.example.android.architecture.blueprints.todoapp.R7import org.junit.Test8import org.junit.runner.RunWith9import android.support.test.espresso.Espresso.onData10import android.support.test.espresso.Espresso.onView11import android.support.test.espresso.assertion.ViewAssertions.matches12import android.support.test.espresso.matcher.LayoutMatchers.hasEllipsizedText13import android.support.test.espresso.matcher.LayoutMatchers.hasMultilineText14import android.support.test.espresso.matcher.PreferenceMatchers.withKey15import android.support.test.espresso.matcher.PreferenceMatchers.withSummaryText16import android.support.test.espresso.matcher.PreferenceMatchers.withTitle17import android.support.test.espresso.matcher.RootMatchers.isDialog18import android.support.test.espresso.matcher.RootMatchers.isPlatformPopup19import android.support.test.espresso.matcher.RootMatchers.isTouchable20import android.support.test.espresso.matcher.ViewMatchers.hasContentDescription21import android.support.test.espresso.matcher.ViewMatchers.hasDescendant22import android.support.test.espresso.matcher.ViewMatchers.hasImeAction23import android.support.test.espresso.matcher.ViewMatchers.hasSibling24import android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom25import android.support.test.espresso.matcher.ViewMatchers.isChecked26import android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA27import android.support.test.espresso.matcher.ViewMatchers.isDisplayed28import android.support.test.espresso.matcher.ViewMatchers.isEnabled29import android.support.test.espresso.matcher.ViewMatchers.isFocusable30import android.support.test.espresso.matcher.ViewMatchers.isSelected31import android.support.test.espresso.matcher.ViewMatchers.supportsInputMethods32import android.support.test.espresso.matcher.ViewMatchers.withChild33import android.support.test.espresso.matcher.ViewMatchers.withClassName34import 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

EspressoUiAutomatorTest.kt

Source:EspressoUiAutomatorTest.kt Github

copy

Full Screen

1package com.example.android.architecture.blueprints.todoapp.test.chapter82import android.preference.PreferenceActivity3import android.support.test.InstrumentationRegistry4import android.support.test.espresso.Espresso.onData5import android.support.test.espresso.Espresso.onView6import android.support.test.espresso.action.ViewActions.click7import android.support.test.espresso.assertion.ViewAssertions.matches8import android.support.test.espresso.matcher.PreferenceMatchers.withKey9import android.support.test.espresso.matcher.ViewMatchers.*10import android.support.test.rule.ActivityTestRule11import android.support.test.runner.AndroidJUnit412import android.support.test.uiautomator.By13import android.support.test.uiautomator.UiDevice14import android.support.test.uiautomator.Until15import com.example.android.architecture.blueprints.todoapp.R16import com.example.android.architecture.blueprints.todoapp.tasks.TasksActivity17import com.example.android.architecture.blueprints.todoapp.test.helpers.CommonElements.openDrawer18import org.hamcrest.CoreMatchers19import org.hamcrest.CoreMatchers.allOf20import org.junit.Rule21import org.junit.Test22import org.junit.runner.RunWith23/**24 * Contains tests that use both Espresso and UI Automator API.25 */26@RunWith(AndroidJUnit4::class)27class EspressoUiAutomatorTest {28 private val instrumentation = InstrumentationRegistry.getInstrumentation()29 private val uiDevice: UiDevice = UiDevice.getInstance(instrumentation)30 private val twoSeconds = 2000L31 @get:Rule32 var activityTestRule = ActivityTestRule(TasksActivity::class.java)33 /**34 * Clicks notification triggered by application under test and35 * verifies that TasksActivity is shown.36 */37 @Test38 fun clickNotificationOpensTasksActivity() {39 openDrawer()40 onView(allOf(withId(R.id.design_menu_item_text),41 withText(R.string.settings_title))).perform(click())42 onData(CoreMatchers.instanceOf(PreferenceActivity.Header::class.java))43 .inAdapterView(withId(android.R.id.list))44 .atPosition(1)45 .onChildView(withId(android.R.id.title))46 .check(matches(withText("Notifications")))47 .perform(click())48 // Click on Send notification item.49 onData(withKey("notifications_send"))50 .inAdapterView(allOf(51 withId(android.R.id.list),52 withParent(withId(android.R.id.list_container))))53 .check(matches(isDisplayed()))54 .perform(click())55 // Perform UI Automator actions.56 uiDevice.openNotification()57 // Click notification by text and wait for application to appear.58 uiDevice.findObject(By.text("My notification"))59 .clickAndWait(Until.newWindow(), twoSeconds)60 // Verify application layout with Espresso.61 onView(withId(R.id.noTasksIcon)).check(matches(isDisplayed()))62 }63 /**64 * Waits for delayed notification triggered by application under test and65 * verifies that TasksActivity is shown.66 */67 @Test68 fun clickNotificationOpensTasksActivityDelay() {69 openDrawer()70 onView(allOf(withId(R.id.design_menu_item_text),71 withText(R.string.settings_title))).perform(click())72 onData(CoreMatchers.instanceOf(PreferenceActivity.Header::class.java))73 .inAdapterView(withId(android.R.id.list))74 .atPosition(1)75 .onChildView(withId(android.R.id.title))76 .check(matches(withText("Notifications")))77 .perform(click())78 onData(withKey("notifications_with_delay_send"))79 .inAdapterView(allOf(80 withId(android.R.id.list),81 withParent(withId(android.R.id.list_container))))82 .check(matches(isDisplayed()))83 .perform(click())84 // Perform UI Automator actions.85 uiDevice.openNotification()86 // Wait and click delayed notification by text.87 uiDevice.findObject(By.res("com.android.systemui:id/notification_stack_scroller"))88 .wait(Until.findObject(By.text("My notification")), 8000)89 .clickAndWait(Until.newWindow(), twoSeconds)90 // Verify application layout with Espresso.91 onView(withId(R.id.noTasksIcon)).check(matches(isDisplayed()))92 }...

Full Screen

Full Screen

NavigationTest.kt

Source:NavigationTest.kt Github

copy

Full Screen

1package me.uport.sdk.demoapp2import android.support.test.espresso.Espresso.onData3import android.support.test.espresso.Espresso.onView4import android.support.test.espresso.Espresso.pressBack5import android.support.test.espresso.action.ViewActions.click6import android.support.test.espresso.assertion.ViewAssertions7import android.support.test.espresso.intent.Intents.intended8import android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent9import android.support.test.espresso.intent.rule.IntentsTestRule10import android.support.test.espresso.matcher.ViewMatchers.isDisplayed11import android.support.test.espresso.matcher.ViewMatchers.withId12import me.uport.sdk.demoapp.key_protection.FingerPrintProtectionActivity13import me.uport.sdk.demoapp.key_protection.KeyGuardProtectionActivity14import me.uport.sdk.demoapp.key_protection.KeyProtectionListActivity15import me.uport.sdk.demoapp.managing_jwt.SignJWTKeyPairSignerActivity16import me.uport.sdk.demoapp.managing_jwt.SignJWTListActivity17import me.uport.sdk.demoapp.managing_jwt.SignJWTUportHDSignerActivity18import org.hamcrest.CoreMatchers.anything19import org.junit.Rule20import org.junit.Test21class NavigationTest {22 @get:Rule23 val activityRule = IntentsTestRule(MainListActivity::class.java)24 @Test25 fun listIsDisplayed() {26 onView(withId(me.uport.sdk.demoapp.R.id.item_list)).check(ViewAssertions.matches(isDisplayed()))27 }28 @Test29 fun navigateAllActivities() {30 // check if CreateAccountActivity is launched31 onData(anything()).inAdapterView(withId(R.id.item_list)).atPosition(0).perform(click())32 intended(hasComponent(CreateAccountActivity::class.java.name))33 pressBack()34 // check if CreateKeyActivity is launched35 onData(anything()).inAdapterView(withId(R.id.item_list)).atPosition(1).perform(click())36 intended(hasComponent(CreateKeyActivity::class.java.name))37 pressBack()38 // check if ImportKeyActivity is launched39 onData(anything()).inAdapterView(withId(R.id.item_list)).atPosition(2).perform(click())40 intended(hasComponent(ImportKeyActivity::class.java.name))41 pressBack()42 // check if KeyProtectionListActivity is launched43 onData(anything()).inAdapterView(withId(R.id.item_list)).atPosition(3).perform(click())44 intended(hasComponent(KeyProtectionListActivity::class.java.name))45 // check if KeyGuardProtectionActivity is launched46 onData(anything()).inAdapterView(withId(R.id.item_list)).atPosition(0).perform(click())47 intended(hasComponent(KeyGuardProtectionActivity::class.java.name))48 pressBack()49 // check if FingerPrintProtectionActivity is launched50 onData(anything()).inAdapterView(withId(R.id.item_list)).atPosition(1).perform(click())51 intended(hasComponent(FingerPrintProtectionActivity::class.java.name))52 pressBack()53 // back to MainListActivity54 pressBack()55 // check if SignJWTListActivity is launched56 onData(anything()).inAdapterView(withId(R.id.item_list)).atPosition(4).perform(click())57 intended(hasComponent(SignJWTListActivity::class.java.name))58 // check if SignJWTKeyPairSignerActivity is launched59 onData(anything()).inAdapterView(withId(R.id.item_list)).atPosition(0).perform(click())60 intended(hasComponent(SignJWTKeyPairSignerActivity::class.java.name))61 pressBack()62 // check if SignJWTUportHDSignerActivity is launched63 onData(anything()).inAdapterView(withId(R.id.item_list)).atPosition(1).perform(click())64 intended(hasComponent(SignJWTUportHDSignerActivity::class.java.name))65 pressBack()66 // back to MainListActivity67 pressBack()68 }69}...

Full Screen

Full Screen

HomeActivityTest.kt

Source:HomeActivityTest.kt Github

copy

Full Screen

1package com.zxventures.zxapp2import android.support.test.espresso.Espresso3import android.support.test.espresso.Espresso.onData4import android.support.test.espresso.action.ViewActions.click5import android.support.test.espresso.action.ViewActions.typeText6import android.support.test.espresso.assertion.ViewAssertions.matches7import android.support.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition8import android.support.test.espresso.matcher.RootMatchers.withDecorView9import android.support.test.espresso.matcher.ViewMatchers.isDisplayed10import android.support.test.rule.ActivityTestRule11import com.google.android.gms.location.places.AutocompletePrediction12import com.zxventures.zxapp.base.AcceptanceActivityTest13import com.zxventures.zxapp.screen.home.HomeActivity14import com.zxventures.zxapp.screen.home.adapter.PointOfContactItem15import org.hamcrest.Matchers.*16import org.junit.Test17/**18 * Created by rodrigosimoesrosa19 */20class HomeActivityTest : AcceptanceActivityTest<HomeActivity>(HomeActivity::class.java){21 override fun buildRule(clazz: Class<HomeActivity>): ActivityTestRule<HomeActivity> = ActivityTestRule(clazz)22 private val SEARCH_CORRECT = "Rua Americo"23 private val SEARCH_WRONG = "Moscou"24 @Test25 fun inputCorrectAddress(){26 event.eventOnView(R.id.inputAddress, click(), typeText(SEARCH_CORRECT))27 onData(instanceOf(AutocompletePrediction::class.java))28 .atPosition(0)29 .inRoot(withDecorView(not(`is`(activity?.window?.decorView))))30 .check(matches(isDisplayed()))31 .perform(click())32 event.clickItem<PointOfContactItem>(R.id.pointOfContactRecycler,0)33 }34 @Test35 fun inputCorrectAddressAndBack(){36 event.eventOnView(R.id.inputAddress, click(), typeText(SEARCH_CORRECT))37 onData(instanceOf(AutocompletePrediction::class.java))38 .atPosition(0)39 .inRoot(withDecorView(not(`is`(activity?.window?.decorView))))40 .check(matches(isDisplayed()))41 .perform(click())42 event.eventOnView(R.id.pointOfContactRecycler,43 actionOnItemAtPosition<PointOfContactItem>(0, click()))44 Espresso.pressBack()45 event.clickItem<PointOfContactItem>(R.id.pointOfContactRecycler,0)46 }47 @Test48 fun inputAddressAndCancel(){49 event.eventOnView(R.id.inputAddress, click(), typeText(SEARCH_CORRECT))50 event.eventOnView(R.id.btnClose, click())51 }52 @Test53 fun inputAddressAndCancelAfterLoaded(){54 event.eventOnView(R.id.inputAddress, click(), typeText(SEARCH_CORRECT))55 onData(instanceOf(AutocompletePrediction::class.java))56 .atPosition(0)57 .inRoot(withDecorView(not(`is`(activity?.window?.decorView))))58 .check(matches(isDisplayed()))59 .perform(click())60 event.eventOnView(R.id.btnClose, click())61 }62 @Test63 fun inputWrongAddress(){64 event.eventOnView(R.id.inputAddress, click(),typeText(SEARCH_WRONG))65 onData(instanceOf(AutocompletePrediction::class.java))66 .atPosition(0)67 .inRoot(withDecorView(not(`is`(activity?.window?.decorView))))68 .check(matches(isDisplayed()))69 .perform(click())70 check.viewDisplayed(R.id.txtAlert)71 }72}...

Full Screen

Full Screen

DataInteractionsTest.kt

Source:DataInteractionsTest.kt Github

copy

Full Screen

2import android.preference.PreferenceActivity3import com.example.android.architecture.blueprints.todoapp.R4import com.example.android.architecture.blueprints.todoapp.test.BaseTest5import org.junit.Test6import android.support.test.espresso.Espresso.onData7import android.support.test.espresso.Espresso.onView8import android.support.test.espresso.action.ViewActions.click9import android.support.test.espresso.action.ViewActions.replaceText10import android.support.test.espresso.assertion.ViewAssertions.matches11import android.support.test.espresso.matcher.PreferenceMatchers.withKey12import android.support.test.espresso.matcher.ViewMatchers.isDisplayed13import android.support.test.espresso.matcher.ViewMatchers.withId14import android.support.test.espresso.matcher.ViewMatchers.withParent15import android.support.test.espresso.matcher.ViewMatchers.withText16import com.example.android.architecture.blueprints.todoapp.test.helpers.CommonElements.openDrawer17import org.hamcrest.CoreMatchers.allOf18import org.hamcrest.CoreMatchers.instanceOf19/**20 * DataInteraction samples.21 */22class DataInteractionsTest : BaseTest() {23 @Test24 fun dataInteractionSample() {25 openDrawer()26 onView(allOf<View>(withId(R.id.design_menu_item_text),27 withText(R.string.settings_title))).perform(click())28 // Start of the flow as shown on Figure 1-8.29 onData(instanceOf(PreferenceActivity.Header::class.java))30 .inAdapterView(withId(android.R.id.list))31 .atPosition(0)32 .onChildView(withId(android.R.id.title))33 .check(matches(withText("General")))34 .perform(click())35 onData(withKey("email_edit_text"))36 /*we have to point explicitly what is the parent of of the General prefs list37 because there are two {@ListView}s with the same id - android.R.id.list in the hierarchy*/38 .inAdapterView(allOf<View>(withId(android.R.id.list), withParent(withId(android.R.id.list_container))))39 .check(matches(isDisplayed()))40 .perform(click())41 onView(withId(android.R.id.edit)).perform(replaceText("sample@ema.il"))42 onView(withId(android.R.id.button1)).perform(click())43 // Verify new email is shown.44 onData(withKey("email_edit_text"))45 .inAdapterView(allOf<View>(withId(android.R.id.list), withParent(withId(android.R.id.list_container))))46 .onChildView(withId(android.R.id.summary))47 .check(matches(withText("sample@ema.il")))48 }49}

Full Screen

Full Screen

DataInteractionsKotlinTest.kt

Source:DataInteractionsKotlinTest.kt Github

copy

Full Screen

1package com.example.android.architecture.blueprints.todoapp.test.chapter3.testsamples2import android.preference.PreferenceActivity3import android.support.test.espresso.Espresso.onData4import android.support.test.espresso.Espresso.onView5import android.support.test.espresso.action.ViewActions.click6import android.support.test.espresso.action.ViewActions.replaceText7import android.support.test.espresso.assertion.ViewAssertions.matches8import android.support.test.espresso.matcher.PreferenceMatchers.withKey9import android.support.test.espresso.matcher.ViewMatchers.*10import android.view.View11import com.example.android.architecture.blueprints.todoapp.R12import com.example.android.architecture.blueprints.todoapp.test.BaseTest13import com.example.android.architecture.blueprints.todoapp.test.helpers.CommonElements.openDrawer14import org.hamcrest.CoreMatchers.allOf15import org.hamcrest.CoreMatchers.instanceOf16import org.junit.Test17/**18 * Demonstrates DataInteraction usage in Kotlin.19 */20class DataInteractionsKotlinTest : BaseTest() {21 @Test22 fun dataInteractionSample() {23 openDrawer()24 onView(allOf<View>(withId(R.id.design_menu_item_text),25 withText(R.string.settings_title))).perform(click())26 onData(instanceOf(PreferenceActivity.Header::class.java))27 .inAdapterView(withId(android.R.id.list))28 .atPosition(0)29 .onChildView(withId(android.R.id.title))30 .check(matches(withText("General")))31 .perform(click())32 onData(withKey("email_edit_text"))33 .inAdapterView(allOf(withId(android.R.id.list), withParent(withId(android.R.id.list_container))))34 .check(matches(isDisplayed()))35 .perform(click())36 onView(withId(android.R.id.edit)).perform(replaceText("sample@ema.il"))37 onView(withId(android.R.id.button1)).perform(click())38 onData(withKey("email_edit_text"))39 .inAdapterView(allOf(withId(android.R.id.list), withParent(withId(android.R.id.list_container))))40 .onChildView(withId(android.R.id.summary))41 .check(matches(withText("sample@ema.il")))42 }43}...

Full Screen

Full Screen

onData

Using AI Code Generation

copy

Full Screen

1Espresso.onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(click());2Espresso.onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(longClick());3Espresso.onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(scrollTo());4Espresso.onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(typeText("test"));5Espresso.onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(typeText("test", KEYCODE_DEL));6Espresso.onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(typeText("test", KEYCODE_ENTER));7Espresso.onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(typeText("test", KEYCODE_NUMPAD_ENTER));8Espresso.onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(typeText("test", KEYCODE_SPACE));9Espresso.onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(typeText("test", KEYCODE_TAB));10Espresso.onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(typeText("test", KEYCODE_UNKNOWN));11Espresso.onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(typeText("test", KEYCODE_Z));12Espresso.onData(anything()).inAdapterView(withId(R.id

Full Screen

Full Screen

onData

Using AI Code Generation

copy

Full Screen

1Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(click());2Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(click());3Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(click());4Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(click());5Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(click());6Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(click());7Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(click());8Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(click());9Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(click());10Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(click());11Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(click());12Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(click());13Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition

Full Screen

Full Screen

onData

Using AI Code Generation

copy

Full Screen

1Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(click());2Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(longClick());3Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(typeText("Hello World"));4Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(typeText("Hello World"), pressImeActionButton());5Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(typeText("Hello World"), closeSoftKeyboard());6Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(typeText("Hello World"), pressImeActionButton(), closeSoftKeyboard());7Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(typeText("Hello World"), pressImeActionButton(), closeSoftKeyboard(), click());8Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(typeText("Hello World"), pressImeActionButton(), closeSoftKeyboard(), longClick());9Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(typeText("Hello World"), pressImeActionButton(), closeSoftKeyboard(), scrollTo());10Espresso.onData(anything()).inAdapterView(withId(R.id.listview)).atPosition(0).perform(typeText("Hello World"), pressImeActionButton(), closeSoftKeyboard(), scrollTo(), click());

Full Screen

Full Screen

onData

Using AI Code Generation

copy

Full Screen

1 onData(anything()).inAdapterView(withId(R.id.listView)).atPosition(0).perform(click());2 onData(anything()).inAdapterView(withId(R.id.listView)).atPosition(1).perform(click());3 onData(anything()).inAdapterView(withId(R.id.listView)).atPosition(2).perform(click());4 onData(anything()).inAdapterView(withId(R.id.listView)).atPosition(3).perform(click());5 onData(anything()).inAdapterView(withId(R.id.listView)).atPosition(4).perform(click());6 onData(anything()).inAdapterView(withId(R.id.listView)).atPosition(5).perform(click());7 onData(anything()).inAdapterView(withId(R.id.listView)).atPosition(6).perform(click());8 onData(anything()).inAdapterView(withId(R.id.listView)).atPosition(7).perform(click());9 onData(anything()).inAdapterView(withId(R.id.listView)).atPosition(8).perform(click());10 onData(anything()).inAdapterView(withId(R.id.listView)).atPosition(9).perform(click());11 onData(anything()).inAdapterView(withId(R.id.listView)).atPosition(10).perform(click());12 onData(anything()).inAdapterView(withId(R.id.listView)).atPosition(11).perform(click());13 onData(anything()).inAdapterView(withId(R.id.listView)).atPosition(12).perform(click());14 onData(anything

Full Screen

Full Screen

onData

Using AI Code Generation

copy

Full Screen

1import android.support.test.espresso.DataInteraction;2import static android.support.test.espresso.Espresso.onData;3import static android.support.test.espresso.action.ViewActions.click;4import static android.support.test.espresso.matcher.ViewMatchers.withId;5import static org.hamcrest.Matchers.anything;6import static org.hamcrest.Matchers.containsString;7import static org.hamcrest.Matchers.instanceOf;8import static org.hamcrest.Matchers.is;9public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {10private MainActivity mActivity;11public MainActivityTest() {12super(MainActivity.class);13}14protected void setUp() throws Exception {15super.setUp();16setActivityInitialTouchMode(false);17mActivity = getActivity();18}19public void testListView() {20DataInteraction linearLayout = onData(anything())21.inAdapterView(withId(R.id.listView))22.atPosition(0);23linearLayout.perform(click());24}25}26import android.support.test.espresso.DataInteraction;27import static android.support.test.espresso.Espresso.onData;28import static android.support.test.espresso.action.ViewActions.click;29import static android.support.test.espresso.matcher.ViewMatchers.withId;30import static org.hamcrest.Matchers.anything;31import static org.hamcrest.Matchers.containsString;32import static org.hamcrest.Matchers.instanceOf;33import static org.hamcrest.Matchers.is;34public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {35private MainActivity mActivity;36public MainActivityTest() {37super(MainActivity.class);38}39protected void setUp() throws Exception {40super.setUp();41setActivityInitialTouchMode(false);42mActivity = getActivity();43}44public void testListView() {45DataInteraction linearLayout = onData(anything())46.inAdapterView(withId(R.id.listView))47.atPosition(0);48linearLayout.perform(click());49}50}51import android.test.ActivityInstrumentationTestCase2;52import android.widget.ListView;53public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {54private MainActivity mActivity;55public MainActivityTest() {56super(MainActivity

Full Screen

Full Screen

onData

Using AI Code Generation

copy

Full Screen

1onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).check(matches(withText("one")));2onData(anything()).inAdapterView(withId(R.id.list)).atPosition(1).check(matches(withText("two")));3onData(anything()).inAdapterView(withId(R.id.list)).atPosition(2).check(matches(withText("three")));4onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).check(matches(withText("one")));5onData(anything()).inAdapterView(withId(R.id.list)).atPosition(1).check(matches(withText("two")));6onData(anything()).inAdapterView(withId(R.id.list)).atPosition(2).check(matches(withText("three")));7onData(anything()).inAdapterView(withId(R.id.list)).atPosition(3).check(matches(withText("four")));8onData(anything()).inAdapterView(withId(R.id.list)).atPosition(4).check(matches(withText("five")));9onData(anything()).inAdapterView(withId(R.id.list)).atPosition(5).check(matches(withText("six")));10onData(anything()).inAdapterView(withId(R.id.list)).atPosition(6).check(matches(withText("seven")));11onData(anything()).inAdapterView(withId(R.id.list)).atPosition(7).check(matches(withText("eight")));12onData(anything()).inAdapterView(withId(R.id.list)).atPosition(8).check(matches(withText("nine")));13onData(anything()).inAdapterView(withId(R.id.list)).atPosition(9).check(matches(withText("ten")));14onData(anything()).inAdapterView(withId(R.id.list)).atPosition(10).check(matches(withText("eleven")));15onData(anything()).inAdapterView(withId(R.id.list)).atPosition(11).check(matches(withText("twelve")));16onData(anything()).inAdapterView(withId(R.id.list)).atPosition(12).check(matches(withText("thirteen")));17onData(anything()).inAdapterView(withId(R.id.list)).atPosition(13).check(matches(withText("fourteen")));18onData(anything()).inAdapterView(withId(R.id.list)).atPosition(14).check(matches(withText("fifteen")));19onData(anything()).inAdapterView(withId(R

Full Screen

Full Screen

onData

Using AI Code Generation

copy

Full Screen

1Espresso.onView(withText("Hello World")).perform(click());2Espresso.onView(withText("Hello World")).perform(click());3Espresso.onView(withText("Hello World")).perform(click());4Espresso.onView(withText("Hello World")).perform(click());5Espresso.onView(withText("Hello World")).perform(click());6Espresso.onView(withText("Hello World")).perform(click());

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.

Run Appium-espresso-driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful