Java 类android.support.test.espresso.ViewInteraction 实例源码

项目:ChimpCheck    文件:FingerGestures.java   
public static void swipeOnView(AppEventOuterClass.UIID uiid, ViewInteraction vi, AppEventOuterClass.Orientation ori){
    switch(ori.getOrientType()){
        case UP: vi.perform(swipeUp()); break;
        case DOWN: vi.perform(swipeDown()); break;
        case LEFT: vi.perform(swipeLeft()); break;
        case RIGHT: vi.perform(swipeRight()); break;
        case XY_TYPE:
            ActivityManager activityManager = new ActivityManager();
            View v = new View(activityManager.getActivityInstance().getApplicationContext());
            switch(uiid.getIdType()){
                case R_ID:
                    v = activityManager.getDecorView().findViewById(uiid.getRid());
                    break;
                case NAME_ID:
                    View decorView = activityManager.getDecorView();
                    int resId = decorView.getResources().getIdentifier(uiid.getNameid(), "id", activityManager.getActivityInstance().getPackageName() );
                    v = decorView.findViewById(resId);
                    break;
            }

            if(v == null) {
                return;
            }

            float x = v.getX();
            float y = v.getY();
            float centerX = x + v.getWidth() / 2;
            float centerY = y + v.getHeight() / 2;
            AppEventOuterClass.XYCoordin desXY = ori.getXy();
            vi.perform(swipeOnCoord(centerX, centerY, desXY.getX(), desXY.getY()));

            break;
    }
}
项目:ChimpCheck    文件:FingerGestures.java   
public static void swipeOnCoord(ViewInteraction vi, AppEventOuterClass.XYCoordin fromXY, AppEventOuterClass.Orientation ori){
    float fromX = fromXY.getX();
    float fromY = fromXY.getY();

    float offset = 100;
    switch(ori.getOrientType()){
        case UP: vi.perform(swipeOnCoord(fromX, fromY, fromX, fromY - offset));
        case DOWN: vi.perform(swipeOnCoord(fromX, fromY, fromX, fromY + offset));
        case LEFT: vi.perform(swipeOnCoord(fromX, fromY, fromX - offset, fromY));
        case RIGHT: vi.perform(swipeOnCoord(fromX, fromY, fromX + offset, fromY));
        case XY_TYPE:
            AppEventOuterClass.XYCoordin ToXY = ori.getXy();
            float toX = ToXY.getX();
            float toY = ToXY.getY();
            vi.perform(swipeOnCoord(fromX, fromY, toX, toY));
        default:
            break;
    }

}
项目:android-testing-sample    文件:MainActivityTest2.java   
@Test
public void mainActivityTest2() {
    ViewInteraction appCompatButton = onView(
            allOf(withId(R.id.next_activity_button), withText("Next Activity"),
                    childAtPosition(
                            childAtPosition(
                                    withId(android.R.id.content),
                                    0),
                            0),
                    isDisplayed()));
    appCompatButton.perform(click());

    ViewInteraction appCompatButton2 = onView(
            allOf(withId(R.id.random_button), withText("RANDOM NUMBER"),
                    childAtPosition(
                            childAtPosition(
                                    withId(android.R.id.content),
                                    0),
                            0),
                    isDisplayed()));
    appCompatButton2.perform(click());

}
项目:NumberPadTimePicker    文件:NumberPadTimePickerDialogTest.java   
private static ViewInteraction[] getButtonInteractions() {
    ViewInteraction[] buttonsInteractions = new ViewInteraction[10];
    // We cannot rely on the withDigit() matcher to retrieve these because,
    // after performing a click on a button, the time display will update to
    // take on that button's digit text, and so withDigit() will return a matcher
    // that matches multiple views with that digit text: the button
    // itself and the time display. This will prevent us from performing
    // validation on the same ViewInteractions later.
    buttonsInteractions[0] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text10));
    buttonsInteractions[1] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text0));
    buttonsInteractions[2] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text1));
    buttonsInteractions[3] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text2));
    buttonsInteractions[4] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text3));
    buttonsInteractions[5] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text4));
    buttonsInteractions[6] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text5));
    buttonsInteractions[7] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text6));
    buttonsInteractions[8] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text7));
    buttonsInteractions[9] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text8));
    return buttonsInteractions;
}
项目:NumberPadTimePicker    文件:NumberPadTimePickerDialogTest.java   
private static void verifyViewEnabledStates(TestCase test) {
    ViewInteraction[] buttonsInteractions = getButtonInteractions();
    ViewInteraction[] altButtonsInteractions = getAltButtonInteractions();
    for (int digit : test.sequence) {
        buttonsInteractions[digit]
                .check(ViewAssertions.matches(ViewMatchers.isEnabled()))
                .perform(ViewActions.click());
    }
    for (int i = 0; i < 10; i++) {
        buttonsInteractions[i].check(matchesIsEnabled(
                i >= test.numberKeysEnabledStart && i < test.numberKeysEnabledEnd));
        altButtonsInteractions[0].check(matchesIsEnabled(test.leftAltKeyEnabled));
        altButtonsInteractions[1].check(matchesIsEnabled(test.rightAltKeyEnabled));
    }

    Espresso.onView(ViewMatchers.withText(android.R.string.ok))
            .check(matchesIsEnabled(test.okButtonEnabled));

    ViewInteraction backspaceInteraction = Espresso.onView(
            ViewMatchers.withId(R.id.nptp_backspace));
    // Reset after each iteration by backspacing on the button just clicked.
    backspaceInteraction.check(matchesIsEnabled(true))
            .perform(ViewActions.longClick())
            .check(matchesIsEnabled(false));
}
项目:MathView    文件:MainActivityTest.java   
@Test
public void mainActivityTest() throws Throwable {
  ViewInteraction webView = onView(
    allOf(childAtPosition(
      allOf(withId(R.id.activity_main),
        childAtPosition(
          withId(android.R.id.content),
          0)),
      0),
      isDisplayed()));
  webView.check(matches(isDisplayed()));

  ViewInteraction editText = onView(
    allOf(withId(R.id.input_view),
      childAtPosition(
        allOf(withId(R.id.activity_main),
          childAtPosition(
            withId(android.R.id.content),
            0)),
        1),
      isDisplayed()));
  editText.check(matches(isDisplayed()));
}
项目:ChipsLayoutManager    文件:FewChipsRowTest.java   
@Test
public void deleteItemInTheFirstLine_ItemHasMaximumHeight_SameStartPadding() throws Exception {
    //arrange
    //just adapt input items list to required start values
    items.remove(1);
    activity.runOnUiThread(() -> activity.initialize());

    ViewInteraction recyclerView = onView(withId(R.id.rvTest)).check(matches(isDisplayed()));

    InstrumentalUtil.waitForIdle();

    View second = layoutManager.getChildAt(1);
    int startHeight = second.getHeight();
    double expectedY = second.getY();

    //act
    recyclerView.perform(
            actionDelegate(((uiController, view) -> items.remove(1))),
            notifyItemRemovedAction(1));

    InstrumentalUtil.waitForIdle();

    second = layoutManager.getChildAt(1);
    int endHeight = second.getHeight();
    double resultY = second.getY();

    //assert
    //check test behaviour
    assumeTrue(startHeight > endHeight);

    assertNotEquals(0, expectedY, 0.01);
    assertNotEquals(0, resultY, 0.01);
    assertEquals(resultY, expectedY, 0.01);
}
项目:TitanCompanion    文件:TCBaseTest.java   
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();
}
项目:frogment    文件:DefiningInitialFragmentWithState.java   
@Test
public void definingInitialFragmentWithState() {
    ViewInteraction appCompatButton = onView(
            allOf(withId(R.id.defining_initial_fragment_with_state), withText("Defining initial fragment with state"),
                    childAtPosition(
                            childAtPosition(
                                    withId(android.R.id.content),
                                    0),
                            4),
                    isDisplayed()));
    appCompatButton.perform(click());

    ViewInteraction textView = onView(
            allOf(withId(R.id.value), withText("100"),
                    childAtPosition(
                            childAtPosition(
                                    withId(R.id.fragment_container),
                                    0),
                            0),
                    isDisplayed()));
    textView.check(matches(withText("100")));

}
项目:SimpleMarkdown    文件:AutosaveTest.java   
private void openFile(String fileName) {
    openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());

    ViewInteraction openMenuItem = onView(
            allOf(withId(R.id.title), withText("Open"),
                    childAtPosition(
                            childAtPosition(
                                    withClassName(is("android.support.v7.view.menu.ListMenuItemView")),
                                    0),
                            0),
                    isDisplayed()));
    openMenuItem.perform(click());

    onView(withText(fileName))
            .perform(click());
}
项目:TitanCompanion    文件:TestSA.java   
public void performChooseWeapons() {

        ViewInteraction button4 = onView(
                allOf(withId(R.id.buttonAddweapon), withText("Add Weapon"),
                        childAtPosition(
                                withParent(withId(R.id.pager)),
                                1),
                        isDisplayed()));
        button4.perform(click());

        ViewInteraction button5 = onView(
                allOf(withId(android.R.id.button1), withText("Ok"),
                        childAtPosition(
                                childAtPosition(
                                        withClassName(is("android.widget.LinearLayout")),
                                        0),
                                2),
                        isDisplayed()));
        button5.perform(click());
    }
