protected void performStartAdventure() { ViewInteraction button = onView(allOf(withText(getString(R.string.create_new_adventure)), isDisplayed())); button.perform(click()); //Clicks over the proper book using the property order of the GamebookEnum DataInteraction textView = onData(anything()) .inAdapterView(allOf(withId(R.id.gamebookListView), childAtPosition( withClassName(is("android.widget.RelativeLayout")), 0))) .atPosition(getGamebook().getOrder() - 1); textView.perform(click()); button = onView(allOf(withText(getString(R.string.create_new_adventure)), isDisplayed())); button.perform(click()); Espresso.closeSoftKeyboard(); }
/** */ @SuppressWarnings("unchecked") public static DataInteraction onListItem(int pos) { return onData(anything()) .inAdapterView(allOf(withId(android.R.id.list), isDisplayed())) .atPosition(pos); }
public void performChoosemartialArt() { DataInteraction linearLayout = onData(anything()) .inAdapterView(allOf(withId(R.id.skillList), childAtPosition( withClassName(is("android.widget.RelativeLayout")), 1))) .atPosition(0); linearLayout.perform(click()); }
public void performChooseSpells() { DataInteraction textView2 = onData(anything()) .inAdapterView(allOf(withId(R.id.spellListView), childAtPosition( withClassName(is("android.widget.LinearLayout")), 1))) .atPosition(0); textView2.perform(click()); DataInteraction textView3 = onData(anything()) .inAdapterView(allOf(withId(R.id.spellListView), childAtPosition( withClassName(is("android.widget.LinearLayout")), 1))) .atPosition(0); textView3.perform(click()); DataInteraction textView4 = onData(anything()) .inAdapterView(allOf(withId(R.id.spellListView), childAtPosition( withClassName(is("android.widget.LinearLayout")), 1))) .atPosition(1); textView4.perform(click()); DataInteraction textView5 = onData(anything()) .inAdapterView(allOf(withId(R.id.spellListView), childAtPosition( withClassName(is("android.widget.LinearLayout")), 1))) .atPosition(1); textView5.perform(click()); }
public void performChooseSuperpower() { DataInteraction linearLayout = onData(anything()) .inAdapterView(allOf(withId(R.id.superpowerList), childAtPosition( withClassName(is("android.widget.RelativeLayout")), 1))) .atPosition(0); linearLayout.perform(click()); }
protected void performChoosePotion() { DataInteraction linearLayout = onData(anything()) .inAdapterView(allOf(withId(R.id.potionList), childAtPosition( withClassName(is("android.widget.LinearLayout")), 0))) .atPosition(0); linearLayout.perform(click()); }
@Test public void testExistingGroup() throws InterruptedException { //Given a preexisting group newGroup, when we search for new group in the list view, //then the new group is still there (and clickable) Thread.sleep(1000); DataInteraction v2 = onData(hasToString(startsWith("newGroup"))) .inAdapterView(withId(R.id.groupList)).atPosition(0); v2.check(matches(withText("newGroup"))); }
/** * Tests clicking on a meal in the meal list to open it */ public void testOpenMeal() throws SQLException { final Matcher<View> mealList = withTagKey(R.id.test_tag_meal_list, Is.<Object>is("Meal List")); final DataInteraction mealItem = onData(anything()).inAdapterView(mealList); mealItem.perform(click()); // Check that the MealViewActivity activity has started // The below statement produces an error in the instrumentation code. // TODO: Fix // intended(hasComponent(new ComponentName(getInstrumentation().getTargetContext(), // MealViewActivity.class))); }
public ActionableData with(C content) { DataInteraction dataInteraction = onData(dataMatcher(content)); if (resourceId != 0) { return new ActionableData(dataInteraction.inAdapterView(withId(resourceId))); } else { return new ActionableData(dataInteraction); } }
@Test public void test_schedule_saturday() { String fromName = "San Francisco"; String toName = "22nd St"; onView(withId(R.id.btn_sat)).perform(click()); onView(withId(R.id.input_departure)).perform(click()); onData(is(fromName)).perform(click()); onView(withId(R.id.input_arrival)).perform(click()); onData(is(toName)).perform(click()); List<String> expects = Arrays.asList("08:07 => 08:11", "09:37 => 09:41", "11:07 => 11:11", "12:37 => 12:41", "14:07 => 14:11", "15:37 => 15:41", "17:07 => 17:11", "18:37 => 18:41", "20:07 => 20:11", "21:37 => 21:41", "22:51 => 22:55", "00:05 => 00:10"); onView(withId(R.id.results)).check(matches(new ResultListMatcher(fromName, toName, expects.size()))); DataInteraction interaction = onData(anything()).inAdapterView(withId(R.id.results)); for (int l = expects.size() - 1; l >= 0; l--) { String expect = expects.get(l); interaction .atPosition(l) .check(matches(new ResultViewMatcher(fromName, toName, l, expect))); } }
@Test public void test_schedule_sunday() { String fromName = "San Francisco"; String toName = "22nd St"; onView(withId(R.id.btn_sun)).perform(click()); onView(withId(R.id.input_departure)).perform(click()); onData(is(fromName)).perform(click()); onView(withId(R.id.input_arrival)).perform(click()); onData(is(toName)).perform(click()); List<String> expects = Arrays.asList("08:07 => 08:11", "09:37 => 09:41", "11:07 => 11:11", "12:37 => 12:41", "14:07 => 14:11", "15:37 => 15:41", "17:07 => 17:11", "18:37 => 18:41", "20:07 => 20:11", "21:37 => 21:41"); onView(withId(R.id.results)).check(matches(new ResultListMatcher(fromName, toName, expects.size()))); DataInteraction interaction = onData(anything()).inAdapterView(withId(R.id.results)); for (int l = expects.size() - 1; l >= 0; l--) { String expect = expects.get(l); interaction .atPosition(l) .check(matches(new ResultViewMatcher(fromName, toName, l, expect))); } }
public static void testArticleLoad(Activity activity) { while (!viewIsDisplayed(R.id.search_results_list)) { waitFor(WAIT_FOR_1000); } DataInteraction view = onData(anything()) .inAdapterView(allOf(withId(R.id.search_results_list), childAtPosition( withId(R.id.search_results_container), 1))) .atPosition(0); view.perform(click()); while (!viewIsDisplayed(R.id.view_page_header_image)) { waitFor(WAIT_FOR_2000); } ScreenshotTools.snap("Barack"); onView(withId(R.id.view_page_header_image)) .perform(swipeUp()); onView(withId(R.id.page_fragment)) .perform(swipeUp()); ScreenshotTools.snap("ArticleSwipeUpNoActionBar"); onView(withId(R.id.page_fragment)) .perform(swipeUp()); onView(withId(R.id.page_fragment)) .perform(swipeDown()); ScreenshotTools.snap("ArticleSwipeDownActionBarAndTabSeen"); }
static DataInteraction onSpinnerString(String value) { return onData(allOf(instanceOf(String.class), is(value))).inRoot(not(isDialog())); }
public ActionableData(DataInteraction dataInteraction) { this.dataInteraction = dataInteraction; }
public DataInteraction thenOnData(Matcher<Object> dataMatcher) { return onData(dataMatcher); }
public Preference getPreferenceAtLine(int index) { DataInteraction dataInteraction = onData(anything()) .inAdapterView(withId(android.R.id.list)) .atPosition(index); return new Preference(dataInteraction); }
public Preference getPreferenceWithTitle(@StringRes int id) { DataInteraction dataInteraction = onData(allOf(instanceOf(EditTextPreference.class), withTitle(id))); return new Preference(dataInteraction); }
private Preference(DataInteraction dataInteraction) { this.dataInteraction = dataInteraction; }
@Test public void openHABMainActivityTest() throws InterruptedException { ViewInteraction firstRecyclerView = onView(withId(R.id.recyclerview)); firstRecyclerView .perform(RecyclerViewActions.scrollToPosition(0)) .check(matches(atPositionOnView(0, isDisplayed(), R.id.widgetlabel))) .check(matches(atPositionOnView(0, withText("First Floor"), R.id.widgetlabel))); firstRecyclerView .perform(RecyclerViewActions.scrollToPosition(6)) .check(matches(atPositionOnView(6, isDisplayed(), R.id.widgetlabel))) .check(matches(atPositionOnView(6, withText("Astronomical Data"), R.id.widgetlabel))); // does it show "garden"? firstRecyclerView .perform(RecyclerViewActions.scrollToPosition(3)) .check(matches(atPositionOnView(3, isDisplayed(), R.id.widgetlabel))) .check(matches(atPositionOnView(3, withText("Garden"), R.id.widgetlabel))); // open widget overview firstRecyclerView .perform(RecyclerViewActions.actionOnItemAtPosition(10, click())); // FIXME: is there a more elegant way to wait for the new fragment? Thread.sleep(1000); // check whether selection widget appears and click on it ViewInteraction secondRecyclerView = onView(withIndex(withId(R.id.recyclerview), 1)); secondRecyclerView .perform(RecyclerViewActions.scrollToPosition(4)) .check(matches(atPositionOnView(4, withText("Scene Selection"), R.id.widgetlabel))) .check(matches(atPositionOnView(4, isDisplayed(), R.id.selectionspinner))) .perform(RecyclerViewActions.actionOnItemAtPosition(4, onChildView(click(), R.id.selectionspinner))); DataInteraction appCompatCheckedTextView = onData(anything()) .inAdapterView(withClassName( is("com.android.internal.app.AlertController$RecycleListView"))) .atPosition(0); appCompatCheckedTextView.check(matches(withText("off"))); appCompatCheckedTextView.perform(click()); // check whether scene radio button group is present secondRecyclerView .perform(RecyclerViewActions.scrollToPosition(5)) .check(matches(atPositionOnView(5, isDisplayed(), R.id.sectionswitchradiogroup))); // check whether switch is displayed secondRecyclerView .perform(RecyclerViewActions.scrollToPosition(1)) .check(matches(atPositionOnView(1, isDisplayed(), R.id.switchswitch))); // check whether slider is displayed secondRecyclerView .perform(RecyclerViewActions.scrollToPosition(8)) .check(matches(atPositionOnView(8, isDisplayed(), R.id.sliderseekbar))); // check whether color control button is displayed secondRecyclerView .perform(RecyclerViewActions.scrollToPosition(9)) .check(matches(atPositionOnView(9, isDisplayed(), R.id.colorbutton_color))); // check whether roller shutter button is displayed secondRecyclerView .perform(RecyclerViewActions.scrollToPosition(10)) .check(matches(atPositionOnView(10, isDisplayed(), R.id.rollershutterbutton_stop))); }
@Test public void test_schedule_weekday() { String fromName = "San Francisco"; String toName = "22nd St"; onView(withId(R.id.btn_week)).perform(click()); onView(withId(R.id.input_departure)).perform(click()); onData(is(fromName)).perform(click()); onView(withId(R.id.input_arrival)).perform(click()); onData(is(toName)).perform(click()); List<String> expects = Arrays.asList("04:55 => 04:59", "05:25 => 05:29", "06:05 => 06:09", "06:15 => 06:19", "06:35 => 06:39", "06:45 => 06:51", "06:59 => 07:03", "07:05 => 07:10", "07:15 => 07:19", "07:35 => 07:39", "07:45 => 07:51", "07:59 => 08:03", "08:05 => 08:10", "08:15 => 08:19", "08:35 => 08:39", "08:45 => 08:49", "09:00 => 09:05", "10:00 => 10:04", "11:00 => 11:04", "12:00 => 12:04", "13:00 => 13:04", "14:00 => 14:04", "15:00 => 15:04", "16:32 => 16:36", "17:32 => 17:36", "18:32 => 18:36", "19:30 => 19:34", "20:30 => 20:34", "21:30 => 21:34", "22:40 => 22:44", "00:05 => 00:10"); onView(withId(R.id.results)).check(matches(new ResultListMatcher(fromName, toName, expects.size()))); DataInteraction interaction = onData(anything()).inAdapterView(withId(R.id.results)); for (int l = expects.size() - 1; l >= 0; l--) { String expect = expects.get(l); interaction .atPosition(l) .check(matches(new ResultViewMatcher(fromName, toName, l, expect))); } }
/** * @see BaseView#BaseView(Class, org.hamcrest.Matcher) * Instead instantiates a {@link DataInteraction} */ @SuppressWarnings("unchecked") public ListItem(Class<T> type, DataInteraction adapter) { super(type, (Matcher) anything()); this.adapter = adapter; }
/** * Retains type and adapter for use later on. * @param type the class of the generic type * @param adapter the {@link android.support.test.espresso.DataInteraction} for the {@link android.widget.AdapterView} this represents */ @SuppressWarnings("unchecked") private ListAdapter(Class<T> type, DataInteraction adapter) { super(type, (Matcher) anything()); this.adapter = adapter; }
public static void searchKeywordAndGo(@NonNull String keyword) { while (!viewIsDisplayed(R.id.search_container)) { waitFor(WAIT_FOR_1000); } ViewInteraction linearLayout = onView( allOf(withId(R.id.search_container), childAtPosition( childAtPosition( withId(R.id.fragment_feed_feed), 0), 0), isDisplayed())); linearLayout.perform(click()); ViewInteraction frameLayout = onView( allOf(withId(R.id.search_lang_button_container), withContentDescription("Wikipedia language"), childAtPosition( childAtPosition( withId(R.id.search_toolbar), 1), 1), isDisplayed())); frameLayout.perform(click()); ViewInteraction plainPasteEditText = onView( allOf(withId(R.id.preference_languages_filter), childAtPosition( childAtPosition( withClassName(is("android.support.design.widget.TextInputLayout")), 0), 0), isDisplayed())); plainPasteEditText.perform(replaceText("test"), closeSoftKeyboard()); // take screenshot ScreenshotTools.snap("SearchPage"); DataInteraction linearLayout2 = onData(anything()) .inAdapterView(allOf(withId(R.id.preference_languages_list), childAtPosition( withClassName(is("android.widget.LinearLayout")), 1))) .atPosition(0); linearLayout2.perform(click()); ViewInteraction searchAutoComplete = onView( allOf(withId(R.id.search_src_text), childAtPosition( allOf(withId(R.id.search_plate), childAtPosition( withId(R.id.search_edit_frame), 1)), 0), isDisplayed())); searchAutoComplete.perform(replaceText(keyword), closeSoftKeyboard()); // hold until the result fetch while (!viewIsDisplayed(R.id.search_results_list)) { waitFor(WAIT_FOR_1000); } // take screenshot ScreenshotTools.snap("SearchSuggestionPage"); }
/** * Uses {@link Espresso#onData(org.hamcrest.Matcher)} to get a reference to a specific row. * <p> * Note: A custom matcher can be used to match the content and have more readable code. * See the Custom Matcher Sample. * </p> * * @param str the content of the field * @return a {@link DataInteraction} referencing the row */ private static DataInteraction onRow(String str) { //return onData(hasEntry(equalTo(LongListActivity.ROW_TEXT), is(str))); return null; }
/** * Uses {@link Espresso#onData(org.hamcrest.Matcher)} to get a reference to a specific row. * <p> * Note: A custom matcher can be used to match the content and have more readable code. * See the Custom Matcher Sample. * </p> * * @param str the content of the field * @return a {@link DataInteraction} referencing the row */ private static DataInteraction onRow(String str) { return onData(hasEntry(equalTo(LongListActivity.ROW_TEXT), is(str))); }