Search in sources :

Example 26 with ViewInteraction

use of android.support.test.espresso.ViewInteraction in project Space-Station-Tracker by Kiarasht.

the class AboutActivityTest method aboutActivityTest.

@Test
public void aboutActivityTest() {
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    onView(allOf(withId(R.id.action_bar_right_bmb), isDisplayed())).perform(click());
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    onView(allOf(withId(R.id.button), withChild(withText("Help")), isDisplayed())).perform(click());
    // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    ViewInteraction textView = onView(allOf(withText("ISS Tracker"), childAtPosition(childAtPosition(IsInstanceOf.<View>instanceOf(android.widget.ScrollView.class), 0), 0), isDisplayed()));
    textView.check(matches(withText("ISS Tracker")));
    // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    ViewInteraction textView2 = onView(allOf(withText("Open source licenses"), childAtPosition(childAtPosition(IsInstanceOf.<View>instanceOf(android.widget.ScrollView.class), 0), 10), isDisplayed()));
    textView2.check(matches(withText("Open source licenses")));
    ViewInteraction textView3 = onView(allOf(withText("Versions"), childAtPosition(childAtPosition(IsInstanceOf.<View>instanceOf(android.widget.ScrollView.class), 0), 14), isDisplayed()));
    textView3.check(matches(withText("Versions")));
}
Also used : ViewInteraction(android.support.test.espresso.ViewInteraction) Espresso.onView(android.support.test.espresso.Espresso.onView) View(android.view.View) LargeTest(android.test.suitebuilder.annotation.LargeTest) Test(org.junit.Test)

Example 27 with ViewInteraction

use of android.support.test.espresso.ViewInteraction in project ChipsLayoutManager by BelooS.

the class FewChipsColumnTest method deleteItemInTheFirstLine_ItemHasMaximumWidth_SameStartPadding.

@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);
}
Also used : ViewInteraction(android.support.test.espresso.ViewInteraction) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Espresso.onView(android.support.test.espresso.Espresso.onView) ChipsEntity(com.beloo.chipslayoutmanager.sample.entity.ChipsEntity) Test(org.junit.Test)

Example 28 with ViewInteraction

use of android.support.test.espresso.ViewInteraction in project ChipsLayoutManager by BelooS.

the class FewChipsColumnTest method wrapContent_HeightIsWrapContent_DeletedLastItemInLastRowCauseHeightToDecrease.

@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);
}
Also used : Assert.assertEquals(junit.framework.Assert.assertEquals) ViewAction(android.support.test.espresso.ViewAction) ChipsFacade(com.beloo.chipslayoutmanager.sample.ui.ChipsFacade) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Mockito.spy(org.mockito.Mockito.spy) TestActivity(com.beloo.chipslayoutmanager.sample.ui.TestActivity) ISpy(com.beloo.widget.chipslayoutmanager.util.testing.ISpy) ViewMatchers.isDisplayed(android.support.test.espresso.matcher.ViewMatchers.isDisplayed) LayoutManagerFactory(com.beloo.chipslayoutmanager.sample.ui.LayoutManagerFactory) MockitoAnnotations(org.mockito.MockitoAnnotations) Assert.assertTrue(junit.framework.Assert.assertTrue) Locale(java.util.Locale) View(android.view.View) RecyclerViewEspressoFactory.notifyItemRemovedAction(com.beloo.test.util.RecyclerViewEspressoFactory.notifyItemRemovedAction) ChipsEntity(com.beloo.chipslayoutmanager.sample.entity.ChipsEntity) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) ViewInteraction(android.support.test.espresso.ViewInteraction) ActivityTestRule(android.support.test.rule.ActivityTestRule) R(com.beloo.chipslayoutmanager.sample.R) Test(org.junit.Test) AndroidJUnit4(android.support.test.runner.AndroidJUnit4) Mockito.when(org.mockito.Mockito.when) ViewGroup(android.view.ViewGroup) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) RecyclerView(android.support.v7.widget.RecyclerView) ViewAssertions.matches(android.support.test.espresso.assertion.ViewAssertions.matches) List(java.util.List) Rule(org.junit.Rule) Espresso.onView(android.support.test.espresso.Espresso.onView) InstrumentalUtil(com.beloo.widget.chipslayoutmanager.util.InstrumentalUtil) Mockito.atMost(org.mockito.Mockito.atMost) ViewMatchers.withId(android.support.test.espresso.matcher.ViewMatchers.withId) RecyclerViewEspressoFactory.actionDelegate(com.beloo.test.util.RecyclerViewEspressoFactory.actionDelegate) ViewAction(android.support.test.espresso.ViewAction) RecyclerView(android.support.v7.widget.RecyclerView) ViewInteraction(android.support.test.espresso.ViewInteraction) Test(org.junit.Test)

Example 29 with ViewInteraction

use of android.support.test.espresso.ViewInteraction in project ChipsLayoutManager by BelooS.

the class FewChipsRowTest method wrapContent_HeightIsWrapContent_DeletedLastItemInLastRowCauseHeightToDecrease.

@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.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        view.requestLayout();
    });
    recyclerView.perform(viewAction);
    int startHeight = rvTest[0].getHeight();
    //act
    recyclerView.perform(actionDelegate(((uiController, view) -> items.remove(9))), notifyItemRemovedAction(9));
    //assert
    int endHeight = rvTest[0].getHeight();
    System.out.println(String.format(Locale.getDefault(), "start height = %d, end height = %d", startHeight, endHeight));
    assertTrue(endHeight < startHeight);
}
Also used : ViewAction(android.support.test.espresso.ViewAction) RelativeLayout(android.widget.RelativeLayout) RecyclerView(android.support.v7.widget.RecyclerView) ViewInteraction(android.support.test.espresso.ViewInteraction) Test(org.junit.Test)

Example 30 with ViewInteraction

use of android.support.test.espresso.ViewInteraction in project dobby-android by InceptAi.

the class WifiExpertUITests method checkIdleState.

private void checkIdleState(boolean initialAppLaunch) {
    captureScreenshot("idle_state");
    checkSlowInternetCheckWifiAndRunSpeedTestButtons();
    if (!initialAppLaunch) {
        checkDetailsButton(3);
    }
    if (initialAppLaunch) {
        ViewInteraction textView = onView(allOf(withId(R.id.dobbyTextTv), withText(containsString("run tests")), childAtPosition(allOf(withId(R.id.dobbyChatLayout), childAtPosition(withId(R.id.chatRv), 0)), 1), isDisplayed()));
        textView.check(matches(withText(containsString("run tests"))));
    }
}
Also used : ViewInteraction(android.support.test.espresso.ViewInteraction)

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