项目:frogment    文件:DefiningInitialFragmentTest.java   
@Test
public void definingInitialFragmentTest() {
    ViewInteraction appCompatButton = onView(
            allOf(withId(R.id.defining_initial_fragment), withText("Defining initial fragment"),
                    childAtPosition(
                            childAtPosition(
                                    withId(android.R.id.content),
                                    0),
                            3),
                    isDisplayed()));
    appCompatButton.perform(click());

    ViewInteraction textView = onView(
            allOf(withText("2"),
                    childAtPosition(
                            childAtPosition(
                                    withId(R.id.fragment_container),
                                    0),
                            0),
                    isDisplayed()));
    textView.check(matches(withText("2")));

}
项目:TurboChat    文件:TeamActivityStartTest.java   
@Test
public void shouldHaveTitleAndSubtitle() {
    ViewInteraction textView = onView(
            allOf(withText("Turbo Chat"),
                    childAtPosition(
                            allOf(withId(R.id.toolbar),
                                    childAtPosition(
                                            IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
                                            0)),
                            0),
                    isDisplayed()));
    textView.check(matches(withText("Turbo Chat")));

    ViewInteraction textView2 = onView(
            allOf(withText("Teams"),
                    childAtPosition(
                            allOf(withId(R.id.toolbar),
                                    childAtPosition(
                                            IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
                                            0)),
                            1),
                    isDisplayed()));
    textView2.check(matches(withText("Teams")));

}
项目:BizareChat    文件:LoginScreenErrorTest.java   
@Test
public void checkDisabledButtonSend() {
    onView(withId(R.id.forgot_password)).perform(click());
    onView(withId(android.R.id.button1)).check(matches(not(isEnabled())));

    ViewInteraction email = onView(
            allOf(withClassName(is("android.support.design.widget.TextInputEditText")),
                    withParent(allOf(withId(R.id.custom),
                            withParent(withId(R.id.customPanel)))),
                    isDisplayed()));
    email.perform(replaceText("йцкк"), closeSoftKeyboard());
    onView(withId(android.R.id.button1)).check(matches((isEnabled())));

    email.perform(replaceText(""), closeSoftKeyboard());
    onView(withId(android.R.id.button1)).check(matches(not(isEnabled())));

    onView(withId(android.R.id.button2)).perform(click());

}
项目:Expert-Android-Programming    文件:SplashActivityTest.java   
@Test
public void verifyMessageSentToMessageActivity() {

    ViewInteraction appCompatTextView2 = onView(
            allOf(withId(R.id.subtitle), withText("NEARBY"), isDisplayed()));
    appCompatTextView2.perform(click());

    // Types a message into a EditText element.
    onView(withId(R.id.searchText))
            .perform(typeText(MESSAGE), closeSoftKeyboard());


    //onView(withId(R.id.submit)).perform(click());

    // Verifies that the DisplayMessageActivity received an intent
    // with the correct package name and message.
    // Check that the text was changed.
    onView(withId(R.id.subtitle))
            .check(matches(withText(MESSAGE)));

}
项目:civify-app    文件:DrawerActivityTest.java   
private void openDrawerAndClickItem(String text) {
    ViewInteraction appCompatImageButton = onView(
            allOf(withContentDescription("Open navigation profile"),
                    withParent(allOf(withId(R.id.toolbar),
                            withParent(withId(R.id.bar_layout)))),
                    isDisplayed()));
    appCompatImageButton.perform(click());

    ViewInteraction appCompatCheckedTextView = onView(
            allOf(withId(R.id.design_menu_item_text), withText(text), isDisplayed()));
    appCompatCheckedTextView.perform(click());
}
项目:civify-app    文件:RewardsFragmentTest.java   
@Test
public void testAvailableRewards() throws ParseException {
    ViewInteraction appCompatImageButton =
            onView(allOf(withContentDescription("Open navigation profile"), withParent(
                    allOf(withId(R.id.toolbar), withParent(withId(R.id.bar_layout)))),
                    isDisplayed()));
    appCompatImageButton.perform(click());

    ViewInteraction appCompatCheckedTextView =
            onView(allOf(withId(R.id.design_menu_item_text), withText("Rewards"),
                    isDisplayed()));
    appCompatCheckedTextView.perform(click());

    pressBack();
}
项目:civify-app    文件:LoginActivityTest.java   
@Test public void loginActivityTest() {
    ViewInteraction textView = onView(allOf(withId(R.id.title), withText("Sign in"),
            childAtPosition(allOf(withId(R.id.intro_background),
                    childAtPosition(withId(android.R.id.content), 0)), 0), isDisplayed()));
    textView.check(matches(withText("Sign in")));

    ViewInteraction linearLayout = onView(allOf(withId(R.id.edit_text_layout), childAtPosition(
            allOf(withId(R.id.intro_background),
                    childAtPosition(withId(android.R.id.content), 0)), 1), isDisplayed()));
    linearLayout.check(matches(isDisplayed()));

    ViewInteraction editText = onView(allOf(withId(R.id.login_email_input),
            childAtPosition(childAtPosition(withId(R.id.login_email_layout), 0), 0),
            isDisplayed()));
    editText.check(matches(isDisplayed()));

    ViewInteraction editText2 = onView(allOf(withId(R.id.login_password_input),
            childAtPosition(childAtPosition(withId(R.id.logi_password_layout), 0), 0),
            isDisplayed()));
    editText2.check(matches(isDisplayed()));

    ViewInteraction textView2 = onView(allOf(withId(R.id.login_forgot),
            withText("Have you forgotten your password?"), childAtPosition(
                    allOf(withId(R.id.intro_background),
                            childAtPosition(withId(android.R.id.content), 0)), 2),
            isDisplayed()));
    textView2.check(matches(withText("Have you forgotten your password?")));

    ViewInteraction button = onView(allOf(withId(R.id.bsignin), childAtPosition(
            allOf(withId(R.id.intro_background),
                    childAtPosition(withId(android.R.id.content), 0)), 3), isDisplayed()));
    button.check(matches(isDisplayed()));
}
项目:android-training-2017    文件:CalculatorAndroidTest.java   
@Test
public void testActivityRun() {
    calculatorActivity.launchActivity(new Intent());

    ViewInteraction calculateButton = onView(withId(R.id.calculate_button));
    calculateButton.check(matches(isDisplayed()));
    calculateButton.check(new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            if(view.isEnabled()) {
                throw new IllegalStateException("button enabled");
            }
        }
    });

    onView(withId(R.id.input_field_edit_text)).perform(typeText("1+2"));

    calculateButton.check(matches(isEnabled()));

    calculateButton.perform(click());

    /*onView(withId(R.id.result_text_view)).check(new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            if(!((TextView)view).getText().toString().equals("3")) {
                throw new IllegalStateException("result wrong. Aspected 3");
            }
        }
    });*/

}
项目:mongol-library    文件:MainActivityTest2.java   
@Test
public void mainActivityTest2() {
    ViewInteraction recyclerView = onView(
            allOf(withId(R.id.rvApiTestingList),
                    childAtPosition(
                            withId(R.id.activity_main),
                            0)));
    recyclerView.perform(actionOnItemAtPosition(0, click()));

}
项目:LocationTracking    文件:ScheduleActivityTest.java   
@Test
public void scheduleActivityTest() {
    ViewInteraction button = onView(
            allOf(withId(R.id.btn_cancel), withText("Cancel"), isDisplayed()));
    button.perform(click());

    ViewInteraction button2 = onView(
            allOf(withId(R.id.btn_start_stop_shift), withText("Start shift"), isDisplayed()));
    button2.perform(click());

    ViewInteraction button3 = onView(
            allOf(withId(R.id.btn_yes), withText("OK"), isDisplayed()));
    button3.perform(click());

    ViewInteraction button4 = onView(
            allOf(withId(R.id.btn_start_stop_shift), withText("Start shift"), isDisplayed()));
    button4.perform(click());

    ViewInteraction button5 = onView(
            allOf(withId(R.id.btn_start_stop_shift), withText("Stop shift"), isDisplayed()));
    button5.perform(click());

    ViewInteraction button6 = onView(
            allOf(withId(R.id.btn_yes), withText("OK"), isDisplayed()));
    button6.perform(click());

}
项目:SgPSI    文件:PsiListActivityUITest.java   
@Test
public void verifySpinnerData() {
    ViewInteraction appCompatSpinner = onView(
            allOf(withId(R.id.psi_list_spinner), isDisplayed()));
    appCompatSpinner.perform(click());

    onView(withText("O3 SubIndex")).check(matches(isDisplayed()));
    onView(withText("PM10 24 Hourly")).check(matches(isDisplayed()));
    onView(withText("CO SubIndex")).check(matches(isDisplayed()));
    onView(withText("PM25 24 Hourly")).check(matches(isDisplayed()));
    onView(withText("CO 8 Hour Max")).check(matches(isDisplayed()));
    onView(withText("SO2 24 Hourly")).check(matches(isDisplayed()));
    onView(withText("PM25 SubIndex")).check(matches(isDisplayed()));
    onView(withText("PSI 24 Hourly")).check(matches(isDisplayed()));
    onView(withText("O3 8 Hour Max")).check(matches(isDisplayed()));
}
项目:Rotate3d    文件:MainActivityTest.java   
@Test
public void mainActivityTest() {
    ViewInteraction frameLayout = onView(
            allOf(withId(R.id.fragment_container_0), isDisplayed()));
    frameLayout.perform(click());

    ViewInteraction frameLayout2 = onView(
            allOf(withId(R.id.fragment_container_1), isDisplayed()));
    frameLayout2.perform(click());

    ViewInteraction frameLayout3 = onView(
            allOf(withId(R.id.fragment_container_2), isDisplayed()));
    frameLayout3.perform(click());

    ViewInteraction frameLayout4 = onView(
            allOf(withId(R.id.fragment_container_3), isDisplayed()));
    frameLayout4.perform(click());

    ViewInteraction frameLayout5 = onView(
            allOf(withId(R.id.fragment_container_1), isDisplayed()));
    frameLayout5.perform(click());

    ViewInteraction frameLayout6 = onView(
            allOf(withId(R.id.fragment_container_3), isDisplayed()));
    frameLayout6.perform(click());

    ViewInteraction frameLayout7 = onView(
            allOf(withId(R.id.fragment_container_0), isDisplayed()));
    frameLayout7.perform(click());

    ViewInteraction frameLayout8 = onView(
            allOf(withId(R.id.fragment_container_2), isDisplayed()));
    frameLayout8.perform(click());

}
项目:encryptedprefs    文件:SharedPreferencesReadWriteTest.java   
@Test
public void testString() {
  ViewInteraction appCompatButton = onView(
      allOf(withText("String"),
          withParent(allOf(ViewMatchers.withId(R.id.activity_main),
              withParent(withId(android.R.id.content)))),
          isDisplayed()));
  appCompatButton.perform(click());
}
项目:encryptedprefs    文件:SharedPreferencesReadWriteTest.java   
@Test
public void testStringSet() {
  ViewInteraction appCompatButton2 = onView(
      allOf(withText("StringSet"),
          withParent(allOf(ViewMatchers.withId(R.id.activity_main),
              withParent(withId(android.R.id.content)))),
          isDisplayed()));
  appCompatButton2.perform(click());
}
项目:encryptedprefs    文件:SharedPreferencesReadWriteTest.java   
@Test
public void testInt() {
  ViewInteraction appCompatButton3 = onView(
      allOf(withText("Int"),
          withParent(allOf(ViewMatchers.withId(R.id.activity_main),
              withParent(withId(android.R.id.content)))),
          isDisplayed()));
  appCompatButton3.perform(click());
}
项目:encryptedprefs    文件:SharedPreferencesReadWriteTest.java   
@Test
public void testLong() {
  ViewInteraction appCompatButton4 = onView(
      allOf(withText("Long"),
          withParent(allOf(ViewMatchers.withId(R.id.activity_main),
              withParent(withId(android.R.id.content)))),
          isDisplayed()));
  appCompatButton4.perform(click());
}
项目:starcraft-2-build-player    文件:ScreenshotFlowTest.java   
private void openExpansionSpinner() {
    ViewInteraction appCompatSpinner = onView(
            allOf(withId(R.id.toolbar_expansion_spinner),
                    withParent(withId(R.id.toolbar)),
                    isDisplayed()));
    appCompatSpinner.perform(click());
}
项目:kfaryarok-android    文件:AboutActivityInstrumentedTest.java   
@SuppressLint("ApplySharedPref")
@Test
public void devModeEasterEggOffWorking() {
    Context appContext = InstrumentationRegistry.getTargetContext();
    ViewInteraction interact = onView(withId(R.id.btn_about_advancedmode_easteregg));
    PreferenceUtil.getSharedPreferences(appContext).edit().putBoolean(appContext.getString(R.string.pref_advanced_mode_bool), true).commit();
    InstrumentationRegistry.getInstrumentation().startActivitySync(new Intent(appContext, AboutActivity.class));

    interact.perform(click());

    Assert.assertThat(PreferenceUtil.getDeveloperModePreference(appContext), is(false));
}
项目:encryptedprefs    文件:SharedPreferencesReadWriteTest.java   
@Test
public void testMissing() {

  ViewInteraction appCompatButton10 = onView(
      allOf(withText("missing"),
          withParent(allOf(ViewMatchers.withId(R.id.activity_main),
              withParent(withId(android.R.id.content)))),
          isDisplayed()));
  appCompatButton10.perform(click());
}
项目:encryptedprefs    文件:SharedPreferencesReadWriteTest.java   
@Test
public void testRegisterListener() {

  ViewInteraction appCompatButton8 = onView(
      allOf(withText("registerListener"),
          withParent(allOf(ViewMatchers.withId(R.id.activity_main),
              withParent(withId(android.R.id.content)))),
          isDisplayed()));
  appCompatButton8.perform(click());
}
项目:ChipsLayoutManager    文件:FewChipsColumnTest.java   
@Test
public void wrapContent_HeightIsWrapContent_DeletedLastItemInLastRowCauseHeightToDecrease() throws Exception {
    //arrange
    activity.runOnUiThread(() -> activity.initialize());
    final RecyclerView[] rvTest = new RecyclerView[1];

    ViewInteraction recyclerView = onView(withId(R.id.rvTest)).check(matches(isDisplayed()));
    ViewAction viewAction = actionDelegate(((uiController, view) -> {
        rvTest[0] = view;
        view.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
        view.requestLayout();
    }));

    recyclerView.perform(viewAction);

    int startWidth = rvTest[0].getHeight();

    //act
    recyclerView.perform(
            actionDelegate(((uiController, view) -> items.remove(9))),
            notifyItemRemovedAction(9));
    InstrumentalUtil.waitForIdle();

    //assert
    int endWidth = rvTest[0].getWidth();
    System.out.println(String.format(Locale.getDefault(), "start height = %d, end height = %d", startWidth, endWidth));
    assertTrue(endWidth < startWidth);
}
项目:ChipsLayoutManager    文件:FewChipsColumnTest.java   
@Test
public void deleteItemInTheFirstLine_ItemHasMaximumWidth_SameStartPadding() throws Exception {
    //arrange
    {
        //just adapt input items list to required start values
        items.remove(1);
        items.remove(9);
        ChipsEntity longItem = items.remove(8);
        items.add(1, longItem);
    }

    activity.runOnUiThread(() -> activity.initialize());
    ViewInteraction recyclerView = onView(withId(R.id.rvTest)).check(matches(isDisplayed()));
    //just adapt input items list to required start values

    InstrumentalUtil.waitForIdle();

    View second = layoutManager.getChildAt(1);
    double expectedX = second.getX();

    //act
    recyclerView.perform(
            actionDelegate(((uiController, view) -> items.remove(1))),
            notifyItemRemovedAction(1));

    InstrumentalUtil.waitForIdle();

    second = layoutManager.getChildAt(5);
    double resultX = second.getX();

    //assert
    assertNotEquals(0, expectedX, 0.01);
    assertNotEquals(0, resultX, 0.01);
    assertEquals(resultX, expectedX, 0.01);
}
项目:espresso-sample-for-droidkaigi2017    文件:Step2.java   
@Test
public void mainActivityTest() {
    ViewInteraction appCompatImageButton = onView(
            allOf(withContentDescription("Open navigation drawer"),
                    withParent(withId(R.id.toolbar)),
                    isDisplayed()));
    appCompatImageButton.perform(click());

    ViewInteraction appCompatCheckedTextView = onView(
            allOf(withId(R.id.design_menu_item_text), withText("Articles"), isDisplayed()));
    appCompatCheckedTextView.perform(click());

    onView(withId(R.id.recyclerView))
            .perform(RecyclerViewActions.actionOnItemAtPosition(1, RecyclerViewUtils.clickDescendantViewWithId(R.id.checkbox_fav)));

    onView(allOf(isDescendantOfA(RecyclerViewUtils.withItemViewAtPosition(withId(R.id.recyclerView), 1)),
            withId(R.id.checkbox_fav))).check(matches(isChecked()));

    ViewInteraction appCompatImageButton2 = onView(
            allOf(withContentDescription("Open navigation drawer"),
                    withParent(withId(R.id.toolbar)),
                    isDisplayed()));
    appCompatImageButton2.perform(click());

    ViewInteraction appCompatCheckedTextView2 = onView(
            allOf(withId(R.id.design_menu_item_text), withText("Local Favorites"), isDisplayed()));
    appCompatCheckedTextView2.perform(click());


    onView(RecyclerViewUtils.withItemViewAtPosition(withId(R.id.recyclerView), 0))
            .check(matches(isDisplayed()));
}
项目:TitanCompanion    文件:TCBaseTest.java   
@Before
public void dismissStartupDialog() {
    ViewInteraction button = onView(
            allOf(withId(android.R.id.button2), withText("Close"),
                    childAtPosition(
                            childAtPosition(
                                    withClassName(is("android.widget.LinearLayout")),
                                    0),
                            0),
                    isDisplayed()));

    if (exists(button))
        button.perform(click());
}
项目:espresso-sample-for-droidkaigi2017    文件:Step3.java   
private void goArticleList() {
    ViewInteraction appCompatImageButton = onView(
            allOf(withContentDescription("Open navigation drawer"),
                    withParent(withId(R.id.toolbar)),
                    isDisplayed()));
    appCompatImageButton.perform(click());

    ViewInteraction appCompatCheckedTextView = onView(
            allOf(withId(R.id.design_menu_item_text), withText("Articles"), isDisplayed()));
    appCompatCheckedTextView.perform(click());
}
项目:dagger-test-example    文件:SimpleEspressoTest.java   
@Test
public void testSearchIsInvokedWhenSubmittingInSearchView() {
    CountDownLatch latch = new CountDownLatch(1);
    app().mainActivitySubcomponent()
                .withPermissionService(activity -> new PermissionServiceStub(activity, false))
              .and().searchFragmentSubcomponent()
                .withSearchViewModel(new SearchViewModelStubDelegate(latch));

    rule.launchActivity(null);
    this.allowPermissionsIfNeeded();

    ViewInteraction viewPager = onView(allOf(withId(R.id.container), isDisplayed()));
    viewPager.perform(swipeLeft());

    ViewInteraction appCompatTextView = onView(allOf(withText("Search"), isDisplayed()));
    appCompatTextView.perform(click());

    ViewInteraction actionMenuItemView = onView(allOf(withId(R.id.action_search), isDisplayed()));
    actionMenuItemView.perform(click());

    ViewInteraction searchAutoComplete = onView(
            allOf(withId(R.id.search_src_text),
                    withParent(allOf(withId(R.id.search_plate),
                            withParent(withId(R.id.search_edit_frame)))),
                    isDisplayed()));
    searchAutoComplete.perform(replaceText("AAA"));

    SystemClock.sleep(1500);

    assertEquals(0, latch.getCount());
}
项目:SimpleMarkdown    文件:AutosaveTest.java   
private void saveFile(String fileName) {
    openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());

    ViewInteraction appCompatTextView = onView(
            allOf(withId(R.id.title), withText("Save"),
                    childAtPosition(
                            childAtPosition(
                                    withClassName(is("android.support.v7.view.menu.ListMenuItemView")),
                                    0),
                            0),
                    isDisplayed()));
    appCompatTextView.perform(click());

    ViewInteraction appCompatEditText = onView(
            allOf(withId(R.id.file_name),
                    childAtPosition(
                            childAtPosition(
                                    withId(android.R.id.content),
                                    0),
                            3),
                    isDisplayed()));
    appCompatEditText.perform(replaceText(fileName));

    appCompatEditText.perform(closeSoftKeyboard());

    ViewInteraction appCompatButton = onView(
            allOf(withId(R.id.button_save),
                    childAtPosition(
                            childAtPosition(
                                    withId(android.R.id.content),
                                    0),
                            4),
                    isDisplayed()));
    appCompatButton.perform(click());
}
项目:frogment    文件:SimpleImplementationTest.java   
@Test
public void simpleImplementationTest() {
    ViewInteraction appCompatButton = onView(
            allOf(withId(R.id.simple_implementation), withText("Simple implementation"),
                    childAtPosition(
                            childAtPosition(
                                    withId(android.R.id.content),
                                    0),
                            0),
                    isDisplayed()));
    appCompatButton.perform(click());

}
项目:LoggingInterceptor    文件:InterceptorsTest.java   
@Test
public void interceptorsFileTest() {
    ViewInteraction buttonPost = onView(
            allOf(withId(R.id.button_pdf), withText("FILE"), isDisplayed()));
    buttonPost.perform(click());
    buttonPost.check(matches(isDisplayed()));
}