Search in sources :

Example 36 with ViewInteraction

use of android.support.test.espresso.ViewInteraction in project chefly_android by chef-ly.

the class FavoriteNavgationTest method favoriteNavgationTest.

@Test
public void favoriteNavgationTest() {
    ViewInteraction appCompatButton = onView(allOf(withId(R.id.skipBtn), withText("Skip"), isDisplayed()));
    appCompatButton.perform(click());
    // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    ViewInteraction appCompatTextView = onView(allOf(withId(R.id.continueAsGuest), withText("Skip"), withParent(allOf(withId(R.id.activity_main), withParent(withId(android.R.id.content)))), isDisplayed()));
    appCompatTextView.perform(click());
    // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
    try {
        Thread.sleep(10000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    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("Contact Us"), isDisplayed()));
    appCompatCheckedTextView.perform(click());
    // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    pressBack();
    // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    ViewInteraction appCompatImageButton2 = onView(allOf(withId(R.id.favBtn), withContentDescription("Favorite"), withParent(childAtPosition(withId(R.id.list), 0)), isDisplayed()));
    appCompatImageButton2.perform(click());
    ViewInteraction appCompatTextView2 = onView(allOf(withId(R.id.favortiesHeader), withText("Favorites"), isDisplayed()));
    appCompatTextView2.perform(click());
    ViewInteraction viewPager = onView(allOf(withId(R.id.viewpager), withParent(withId(R.id.activity_recipe_list)), isDisplayed()));
    viewPager.perform(swipeLeft());
    // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    ViewInteraction appCompatImageButton3 = onView(allOf(withContentDescription("Open navigation drawer"), withParent(withId(R.id.toolbar)), isDisplayed()));
    appCompatImageButton3.perform(click());
    ViewInteraction appCompatCheckedTextView2 = onView(allOf(withId(R.id.design_menu_item_text), withText("Ingredients Search"), isDisplayed()));
    appCompatCheckedTextView2.perform(click());
}
Also used : ViewInteraction(android.support.test.espresso.ViewInteraction) LargeTest(android.test.suitebuilder.annotation.LargeTest) Test(org.junit.Test)

Example 37 with ViewInteraction

use of android.support.test.espresso.ViewInteraction in project appium-espresso-driver by appium.

the class SendKeys method handle.

@Override
@Nullable
public Void handle(TextParams params) throws AppiumException {
    String id = params.getElementId();
    ViewInteraction viewInteraction = Element.getById(id);
    // Convert the array of text to a String
    String[] textArray = params.getValue();
    StringBuilder stringBuilder = new StringBuilder();
    for (String text : textArray) {
        stringBuilder.append(text);
    }
    String textValue = stringBuilder.toString();
    try {
        viewInteraction.perform(typeText(textValue));
    } catch (PerformException e) {
        throw new AppiumException("Could not apply sendKeys to element " + id + ": " + e.getMessage());
    }
    return null;
}
Also used : AppiumException(io.appium.espressoserver.lib.handlers.exceptions.AppiumException) ViewInteraction(android.support.test.espresso.ViewInteraction) PerformException(android.support.test.espresso.PerformException) Nullable(javax.annotation.Nullable)

Example 38 with ViewInteraction

use of android.support.test.espresso.ViewInteraction in project dagger-test-example by aschattney.

the class SimpleTest method itShouldShowWeatherForNextDay.

@Test
public void itShouldShowWeatherForNextDay() throws IOException {
    doReturn(Observable.empty()).when(weatherApi).getCurrentWeather(anyDouble(), anyDouble(), anyString(), anyString(), anyString());
    doReturn(Observable.empty()).when(weatherApi).getTomorrowWeather(anyDouble(), anyDouble(), anyString(), anyInt(), anyString(), anyString());
    when(weatherApi.getForecastWeather(eq(FAKE_LONGITUDE), eq(FAKE_LATITUDE), eq("metric"), eq("de"), anyString())).thenReturn(Observable.just(jsonToPojo(ThreeHoursForecastWeather.class, Responses.THREE_HOUR_FORECAST)));
    mActivity = rule.launchActivity(null);
    allowPermissionsIfNeeded();
    ViewInteraction appCompatTextView = onView(allOf(withText(R.string.tomorrow), isDisplayed()));
    appCompatTextView.perform(click());
    ViewInteraction appCompatImageView = onView(allOf(withId(R.id.imageView), isDisplayed()));
    appCompatImageView.perform(click());
    String threeHourForecastDataAsString = "2017-01-23 00:00:00: -11.55°C\n" + "2017-01-23 03:00:00: -12.0°C\n" + "2017-01-23 06:00:00: -12.15°C\n" + "2017-01-23 09:00:00: -11.34°C\n" + "2017-01-23 12:00:00: -8.84°C\n" + "2017-01-23 15:00:00: -7.94°C\n" + "2017-01-23 18:00:00: -9.35°C\n" + "2017-01-23 21:00:00: -10.29°C\n";
    ViewInteraction textView = onView(withId(R.id.textView));
    textView.check(matches(withText(threeHourForecastDataAsString)));
    ViewInteraction textView2 = onView(withId(R.id.textView6));
    textView2.check(matches(withText("Three Hour Forecast")));
}
Also used : ViewInteraction(android.support.test.espresso.ViewInteraction) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

ViewInteraction (android.support.test.espresso.ViewInteraction)38 Test (org.junit.Test)19 LargeTest (android.test.suitebuilder.annotation.LargeTest)13 Espresso.onView (android.support.test.espresso.Espresso.onView)5 View (android.view.View)5 NoMatchingViewException (android.support.test.espresso.NoMatchingViewException)4 RecyclerView (android.support.v7.widget.RecyclerView)4 ViewAction (android.support.test.espresso.ViewAction)2 ChipsEntity (com.beloo.chipslayoutmanager.sample.entity.ChipsEntity)2 InvalidStrategyException (io.appium.espressoserver.lib.handlers.exceptions.InvalidStrategyException)2 NoSuchElementException (io.appium.espressoserver.lib.handlers.exceptions.NoSuchElementException)2 Nullable (javax.annotation.Nullable)2 Context (android.content.Context)1 PerformException (android.support.test.espresso.PerformException)1 ViewAssertion (android.support.test.espresso.ViewAssertion)1 ViewAssertions.matches (android.support.test.espresso.assertion.ViewAssertions.matches)1 ViewMatchers.isDisplayed (android.support.test.espresso.matcher.ViewMatchers.isDisplayed)1 ViewMatchers.withId (android.support.test.espresso.matcher.ViewMatchers.withId)1 ActivityTestRule (android.support.test.rule.ActivityTestRule)1 AndroidJUnit4 (android.support.test.runner.AndroidJUnit4)1