當前位置: 首頁>>代碼示例>>Java>>正文


Java ViewInteraction類代碼示例

本文整理匯總了Java中android.support.test.espresso.ViewInteraction的典型用法代碼示例。如果您正苦於以下問題:Java ViewInteraction類的具體用法?Java ViewInteraction怎麽用?Java ViewInteraction使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ViewInteraction類屬於android.support.test.espresso包,在下文中一共展示了ViewInteraction類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: verifyViewEnabledStates

import android.support.test.espresso.ViewInteraction; //導入依賴的package包/類
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));
}
 
開發者ID:philliphsu,項目名稱:NumberPadTimePicker,代碼行數:26,代碼來源:NumberPadTimePickerDialogTest.java

示例2: swipeOnView

import android.support.test.espresso.ViewInteraction; //導入依賴的package包/類
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;
    }
}
 
開發者ID:cuplv,項目名稱:ChimpCheck,代碼行數:35,代碼來源:FingerGestures.java

示例3: swipeOnCoord

import android.support.test.espresso.ViewInteraction; //導入依賴的package包/類
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;
    }

}
 
開發者ID:cuplv,項目名稱:ChimpCheck,代碼行數:21,代碼來源:FingerGestures.java

示例4: mainActivityTest2

import android.support.test.espresso.ViewInteraction; //導入依賴的package包/類
@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());

}
 
開發者ID:talhahasanzia,項目名稱:android-testing-sample,代碼行數:24,代碼來源:MainActivityTest2.java

示例5: getButtonInteractions

import android.support.test.espresso.ViewInteraction; //導入依賴的package包/類
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;
}
 
開發者ID:philliphsu,項目名稱:NumberPadTimePicker,代碼行數:21,代碼來源:NumberPadTimePickerDialogTest.java

示例6: mainActivityTest

import android.support.test.espresso.ViewInteraction; //導入依賴的package包/類
@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()));
}
 
開發者ID:Nishant-Pathak,項目名稱:MathView,代碼行數:24,代碼來源:MainActivityTest.java

示例7: deleteItemInTheFirstLine_ItemHasMaximumHeight_SameStartPadding

import android.support.test.espresso.ViewInteraction; //導入依賴的package包/類
@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);
}
 
開發者ID:sathishmscict,項目名稱:ChipsLayoutManager,代碼行數:35,代碼來源:FewChipsRowTest.java

示例8: performStartAdventure

import android.support.test.espresso.ViewInteraction; //導入依賴的package包/類
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();
}
 
開發者ID:joaomneto,項目名稱:TitanCompanion,代碼行數:20,代碼來源:TCBaseTest.java

示例9: definingInitialFragmentWithState

import android.support.test.espresso.ViewInteraction; //導入依賴的package包/類
@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")));

}
 
開發者ID:grzechu92,項目名稱:frogment,代碼行數:24,代碼來源:DefiningInitialFragmentWithState.java

示例10: openFile

import android.support.test.espresso.ViewInteraction; //導入依賴的package包/類
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());
}
 
開發者ID:wbrawner,項目名稱:SimpleMarkdown,代碼行數:17,代碼來源:AutosaveTest.java

示例11: performChooseWeapons

import android.support.test.espresso.ViewInteraction; //導入依賴的package包/類
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());
    }
 
開發者ID:joaomneto,項目名稱:TitanCompanion,代碼行數:21,代碼來源:TestSA.java

示例12: definingInitialFragmentTest

import android.support.test.espresso.ViewInteraction; //導入依賴的package包/類
@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")));

}
 
開發者ID:grzechu92,項目名稱:frogment,代碼行數:24,代碼來源:DefiningInitialFragmentTest.java

示例13: shouldHaveTitleAndSubtitle

import android.support.test.espresso.ViewInteraction; //導入依賴的package包/類
@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")));

}
 
開發者ID:charafau,項目名稱:TurboChat,代碼行數:26,代碼來源:TeamActivityStartTest.java

示例14: checkDisabledButtonSend

import android.support.test.espresso.ViewInteraction; //導入依賴的package包/類
@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());

}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:20,代碼來源:LoginScreenErrorTest.java

示例15: verifyMessageSentToMessageActivity

import android.support.test.espresso.ViewInteraction; //導入依賴的package包/類
@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)));

}
 
開發者ID:PacktPublishing,項目名稱:Expert-Android-Programming,代碼行數:22,代碼來源:SplashActivityTest.java


注:本文中的android.support.test.espresso.ViewInteraction類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。