diff --git a/WordPress/src/androidTest/java/org/wordpress/android/e2e/StatsTests.kt b/WordPress/src/androidTest/java/org/wordpress/android/e2e/StatsTests.kt index 9cb69659d814..1e9495f14b3e 100644 --- a/WordPress/src/androidTest/java/org/wordpress/android/e2e/StatsTests.kt +++ b/WordPress/src/androidTest/java/org/wordpress/android/e2e/StatsTests.kt @@ -6,7 +6,6 @@ import dagger.hilt.android.testing.HiltAndroidTest import org.junit.After import org.junit.Assume.assumeTrue import org.junit.Before -import org.junit.Ignore import org.junit.Test import org.wordpress.android.BuildConfig import org.wordpress.android.R @@ -22,9 +21,7 @@ import org.wordpress.android.util.StatsVisitsData class StatsTests : BaseTest() { @Before fun setUp() { - // We're not running Stats tests for JP. - // See https://github.com/wordpress-mobile/WordPress-Android/issues/18065 - assumeTrue(!BuildConfig.IS_JETPACK_APP) + assumeTrue(BuildConfig.IS_JETPACK_APP) ComposeEspressoLink().unregister() logoutIfNecessary() wpLogin() @@ -38,8 +35,7 @@ class StatsTests : BaseTest() { Espresso.pressBack() } } - - @Ignore("Will be taken care of in a future PR - scrollToPosts is not working") + @Test fun e2eAllDayStatsLoad() { val todayVisits = StatsVisitsData("97", "28", "14", "11") diff --git a/WordPress/src/androidTest/java/org/wordpress/android/e2e/pages/MySitesPage.kt b/WordPress/src/androidTest/java/org/wordpress/android/e2e/pages/MySitesPage.kt index 8cce56e7b95e..8c9c3ba593cc 100644 --- a/WordPress/src/androidTest/java/org/wordpress/android/e2e/pages/MySitesPage.kt +++ b/WordPress/src/androidTest/java/org/wordpress/android/e2e/pages/MySitesPage.kt @@ -149,7 +149,7 @@ class MySitesPage { val statsButton = Espresso.onView( Matchers.allOf( ViewMatchers.withText(R.string.stats), - ViewMatchers.withId(R.id.my_site_item_primary_text) + ViewMatchers.withId(R.id.quick_link_item) ) ) WPSupportUtils.clickOn(statsButton) @@ -158,7 +158,7 @@ class MySitesPage { WPSupportUtils.waitForElementToBeDisplayedWithoutFailure(R.id.tabLayout) // Wait for the stats to load - WPSupportUtils.idleFor(8000) + WPSupportUtils.idleFor(4000) return StatsPage() } diff --git a/WordPress/src/androidTest/java/org/wordpress/android/e2e/pages/StatsPage.kt b/WordPress/src/androidTest/java/org/wordpress/android/e2e/pages/StatsPage.kt index 0f515bfdc26a..76c2c4d8a054 100644 --- a/WordPress/src/androidTest/java/org/wordpress/android/e2e/pages/StatsPage.kt +++ b/WordPress/src/androidTest/java/org/wordpress/android/e2e/pages/StatsPage.kt @@ -1,12 +1,15 @@ package org.wordpress.android.e2e.pages +import androidx.recyclerview.widget.RecyclerView.ViewHolder import androidx.test.espresso.Espresso import androidx.test.espresso.action.ViewActions import androidx.test.espresso.assertion.ViewAssertions +import androidx.test.espresso.contrib.RecyclerViewActions import androidx.test.espresso.matcher.ViewMatchers import org.hamcrest.Matchers import org.wordpress.android.R import org.wordpress.android.support.WPSupportUtils +import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel import org.wordpress.android.util.StatsKeyValueData import org.wordpress.android.util.StatsVisitsData @@ -31,37 +34,37 @@ class StatsPage { } fun scrollToPosts(): StatsPage { - scrollToCard("Posts and Pages") + scrollToCard(1, StatsListViewModel.StatsSection.DAYS) return this } fun scrollToReferrers(): StatsPage { - scrollToCard("Referrers") + scrollToCard(2, StatsListViewModel.StatsSection.DAYS) return this } fun scrollToClicks(): StatsPage { - scrollToCard("Clicks") + scrollToCard(3, StatsListViewModel.StatsSection.DAYS) return this } fun scrollToAuthors(): StatsPage { - scrollToCard("Authors") + scrollToCard(4, StatsListViewModel.StatsSection.DAYS) return this } fun scrollToCountries(): StatsPage { - scrollToCard("Countries") + scrollToCard(5, StatsListViewModel.StatsSection.DAYS) return this } fun scrollToVideos(): StatsPage { - scrollToCard("Videos") + scrollToCard(7, StatsListViewModel.StatsSection.DAYS) return this } fun scrollToFileDownloads(): StatsPage { - scrollToCard("File downloads") + scrollToCard(8, StatsListViewModel.StatsSection.DAYS) return this } @@ -96,7 +99,7 @@ class StatsPage { ) ) ) - cardStructure.check(ViewAssertions.matches(ViewMatchers.isCompletelyDisplayed())) + cardStructure.check(ViewAssertions.matches(ViewMatchers.isDisplayed())) return this } @@ -121,7 +124,7 @@ class StatsPage { ) ) ) - cardStructure.check(ViewAssertions.matches(ViewMatchers.isCompletelyDisplayed())) + cardStructure.check(ViewAssertions.matches(ViewMatchers.isDisplayed())) } } @@ -160,15 +163,14 @@ class StatsPage { return this } - private fun scrollToCard(cardHeader: String) { - val card = Espresso.onView( - Matchers.allOf( - ViewMatchers.isDescendantOfA(visibleCoordinatorLayout), - ViewMatchers.withId(R.id.stats_block_list), - ViewMatchers.hasDescendant(ViewMatchers.withText(cardHeader)) - ) + private fun scrollToCard(viewholderPosition: Int, section: StatsListViewModel.StatsSection) { + WPSupportUtils.idleFor(2000) + Espresso.onView(Matchers.allOf( + ViewMatchers.withTagValue(Matchers.`is`(section.name)) + )).perform( + RecyclerViewActions.scrollToPosition(viewholderPosition) ) - WPSupportUtils.scrollIntoView(R.id.statsPager, card, 0.5.toFloat()) + WPSupportUtils.idleFor(2000) } companion object { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt index bc49cb17d900..65d693364ca7 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt @@ -128,6 +128,7 @@ class StatsListFragment : ViewPagerFragment(R.layout.stats_list_fragment) { } this@StatsListFragment.layoutManager = layoutManager + this.recyclerView.tag = statsSection.name recyclerView.layoutManager = this@StatsListFragment.layoutManager recyclerView.addItemDecoration( StatsListItemDecoration(