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


Java ViewActions類代碼示例

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


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

示例1: verifyViewEnabledStates

import android.support.test.espresso.action.ViewActions; //導入依賴的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: checkRealApiResponse

import android.support.test.espresso.action.ViewActions; //導入依賴的package包/類
@Test
public void checkRealApiResponse() throws Exception {
    WikiHelper.BASE_WIKI_URL = "https://en.wikipedia.org/w/";
    openActivity();

    //Wait for the api call
    Delay.startDelay(TestConfig.DELAY_FOR_REAL_API);
    onView(withId(R.id.root_view)).perform(ViewActions.closeSoftKeyboard());

    //Check if there are text?
    assertTrue(mWikiFragmentFragmentTestRule.getActivity().mViewFlipper.getDisplayedChild() ==
            INFO_VIEW);
    onView(withId(R.id.wiki_page_tv)).check(ViewAssertions.matches(CustomMatchers.hasText()));
    onView(withId(R.id.wiki_page_iv)).check(ViewAssertions.matches(CustomMatchers.hasImage()));
    Delay.stopDelay();
}
 
開發者ID:kevalpatel2106,項目名稱:smart-lens,代碼行數:17,代碼來源:InfoActivityTest.java

示例3: checkImageApiResponseFail

import android.support.test.espresso.action.ViewActions; //導入依賴的package包/類
@Test
public void checkImageApiResponseFail() throws Exception {
    MockWebServer mockWebServer = startMockWebServer();
    //Success response for the info api
    mockWebServer.enqueue(new MockResponse()
            .setResponseCode(200)
            .setBody(getStringFromFile(InstrumentationRegistry.getInstrumentation().getContext(),
                    com.kevalpatel2106.smartlens.test.R.raw.wiki_info_success_response)));
    //Fail response for the image api.
    mockWebServer.enqueue(new MockResponse().setResponseCode(500));
    openActivity();

    //Wait for mock api
    Delay.startDelay(TestConfig.DELAY_FOR_MOCK_API);
    onView(withId(R.id.root_view)).perform(ViewActions.closeSoftKeyboard());

    //Check if there are text?
    assertTrue(mWikiFragmentFragmentTestRule.getActivity().mViewFlipper.getDisplayedChild() ==
            INFO_VIEW);
    onView(withId(R.id.wiki_page_tv)).check(ViewAssertions.matches(CustomMatchers.hasText()));
    onView(withId(R.id.wiki_page_iv)).check(ViewAssertions.matches(not(CustomMatchers.hasImage())));

    Delay.stopDelay();
    mockWebServer.shutdown();
}
 
開發者ID:kevalpatel2106,項目名稱:smart-lens,代碼行數:26,代碼來源:InfoActivityTest.java

示例4: testSwipeDownToHide

import android.support.test.espresso.action.ViewActions; //導入依賴的package包/類
@Test
@MediumTest
public void testSwipeDownToHide() {
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              ViewActions.swipeDown(), ViewMatchers.isDisplayingAtLeast(5)));
  registerIdlingResourceCallback();
  try {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(not(ViewMatchers.isDisplayed())));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_HIDDEN));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
開發者ID:material-components,項目名稱:material-components-android,代碼行數:17,代碼來源:BottomSheetBehaviorTest.java

示例5: checkInfoNotFoundApiResponse

import android.support.test.espresso.action.ViewActions; //導入依賴的package包/類
@Test
public void checkInfoNotFoundApiResponse() throws Exception {
    MockWebServer mockWebServer = startMockWebServer();
    //Success response for the info api
    mockWebServer.enqueue(new MockResponse()
            .setResponseCode(200)
            .setBody(getStringFromFile(InstrumentationRegistry.getInstrumentation().getContext(),
                    com.kevalpatel2106.smartlens.test.R.raw.wiki_info_not_found_success_response)));
    //Success response for the image api.
    mockWebServer.enqueue(new MockResponse()
            .setResponseCode(200)
            .setBody(getStringFromFile(InstrumentationRegistry.getInstrumentation().getContext(),
                    com.kevalpatel2106.smartlens.test.R.raw.wiki_image_success_response)));
    openActivity();

    //Wait for mock api
    Delay.startDelay(TestConfig.DELAY_FOR_MOCK_API);
    onView(withId(R.id.root_view)).perform(ViewActions.closeSoftKeyboard());

    //Check if is error?
    assertTrue(mWikiFragmentFragmentTestRule.getActivity().mViewFlipper.getDisplayedChild() ==
            ERROR_VIEW);

    Delay.stopDelay();
    mockWebServer.shutdown();
}
 
