Skip to content

Commit

Permalink
remove visibility constraints/expectations/assertions from UI test
Browse files Browse the repository at this point in the history
the Github Action run doesn't support that (no graphical output)
  • Loading branch information
mathisdt committed Sep 5, 2022
1 parent a87c739 commit 45fadf9
Showing 1 changed file with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import static androidx.test.espresso.action.ViewActions.scrollTo;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.withClassName;
import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withParent;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
Expand All @@ -21,7 +20,6 @@

import androidx.test.espresso.IdlingPolicies;
import androidx.test.espresso.ViewInteraction;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
Expand All @@ -38,6 +36,10 @@

import java.util.concurrent.TimeUnit;

/**
* Attention: DON'T USE visibility expectations or assertions for UI elements!
* The script running this test in a Github Action doesn't support that, it will result in test failure.
*/
@LargeTest
@RunWith(AndroidJUnit4.class)
public class WorkTimeTrackerActivityIT {
Expand All @@ -49,8 +51,8 @@ public class WorkTimeTrackerActivityIT {
@BeforeClass
public static void beforeClass() {
// let's be generous, Github Actions are slow
IdlingPolicies.setMasterPolicyTimeout(300, TimeUnit.SECONDS);
IdlingPolicies.setIdlingResourceTimeout(300, TimeUnit.SECONDS);
IdlingPolicies.setMasterPolicyTimeout(120, TimeUnit.SECONDS);
IdlingPolicies.setIdlingResourceTimeout(120, TimeUnit.SECONDS);
}

@Test
Expand Down Expand Up @@ -85,12 +87,11 @@ public void workTimeTrackerActivityIT() {
weekTimesView.perform(scrollTo(), click());

ViewInteraction menuButton = onView(
allOf(childAtPosition(
childAtPosition(
childAtPosition(
withId(androidx.appcompat.R.id.action_bar),
2),
0),
withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
0));
menuButton.perform(click());

ViewInteraction newPeriodMenuItem = onView(
Expand All @@ -99,8 +100,7 @@ public void workTimeTrackerActivityIT() {
childAtPosition(
withId(androidx.appcompat.R.id.content),
0),
0),
withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
0)));
newPeriodMenuItem.perform(click());

ViewInteraction saveNewPeriodButton = onView(
Expand All @@ -109,18 +109,16 @@ public void workTimeTrackerActivityIT() {
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0),
1),
withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
1)));
saveNewPeriodButton.perform(click());

ViewInteraction backToMainActivity = onView(
allOf(childAtPosition(
childAtPosition(
allOf(withId(androidx.appcompat.R.id.action_bar),
childAtPosition(
withId(androidx.appcompat.R.id.action_bar_container),
0)),
1),
withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
1));
backToMainActivity.perform(click());

ViewInteraction totalWorked2 = onView(
Expand All @@ -135,7 +133,7 @@ public void workTimeTrackerActivityIT() {
private static Matcher<View> childAtPosition(
final Matcher<View> parentMatcher, final int position) {

return new TypeSafeMatcher<View>() {
return new TypeSafeMatcher<>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
Expand Down

0 comments on commit 45fadf9

Please sign in to comment.