Java Code Examples for android.support.test.uiautomator.UiObject#swipeUp()
The following examples show how to use
android.support.test.uiautomator.UiObject#swipeUp() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItSettingsActivity.java From SmoothClicker with MIT License | 5 votes |
/** * Test if the item about credits in the Settings activity starts the credits activity */ @Test public void credits(){ l(this, "@Test credits"); try { // Swipe to the bottom of the view to get the credits field UiObject list = mDevice.findObject( new UiSelector() .className("android.widget.ListView") .packageName(PACKAGE_APP_PATH) .resourceId("android:id/list") ); list.swipeUp(100); list.swipeUp(100); // Clicks on the credits row String s = InstrumentationRegistry.getTargetContext().getString(R.string.pref_key_credit_title); UiObject creditsRow = mDevice.findObject( new UiSelector() .className("android.widget.TextView") .packageName(PACKAGE_APP_PATH) .resourceId("android:id/title") .text(s) ); creditsRow.click(); w(1000); assertEquals(CreditsActivity.class.getSimpleName(), getActivityInstance().getClass().getSimpleName()); } catch ( UiObjectNotFoundException uonfe ){ fail(uonfe.getMessage()); uonfe.printStackTrace(); } }
Example 2
Source File: ItClickerActivity.java From SmoothClicker with MIT License | 5 votes |
/** * Tests the long clicks on the floating action button for new point in the arc menu * * <i>A long click on the button to use to add points to click on should display a snackbar with an explain message</i> */ @Test public void longClickOnArcMenuNewPointItem(){ l(this, "@Test longClickOnArcMenuNewPointItem"); String expectedString = InstrumentationRegistry.getTargetContext().getString(R.string.info_message_new_point); try { /* * Display the floating action buttons in the arc menu */ UiObject arcMenu = mDevice.findObject( new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/fabAction") ); arcMenu.click(); arcMenu.waitForExists(WAIT_FOR_EXISTS_TIMEOUT); /* * The floating action button */ UiObject fab = mDevice.findObject( new UiSelector().resourceId(PACKAGE_APP_PATH+":id/fabSelectPoint") ); fab.waitForExists(WAIT_FOR_EXISTS_TIMEOUT); assertTrue(fab.isLongClickable()); fab.swipeUp(100); //fab.longClick() makes clicks sometimes, so swipeUp() is a trick to make always a longclick UiObject snack = mDevice.findObject( new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/snackbar_text") ); assertEquals(expectedString, snack.getText()); } catch ( UiObjectNotFoundException uonfe ){ uonfe.printStackTrace(); fail( uonfe.getMessage() ); } }
Example 3
Source File: AutomatorServiceImpl.java From android-uiautomator-server with MIT License | 5 votes |
private boolean swipe(UiObject item, String dir, int steps) throws UiObjectNotFoundException { dir = dir.toLowerCase(); boolean result = false; if ("u".equals(dir) || "up".equals(dir)) result = item.swipeUp(steps); else if ("d".equals(dir) || "down".equals(dir)) result = item.swipeDown(steps); else if ("l".equals(dir) || "left".equals(dir)) result = item.swipeLeft(steps); else if ("r".equals(dir) || "right".equals(dir)) result = item.swipeRight(steps); return result; }
Example 4
Source File: ItSettingsActivity.java From SmoothClicker with MIT License | 4 votes |
/** * Tests the seekbar for the threshold sued in the picture recognition system */ @Test public void thresholdSeekBar(){ l(this, "@Test thresholdSeekBar"); try { // Swipe to the bottom of the view to get the seekbar UiObject list = mDevice.findObject( new UiSelector() .className("android.widget.ListView") .packageName(PACKAGE_APP_PATH) .resourceId("android:id/list") ); list.swipeUp(100); list.swipeUp(100); // Get the seek bar UiObject seekBar = mDevice.findObject( new UiSelector() .className("android.widget.SeekBar") .packageName(PACKAGE_APP_PATH) ); // Swipe to the very right and check if we are at 100% seekBar.swipeRight(100); UiObject seekBarValue = mDevice.findObject( new UiSelector() .className("android.widget.TextView") .packageName(PACKAGE_APP_PATH) .resourceId(PACKAGE_APP_PATH + ":id/seekbar_value") ); assertEquals( "10", seekBarValue.getText() ); // Swipe to the very left and check if we are at 100% seekBar.swipeLeft(100); seekBarValue = mDevice.findObject( new UiSelector() .className("android.widget.TextView") .packageName(PACKAGE_APP_PATH) .resourceId(PACKAGE_APP_PATH+":id/seekbar_value") ); assertEquals("1", seekBarValue.getText()); w(1000); // // Click on the item to get the dialog to fill the seekbar: change the value but cancel // seekBarValue.click(); // UiObject customValue = mDevice.findObject( // new UiSelector() // .className("android.widget.EditText") // .packageName(PACKAGE_APP_PATH) // .resourceId(PACKAGE_APP_PATH + ":id/customValue") // ); // customValue.setText("42"); // UiObject button = mDevice.findObject( // new UiSelector() // .className("android.widget.Button") // .packageName(PACKAGE_APP_PATH) // .resourceId(PACKAGE_APP_PATH + ":id/btn_cancel") // ); // button.click(); // assertEquals("1", seekBarValue.getText()); // w(1000); // // // Click on the item to get the dialog to fill the seekbar: change the value but apply // seekBarValue.click(); // customValue = mDevice.findObject( // new UiSelector() // .className("android.widget.EditText") // .packageName(PACKAGE_APP_PATH) // .resourceId(PACKAGE_APP_PATH + ":id/customValue") // ); // customValue.setText("23"); // button = mDevice.findObject( // new UiSelector() // .className("android.widget.Button") // .packageName(PACKAGE_APP_PATH) // .resourceId(PACKAGE_APP_PATH + ":id/btn_apply") // ); // button.click(); // assertEquals("23", seekBarValue.getText()); // w(1000); } catch ( UiObjectNotFoundException uonfe ){ uonfe.printStackTrace(); fail(uonfe.getMessage()); } }
Example 5
Source File: ItSettingsActivity.java From SmoothClicker with MIT License | 4 votes |
/** * Test if the item about help in the Settings activity starts the intro screens activity */ @Test public void help(){ l(this, "@Test help"); try { // Swipe to the bottom of the view to get the credits field in an inner preference screen UiObject list = mDevice.findObject( new UiSelector() .className("android.widget.ListView") .packageName(PACKAGE_APP_PATH) .resourceId("android:id/list") ); list.swipeUp(100); list.swipeUp(100); String innerPreferenceScreenTitle = InstrumentationRegistry.getTargetContext().getString(R.string.pref_about_subtitle); UiObject aboutRow = mDevice.findObject( new UiSelector() .className("android.widget.TextView") .packageName(PACKAGE_APP_PATH) .resourceId("android:id/title") .text(innerPreferenceScreenTitle) ); aboutRow.click(); // Clicks on the credits row String s = InstrumentationRegistry.getTargetContext().getString(R.string.pref_key_help_title); UiObject helpRow = mDevice.findObject( new UiSelector() .className("android.widget.TextView") .packageName(PACKAGE_APP_PATH) .resourceId("android:id/title") .text(s) ); helpRow.click(); w(1000); assertEquals(IntroScreensActivity.class.getSimpleName(), getActivityInstance().getClass().getSimpleName()); } catch ( UiObjectNotFoundException uonfe ){ fail(uonfe.getMessage()); uonfe.printStackTrace(); } }
Example 6
Source File: ItSettingsActivity.java From SmoothClicker with MIT License | 4 votes |
/** * Tests the files names fields * * <i>If we change the name of the file in sue, we have to see the summary of the dedicated field be updated</i> */ @Test public void filesNames(){ l(this, "@Test filesNames"); try { // Swipe to the bottom of the view to get the fields field in an inner preference screen UiObject list = mDevice.findObject( new UiSelector() .className("android.widget.ListView") .packageName(PACKAGE_APP_PATH) .resourceId("android:id/list") ); list.swipeUp(100); String innerPreferenceScreenTitle = InstrumentationRegistry.getTargetContext().getString(R.string.pref_app_files_title); UiObject filesRow = mDevice.findObject( new UiSelector() .className("android.widget.TextView") .packageName(PACKAGE_APP_PATH) .resourceId("android:id/title") .text(innerPreferenceScreenTitle) ); filesRow.click(); // Update the name of file containing the points testFieldWithName(0, InstrumentationRegistry.getTargetContext().getString(R.string.pref_app_files_points_name)); // Update the name of file containing the config testFieldWithName(1, InstrumentationRegistry.getTargetContext().getString(R.string.pref_app_files_config_name)); // Update the name of file containing the unlock script testFieldWithName(2, InstrumentationRegistry.getTargetContext().getString(R.string.pref_app_files_unlock_name)); // Update the name of file containing the picture testFieldWithName(3, InstrumentationRegistry.getTargetContext().getString(R.string.pref_app_files_trigger_name)); } catch ( UiObjectNotFoundException uonfe ){ uonfe.printStackTrace(); fail(uonfe.getMessage()); } }
Example 7
Source File: ItClickerActivity.java From SmoothClicker with MIT License | 4 votes |
/** * Test the click on the button for the "clean all" feature * * <i>If the button to clean all is clicked, the configuration / values ion the fields have to be the default values, and the list of points has to be cleaned</i> * <i>If the button to clean all is clicked and no values has been changed, the values still remain the default ones</i> */ @Test public void clickCleanAll(){ l(this, "@Test clickCleanAll"); try { // Get the menu item UiObject mi = mDevice.findObject( new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/action_clean_all") ); // Add some values UiObject delayField = mDevice.findObject( new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/etDelay") ); delayField.setText("007"); Espresso.closeSoftKeyboard(); w(1000); UiObject repeatField = mDevice.findObject( new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/etRepeat") ); repeatField.setText("42"); Espresso.closeSoftKeyboard(); w(1000); UiObject timeGapField = mDevice.findObject( new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/etTimeBeforeEachClick") ); timeGapField.setText("123"); Espresso.closeSoftKeyboard(); w(1000); UiObject endless = mDevice.findObject( new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/scEndlessRepeat") ); endless.click(); w(1000); // Swipe to display items UiObject swipeableLayout = mDevice.findObject( new UiSelector().resourceId(PACKAGE_APP_PATH+":id/clickerActivityMainLayout") ); swipeableLayout.swipeUp(100); UiObject vibrateOnStart = mDevice.findObject( new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/scVibrateOnStart") ); vibrateOnStart.click(); w(1000); UiObject vibrateOnClick = mDevice.findObject( new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/scVibrateOnClick") ); vibrateOnClick.click(); w(1000); UiObject notifications = mDevice.findObject( new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/scNotifOnClick") ); notifications.click(); w(1000); fillSpinnerAsUser(); // Click on the menu item mi.click(); // Check if the values have been made empty assertEquals(Config.DEFAULT_DELAY, delayField.getText()); assertEquals(Config.DEFAULT_TIME_GAP, timeGapField.getText()); assertEquals(Config.DEFAULT_REPEAT, repeatField.getText()); assertEquals(Config.DEFAULT_REPEAT_ENDLESS, endless.isChecked()); assertEquals(Config.DEFAULT_VIBRATE_ON_START, vibrateOnStart.isChecked()); assertEquals(Config.DEFAULT_VIBRATE_ON_CLICK, vibrateOnClick.isChecked()); assertEquals(Config.DEFAULT_NOTIF_ON_CLICK, notifications.isChecked()); // onView(withId(R.id.clickerActivityMainLayout)).perform(swipeUp()); // onView(withId(R.id.sPointsToClick)).perform(click()); // onView(withId(R.id.sPointsToClick)).check(ViewAssertions.matches(withListSize(1))); // Test again to check if the default values remain mi.click(); assertEquals(Config.DEFAULT_DELAY, delayField.getText()); assertEquals(Config.DEFAULT_TIME_GAP, timeGapField.getText()); assertEquals(Config.DEFAULT_REPEAT, repeatField.getText()); assertEquals(Config.DEFAULT_REPEAT_ENDLESS, endless.isChecked()); assertEquals(Config.DEFAULT_VIBRATE_ON_START, vibrateOnStart.isChecked()); assertEquals(Config.DEFAULT_VIBRATE_ON_CLICK, vibrateOnClick.isChecked()); assertEquals(Config.DEFAULT_NOTIF_ON_CLICK, notifications.isChecked()); // onView(withId(R.id.sPointsToClick)).check(ViewAssertions.matches(withListSize(1))); } catch ( Exception e ){ e.printStackTrace(); fail( e.getMessage() ); } }