開發者ID:kevalpatel2106,項目名稱:smart-lens,代碼行數:27,代碼來源:InfoActivityTest.java

示例6: checkInfoApiResponseFail

import android.support.test.espresso.action.ViewActions; //導入依賴的package包/類
@Test
public void checkInfoApiResponseFail() throws Exception {
    MockWebServer mockWebServer = startMockWebServer();
    //Fail response for the info api.
    mockWebServer.enqueue(new MockResponse().setResponseCode(500));
    //Success response for the image api.
    mockWebServer.enqueue(new MockResponse()
            .setResponseCode(200)
            .setBody(getStringFromFile(InstrumentationRegistry.getInstrumentation().getContext(),
                    com.kevalpatel2106.smartlens.test.R.raw.wiki_image_success_response)));
    openActivity();

    //Wait for mock api
    Delay.startDelay(TestConfig.DELAY_FOR_MOCK_API);
    onView(withId(R.id.root_view)).perform(ViewActions.closeSoftKeyboard());

    //Check if error occurred?
    assertTrue(mWikiFragmentFragmentTestRule.getActivity().mViewFlipper.getDisplayedChild() ==
            ERROR_VIEW);

    Delay.stopDelay();
    mockWebServer.shutdown();
}
 
開發者ID:kevalpatel2106,項目名稱:smart-lens,代碼行數:24,代碼來源:InfoActivityTest.java

示例7: openAd

import android.support.test.espresso.action.ViewActions; //導入依賴的package包/類
@Test
    public void openAd() {

        try {
            Thread.sleep(20000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        onView(ViewMatchers.withId(R.id.buttonShowAd))
                .perform(ViewActions.click());

//        intended(allOf(
//                hasComponent(hasShortClassName("AdSimasFullActivity"))
//        ));

        onView(ViewMatchers.withText("hardMOB - Promoções"));
    }
 
開發者ID:leosimas,項目名稱:AdSimasTeam,代碼行數:19,代碼來源:ShowAds.java

示例8: testWebViewUpdateElementByDisplayed

import android.support.test.espresso.action.ViewActions; //導入依賴的package包/類
@Test
public void testWebViewUpdateElementByDisplayed() throws Exception {
    String go = MainFragment.DEFAULT_URL;

    onView(withId(R.id.et_url)).perform(clearText());
    onView(withId(R.id.et_url)).perform(typeText(go)).perform(ViewActions.pressImeActionButton());

    waitWebViewLoad();

    onView(withId(R.id.et_keyword)).perform(clearText()).perform(typeText(JAVASCRIPT_CALL));
    onView(withId(R.id.btn_search)).perform(click());

    onWebView()
            // Find the message element by ID
            .withElement(findElement(Locator.ID, "message"))
            // Verify that the text is displayed
            .check(webMatches(getText(), containsString(JAVASCRIPT_CALL)));
}
 
開發者ID:taehwandev,項目名稱:Android-BlogExample,代碼行數:19,代碼來源:MainFragmentTest.java

示例9: testCanAddNewMeal

import android.support.test.espresso.action.ViewActions; //導入依賴的package包/類
@Test
public void testCanAddNewMeal() {
    onView(withId(R.id.fab_expand_menu_button)).perform(click());
    onView(withId(R.id.overview_fab_add_meal)).perform(click());
    intended(hasComponent(new ComponentName(getTargetContext(), AddMealActivity.class)));
    onView(withId(R.id.add_meal_content)).check(matches(isDisplayed()));
    onView(withId(R.id.add_meal_name)).perform(typeTextIntoFocusedView("Meal 3"));
    closeSoftKeyboard();
    onView(withId(R.id.add_meal_fab_add_ingredient)).perform(click());
    intended(hasComponent(new ComponentName(getTargetContext(), IngredientsActivity.class)));
    onView(allOf(withId(R.id.ingredients_content), isAssignableFrom(RecyclerView.class)))
            .check(matches(isDisplayed()));
    onView(withText(IngredientActivityTest.exampleIngredients[0].getName())).check(matches(isDisplayed()))
            .perform(click());
    intended(hasComponent(new ComponentName(getTargetContext(), IngredientDetailActivity.class)));
    onView(withText(IngredientActivityTest.exampleIngredients[0].getName())).check(matches(isDisplayed()));
    onView(withHint(R.string.add_meal_ingredient_amount_hint)).perform(click())
            .perform(typeTextIntoFocusedView("200"))
            .perform(ViewActions.closeSoftKeyboard());
    onView(withId(R.id.add_meal_ingredient_accept)).perform(click());
    onView(withText(R.string.add_meal_save_action)).perform(click());
    onView(ViewMatchers.withId(R.id.overview_fab_add_meal)).check(matches(isDisplayed()));
    onView(withText("Meal 3"))
            .check(matches(isDisplayed()));
}
 
開發者ID:st1hy,項目名稱:Red-Calorie,代碼行數:26,代碼來源:OverviewActivityTest.java

示例10: testAddNewTag

import android.support.test.espresso.action.ViewActions; //導入依賴的package包/類
@Test
    public void testAddNewTag() throws Exception {
        main.launchActivity(null);
        final String tagName = "My tag name";
        onView(ViewMatchers.withId(R.id.tags_fab_add_new)).check(matches(isDisplayed()))
                .perform(click());
        onView(withText(R.string.tags_new_tag_dialog)).check(matches(isDisplayed()));
        onView(withHint(R.string.tags_new_tag_hint)).check(matches(isDisplayed()))
                .perform(ViewActions.typeTextIntoFocusedView(tagName));
        onView(withText(tagName)).check(matches(isDisplayed()));
        onView(withText(android.R.string.ok)).check(matches(isDisplayed()))
                .perform(click());
        onView(withText(tagName)).check(matches(isDisplayed()));

//        onView(withText(R.string.tags_undo)).perform(click());
//        onView(withText(tagName)).check(doesNotExist());
    }
 
開發者ID:st1hy,項目名稱:Red-Calorie,代碼行數:18,代碼來源:TagsActivityTest.java

示例11: testErrorWithConfirmPasswordDifferentPassword

import android.support.test.espresso.action.ViewActions; //導入依賴的package包/類
public void testErrorWithConfirmPasswordDifferentPassword(){
    closeSoftKeyboard();
    onView(withId(R.id.registerText)).perform(ViewActions.scrollTo()).perform(click());
    onView(withId(R.id.firstNameField)).perform(typeText("aaaaa"));
    onView(withId(R.id.lastNameField)).perform(typeText("aaaaaa"));
    closeSoftKeyboard();
    onView(withId(R.id.emailField)).perform(typeText("[email protected]"));
    closeSoftKeyboard();
    onView(withId(R.id.passwordField)).perform(typeText("123456789"));
    closeSoftKeyboard();
    onView(withId(R.id.passwordConfirmationField)).perform(typeText("12345678"));
    closeSoftKeyboard();
    onView(withId(R.id.registerButton)).perform(ViewActions.scrollTo()).perform(click());

    onView(withId(R.id.passwordConfirmationField)).check(matches(hasErrorText("As senhas digitadas sao diferentes")));
}
 
開發者ID:fga-gpp-mds,項目名稱:2016.2-WikiLegis,代碼行數:17,代碼來源:RegisterUserFragmentTest.java

示例12: testEmailRepeatFields

import android.support.test.espresso.action.ViewActions; //導入依賴的package包/類
public void testEmailRepeatFields() throws InterruptedException {
    closeSoftKeyboard();
    onView(withId(R.id.registerText)).perform(ViewActions.scrollTo()).perform(click());
    onView(withId(R.id.firstNameField)).perform(typeText("Augusto"));
    onView(withId(R.id.lastNameField)).perform(typeText("Moreno"));
    closeSoftKeyboard();
    onView(withId(R.id.emailField)).perform(typeText("[email protected]"));
    closeSoftKeyboard();
    onView((withId(R.id.passwordField))).perform(typeText("12345678"));
    closeSoftKeyboard();
    onView(withId(R.id.passwordConfirmationField)).perform(typeText("12345678"));
    closeSoftKeyboard();
    onView(withId(R.id.registerButton)).perform(ViewActions.scrollTo()).perform(click());
    Thread.sleep(400);
    onView(withText("Email já cadastrado!")).inRoot(withDecorView(not(is(getActivity()
            .getWindow().getDecorView())))).check(matches(isDisplayed()));
}
 
開發者ID:fga-gpp-mds,項目名稱:2016.2-WikiLegis,代碼行數:18,代碼來源:RegisterUserFragmentTest.java

示例13: enterCardDetails

import android.support.test.espresso.action.ViewActions; //導入依賴的package包/類
public void enterCardDetails() throws InterruptedException {
    // Check that the sipping button appears
    onView(withId(R.id.buyNowButton))
            .check(matches(withText("Shipping")));

    onView(withId(R.id.creditCardNumberEditText))
            .perform(typeText(cardNumberGeneratorTest()), ViewActions.closeSoftKeyboard());

    CardFormTesterCommon.fillInAllFieldsWithValidCard();

    onView(withId(R.id.buyNowButton)).perform(click());
    Thread.sleep(2000);
    //TODO: check that the shipping activity is launched.
    CardFormTesterCommon.fillInShippingDetails();
    Thread.sleep(2000);
    onView(withId(R.id.shippingBuyNowButton)).perform(ViewActions.closeSoftKeyboard()).perform(click());
    //TOOD: Verify that flow returns to Payment


}
 
開發者ID:bluesnap,項目名稱:bluesnap-android-int,代碼行數:21,代碼來源:ShippingFlowTest.java

示例14: testWithOnlyWifiIfSelectedInActionBarWithUserLogged

import android.support.test.espresso.action.ViewActions; //導入依賴的package包/類
public void testWithOnlyWifiIfSelectedInActionBarWithUserLogged() {
    closeSoftKeyboard();
    onView(withId(R.id.emailLoginField)).perform(typeText("[email protected]"));
    closeSoftKeyboard();
    onView(withId(R.id.passwordLoginField)).perform(typeText("12345678"));
    closeSoftKeyboard();
    onView(withId(R.id.loginButton)).perform(ViewActions.scrollTo()).perform(click());

    onView(withId(R.id.action_profile_logged)).perform(click());
    onView(withText("Configurações de download")).perform(click());
    onView(withText("Apenas wifi")).perform(click());
    onView(withText("Confirmar")).perform(click());

    SharedPreferences session = PreferenceManager.
            getDefaultSharedPreferences(getActivity().getBaseContext());

    assertTrue(session.getInt("NetworkSettings", -1) == 0);
}
 
開發者ID:fga-gpp-mds,項目名稱:2016.2-WikiLegis,代碼行數:19,代碼來源:LoginFragmentTest.java

示例15: testWithWifiAndDataMobileIfSelectedInActionBarWithUserLogged

import android.support.test.espresso.action.ViewActions; //導入依賴的package包/類
public void testWithWifiAndDataMobileIfSelectedInActionBarWithUserLogged() {
    closeSoftKeyboard();
    onView(withId(R.id.emailLoginField)).perform(typeText("[email protected]"));
    closeSoftKeyboard();
    onView(withId(R.id.passwordLoginField)).perform(typeText("12345678"));
    closeSoftKeyboard();
    onView(withId(R.id.loginButton)).perform(ViewActions.scrollTo()).perform(click());

    onView(withId(R.id.action_profile_logged)).perform(click());
    onView(withText("Configurações de download")).perform(click());
    onView(withText("Wifi e dados")).perform(click());
    onView(withText("Confirmar")).perform(click());

    SharedPreferences session = PreferenceManager.
            getDefaultSharedPreferences(getActivity().getBaseContext());

    assertTrue(session.getInt("NetworkSettings", -1) == 1);
}
 
開發者ID:fga-gpp-mds,項目名稱:2016.2-WikiLegis,代碼行數:19,代碼來源:LoginFragmentTest.java


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