From d81813a7abed1672a156ddfadaacf223291a96ba Mon Sep 17 00:00:00 2001 From: williamrai Date: Thu, 5 Dec 2024 17:05:50 -0500 Subject: [PATCH 01/22] - adds article tab test - adds assertColorForChildItemInAList function which will allow to test color for any child item in the recyclerview - adds clickOnSpecificItemInList function - separates some function from PageRobot to TabsRobot - --- .../java/org/wikipedia/base/BaseRobot.kt | 58 +++++++++++++++ .../java/org/wikipedia/robots/DialogRobot.kt | 23 ++++++ .../robots/feature/ExploreFeedRobot.kt | 36 +++++----- .../org/wikipedia/robots/feature/PageRobot.kt | 21 ++---- .../wikipedia/robots/feature/SearchRobot.kt | 6 ++ .../org/wikipedia/robots/feature/TabsRobot.kt | 38 ++++++++++ .../tests/articles/ArticleTabTest.kt | 71 +++++++++++++++++++ 7 files changed, 222 insertions(+), 31 deletions(-) create mode 100644 app/src/androidTest/java/org/wikipedia/robots/DialogRobot.kt create mode 100644 app/src/androidTest/java/org/wikipedia/robots/feature/TabsRobot.kt create mode 100644 app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt diff --git a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt index acaebeeaf78..b7d0a987f28 100644 --- a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt @@ -14,6 +14,7 @@ import androidx.test.espresso.Espresso.onView import androidx.test.espresso.Espresso.pressBack import androidx.test.espresso.UiController import androidx.test.espresso.ViewAction +import androidx.test.espresso.ViewAssertion import androidx.test.espresso.action.ViewActions import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.action.ViewActions.closeSoftKeyboard @@ -98,6 +99,33 @@ abstract class BaseRobot { ) } + protected fun clickOnSpecificItemInList(@IdRes listId: Int, @IdRes itemId: Int, position: Int) { + onView(withId(listId)) + .perform( + RecyclerViewActions.scrollToPosition(position), + RecyclerViewActions.actionOnItemAtPosition( + position, + clickChildViewWithId(itemId) + ) + ) + } + + protected fun assertColorForChildItemInAList( + @IdRes listId: Int, + @IdRes childItemId: Int, + colorResOrAttr: Int, + position: Int, + isAttr: Boolean = true, + colorType: ColorAssertions.ColorType = ColorAssertions.ColorType.TextColor + ) { + onView(withId(listId)) + .perform(RecyclerViewActions.scrollToPosition(position)) + .check(matchesAtPosition(position, targetViewId = childItemId, assertion = { view -> + ColorAssertions.hasColor(colorResOrAttr, isAttr, colorType) + .check(view, null) + })) + } + protected fun scrollToView(@IdRes viewId: Int) { onView(withId(viewId)).perform(scrollTo()) } @@ -393,6 +421,36 @@ abstract class BaseRobot { onView(withId(viewId)) .check((matches(ColorMatchers.withTintColor(colorResOrAttr, isAttr)))) } + + protected fun makeViewVisibleAndClick(@IdRes viewId: Int, @IdRes parentViewId: Int) { + onView(allOf(withId(viewId), isDescendantOfA(withId(parentViewId)))) + .perform(scrollAndClick()) + } + + private fun clickChildViewWithId(@IdRes id: Int) = object : ViewAction { + override fun getConstraints() = null + + override fun getDescription() = "Click on a child view with specified id." + + override fun perform(uiController: UiController, view: View) { + val v = view.findViewById(id) + v?.performClick() + } + } + + private fun matchesAtPosition(position: Int, @IdRes targetViewId: Int, assertion: (View) -> Unit): ViewAssertion { + return ViewAssertion { view, noViewFoundException -> + if (view !is RecyclerView) { + throw IllegalStateException("The asserted view is not RecyclerView") + } + + val itemView = view.findViewHolderForAdapterPosition(position)?.itemView + ?: throw IllegalStateException("No view with id: $targetViewId") + val targetView = itemView.findViewById(targetViewId) + ?: throw IllegalStateException("No view with id: $targetViewId") + assertion(targetView) + } + } } class NestedScrollViewExtension(scrollToAction: ViewAction = ViewActions.scrollTo()) : ViewAction by scrollToAction { diff --git a/app/src/androidTest/java/org/wikipedia/robots/DialogRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/DialogRobot.kt new file mode 100644 index 00000000000..37629f28636 --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/robots/DialogRobot.kt @@ -0,0 +1,23 @@ +package org.wikipedia.robots + +import android.util.Log +import org.wikipedia.base.BaseRobot + +class DialogRobot : BaseRobot() { + + fun dismissContributionDialog() = apply { + try { + clickOnViewWithText(text = "No, thanks") + } catch (e: Exception) { + Log.d("DialogRobot: ", "No Contribution dialog shown.") + } + } + + fun dismissBigEnglishDialog() = apply { + try { + clickOnViewWithText(text = "Maybe later") + } catch (e: Exception) { + Log.d("DialogRobot: ", "No Big English dialog shown.") + } + } +} diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt index 39b22231d66..7421e44eeb4 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt @@ -10,7 +10,6 @@ import androidx.test.espresso.UiController import androidx.test.espresso.ViewAction import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.action.ViewActions.longClick -import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom import androidx.test.espresso.matcher.ViewMatchers.isDisplayed @@ -22,7 +21,6 @@ import org.hamcrest.Matchers import org.hamcrest.Matchers.allOf import org.wikipedia.R import org.wikipedia.TestUtil.childAtPosition -import org.wikipedia.TestUtil.isDisplayed import org.wikipedia.base.BaseRobot import org.wikipedia.base.TestConfig import org.wikipedia.feed.view.FeedView @@ -122,20 +120,26 @@ class ExploreFeedRobot : BaseRobot() { delay(TestConfig.DELAY_SHORT) } - // @TODO: flaky test due to snackbar - fun addOrRemoveToWatchList() = apply { - val isVisible = onView(withText("Watch")) - if (isVisible.isDisplayed()) { - clickOnViewWithText("Watch") - onView(withId(com.google.android.material.R.id.snackbar_text)) - .check(matches(isDisplayed())) - changWatchListArticleExpiryFromTheSnackBar() - } else { - clickOnViewWithText("Unwatch") - onView(withId(com.google.android.material.R.id.snackbar_text)) - .check(matches(isDisplayed())) - delay(TestConfig.DELAY_SHORT) - } + fun scrollToItem( + recyclerViewId: Int = R.id.feed_view, + title: String, + textViewId: Int = R.id.view_card_header_title, + verticalOffset: Int = 200 + ) = apply { + scrollToRecyclerView( + recyclerViewId, + title, + textViewId, + verticalOffset + ) + } + + fun clickOnFeaturedArticle() = apply { + makeViewVisibleAndClick( + viewId = R.id.view_featured_article_card_content_container, + parentViewId = R.id.feed_view + ) + delay(TestConfig.DELAY_MEDIUM) } private fun changWatchListArticleExpiryFromTheSnackBar() = apply { diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt index b1266c4d1f2..1f3938500ca 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt @@ -38,15 +38,11 @@ class PageRobot : BaseRobot() { delay(TestConfig.DELAY_MEDIUM) } - fun openInNewTab() = apply { + fun openPreviewLinkInNewTab() = apply { clickOnDisplayedView(R.id.link_preview_secondary_button) delay(TestConfig.DELAY_MEDIUM) } - fun verifyTabCount(count: String) = apply { - checkWithTextIsDisplayed(R.id.tabsCountText, count) - } - fun dismissTooltip(activity: Activity) = apply { dismissTooltipIfAny(activity, viewId = R.id.buttonView) delay(TestConfig.DELAY_SHORT) @@ -104,16 +100,6 @@ class PageRobot : BaseRobot() { onWebView().forceJavascriptEnabled() } - fun launchTabsScreen() = apply { - clickOnDisplayedView(R.id.page_toolbar_button_tabs) - delay(TestConfig.DELAY_MEDIUM) - } - - fun createNewTabWithContentDescription(text: String) = apply { - clickOnDisplayedViewWithContentDescription(text) - delay(TestConfig.DELAY_MEDIUM) - } - fun clickOnPreviewTabInTheList(position: Int) = apply { clickRecyclerViewItemAtPosition(R.id.tabRecyclerView, position) } @@ -181,6 +167,11 @@ class PageRobot : BaseRobot() { delay(TestConfig.DELAY_LARGE) } + fun navigateUp() = apply { + clickOnDisplayedViewWithContentDescription("Navigate up") + delay(TestConfig.DELAY_SHORT) + } + private fun assertElementVisibility(elementSelector: String, isVisible: Boolean) { onView(withId(R.id.page_web_view)) .perform(AssertJavascriptAction("(function() { return document.querySelector(\"$elementSelector\").checkVisibility() })();", isVisible.toString())) diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt index 2b45a7612ee..293ad04eb28 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt @@ -5,6 +5,12 @@ import org.wikipedia.base.BaseRobot import org.wikipedia.base.TestConfig class SearchRobot : BaseRobot() { + fun tapSearchView() = apply { + // Click the Search box + clickOnViewWithText("Search Wikipedia") + delay(TestConfig.DELAY_SHORT) + } + fun clickSearchContainer() = apply { // Click the Search box clickOnDisplayedView(R.id.search_container) diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/TabsRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/TabsRobot.kt new file mode 100644 index 00000000000..bcfd171d299 --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/TabsRobot.kt @@ -0,0 +1,38 @@ +package org.wikipedia.robots.feature + +import org.wikipedia.R +import org.wikipedia.base.BaseRobot +import org.wikipedia.base.TestConfig + +class TabsRobot : BaseRobot() { + fun removeTab(position: Int) = apply { + clickOnSpecificItemInList( + listId = R.id.tabRecyclerView, + itemId = R.id.tabCloseButton, + position = position + ) + } + + fun launchTabsScreen() = apply { + clickOnDisplayedView(R.id.page_toolbar_button_tabs) + delay(TestConfig.DELAY_MEDIUM) + } + + fun createNewTabWithContentDescription(text: String) = apply { + clickOnDisplayedViewWithContentDescription(text) + delay(TestConfig.DELAY_MEDIUM) + } + + fun verifyTabCount(count: Int) = apply { + checkWithTextIsDisplayed(R.id.tabsCountText, count.toString()) + } + + fun assertColorOfTabsTitle(position: Int) = apply { + assertColorForChildItemInAList( + listId = R.id.tabRecyclerView, + childItemId = R.id.tabArticleTitle, + colorResOrAttr = R.attr.primary_color, + position = position + ) + } +} diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt new file mode 100644 index 00000000000..8fc0225ce2a --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt @@ -0,0 +1,71 @@ +package org.wikipedia.tests.articles + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import org.junit.Test +import org.junit.runner.RunWith +import org.wikipedia.Constants +import org.wikipedia.R +import org.wikipedia.base.BaseTest +import org.wikipedia.main.MainActivity +import org.wikipedia.robots.DialogRobot +import org.wikipedia.robots.SystemRobot +import org.wikipedia.robots.feature.ExploreFeedRobot +import org.wikipedia.robots.feature.PageRobot +import org.wikipedia.robots.feature.SearchRobot +import org.wikipedia.robots.feature.TabsRobot + +@LargeTest +@RunWith(AndroidJUnit4::class) +class ArticleTabTest : BaseTest( + activityClass = MainActivity::class.java +) { + + private val pageRobot = PageRobot() + private val tabsRobot = TabsRobot() + private val systemRobot = SystemRobot() + private val exploreFeedRobot = ExploreFeedRobot() + private val dialogRobot = DialogRobot() + private val searchRobot = SearchRobot() + + @Test + fun runTest() { + systemRobot + .clickOnSystemDialogWithText("Allow") + exploreFeedRobot + .scrollToItem(title = Constants.FEATURED_ARTICLE) + .clickOnFeaturedArticle() + pageRobot + .dismissTooltip(activity) + .navigateUp() + exploreFeedRobot + .scrollToItem(title = Constants.FEATURED_ARTICLE) + .clickOnFeaturedArticle() + dialogRobot + .dismissBigEnglishDialog() + .dismissContributionDialog() + tabsRobot + .launchTabsScreen() + .assertColorOfTabsTitle(0) + .createNewTabWithContentDescription(context.getString(R.string.menu_new_tab)) + + searchRobot + .tapSearchView() + .typeTextInView(Constants.SEARCH_TERM) + .clickOnItemFromSearchList(0) + tabsRobot + .launchTabsScreen() + .assertColorOfTabsTitle(1) + .createNewTabWithContentDescription(context.getString(R.string.menu_new_tab)) + searchRobot + .tapSearchView() + .typeTextInView(Constants.SEARCH_TERM2) + .clickOnItemFromSearchList(0) + tabsRobot + .launchTabsScreen() + .assertColorOfTabsTitle(2) + .verifyTabCount(3) + .removeTab(0) + .verifyTabCount(2) + } +} From fa27ba6d36fe593dc5054c94c8a68358dea7bd76 Mon Sep 17 00:00:00 2001 From: williamrai Date: Thu, 5 Dec 2024 17:05:59 -0500 Subject: [PATCH 02/22] - name fix --- .../androidTest/java/org/wikipedia/Constants.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 app/src/androidTest/java/org/wikipedia/Constants.kt diff --git a/app/src/androidTest/java/org/wikipedia/Constants.kt b/app/src/androidTest/java/org/wikipedia/Constants.kt new file mode 100644 index 00000000000..830828f1fb7 --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/Constants.kt @@ -0,0 +1,15 @@ +package org.wikipedia + +object Constants { + const val FEATURED_ARTICLE = "Featured article" + const val TODAY_ON_WIKIPEDIA_MAIN_PAGE = "Today on Wikipedia" + const val TOP_READ_ARTICLES = "Top read" + const val PICTURE_OF_DAY = "Picture of the day" + const val BECAUSE_YOU_READ = "Because you read" + const val NEWS_CARD = "In the news" + const val ON_THIS_DAY_CARD = "On this day" + const val RANDOM_CARD = "Random article" + const val SUGGESTED_EDITS = "Suggested edits" + const val SEARCH_TERM = "apple" + const val SEARCH_TERM2 = "orange" +} From 9479161326af66a05fb833ab74a4746db7b0a854 Mon Sep 17 00:00:00 2001 From: williamrai Date: Fri, 6 Dec 2024 16:30:10 -0500 Subject: [PATCH 03/22] - merge fix --- .../java/org/wikipedia/base/BaseRobot.kt | 52 ------------------- .../robots/feature/ExploreFeedRobot.kt | 20 ------- 2 files changed, 72 deletions(-) diff --git a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt index f2ba9cb60af..9b5f6ba8e80 100644 --- a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt @@ -442,31 +442,6 @@ abstract class BaseRobot { .check((matches(ColorMatchers.withTintColor(colorResOrAttr, isAttr)))) } - private fun clickChildViewWithId(@IdRes id: Int) = object : ViewAction { - override fun getConstraints() = null - - override fun getDescription() = "Click on a child view with specified id." - - override fun perform(uiController: UiController, view: View) { - val v = view.findViewById(id) - v?.performClick() - } - } - - private fun matchesAtPosition(position: Int, @IdRes targetViewId: Int, assertion: (View) -> Unit): ViewAssertion { - return ViewAssertion { view, noViewFoundException -> - if (view !is RecyclerView) { - throw IllegalStateException("The asserted view is not RecyclerView") - } - - val itemView = view.findViewHolderForAdapterPosition(position)?.itemView - ?: throw IllegalStateException("No view with id: $targetViewId") - val targetView = itemView.findViewById(targetViewId) - ?: throw IllegalStateException("No view with id: $targetViewId") - assertion(targetView) - } - } - protected fun checkRTLDirectionOfAView(@IdRes viewId: Int) { onView(withId(viewId),) .check(matches(isLayoutDirectionRTL())) @@ -500,33 +475,6 @@ abstract class BaseRobot { } } - protected fun clickOnSpecificItemInList(@IdRes listId: Int, @IdRes itemId: Int, position: Int) { - onView(withId(listId)) - .perform( - RecyclerViewActions.scrollToPosition(position), - RecyclerViewActions.actionOnItemAtPosition( - position, - clickChildViewWithId(itemId) - ) - ) - } - - protected fun assertColorForChildItemInAList( - @IdRes listId: Int, - @IdRes childItemId: Int, - colorResOrAttr: Int, - position: Int, - isAttr: Boolean = true, - colorType: ColorAssertions.ColorType = ColorAssertions.ColorType.TextColor - ) { - onView(withId(listId)) - .perform(RecyclerViewActions.scrollToPosition(position)) - .check(matchesAtPosition(position, targetViewId = childItemId, assertion = { view -> - ColorAssertions.hasColor(colorResOrAttr, isAttr, colorType) - .check(view, null) - })) - } - private fun clickChildViewWithId(@IdRes id: Int) = object : ViewAction { override fun getConstraints() = null diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt index 2d81593a0b9..cc71cd34e65 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt @@ -148,26 +148,6 @@ class ExploreFeedRobot : BaseRobot() { } catch (e: Exception) { Log.e("ScrollError:", "Suggested edits not visible or espresso cannot find it.") } - fun scrollToItem( - recyclerViewId: Int = R.id.feed_view, - title: String, - textViewId: Int = R.id.view_card_header_title, - verticalOffset: Int = 200 - ) = apply { - scrollToRecyclerView( - recyclerViewId, - title, - textViewId, - verticalOffset - ) - } - - fun clickOnFeaturedArticle() = apply { - makeViewVisibleAndClick( - viewId = R.id.view_featured_article_card_content_container, - parentViewId = R.id.feed_view - ) - delay(TestConfig.DELAY_MEDIUM) } private fun changWatchListArticleExpiryFromTheSnackBar() = apply { From 9d39f5510655f29fc9b7cbc76b2818527042cfe2 Mon Sep 17 00:00:00 2001 From: williamrai Date: Fri, 6 Dec 2024 16:30:31 -0500 Subject: [PATCH 04/22] - ci fix --- .../java/org/wikipedia/robots/feature/ExploreFeedRobot.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt index cc71cd34e65..9e6fdf64501 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt @@ -9,7 +9,6 @@ import androidx.test.espresso.Espresso.onView import androidx.test.espresso.NoMatchingViewException import androidx.test.espresso.action.ViewActions import androidx.test.espresso.action.ViewActions.click -import androidx.test.espresso.action.ViewActions.longClick import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition import androidx.test.espresso.contrib.RecyclerViewActions.scrollTo import androidx.test.espresso.matcher.BoundedMatcher From fd020a1950ffda054f22f8c1898f7d620573afb9 Mon Sep 17 00:00:00 2001 From: williamrai Date: Mon, 9 Dec 2024 16:53:49 -0500 Subject: [PATCH 05/22] - adds page action item test --- .../java/org/wikipedia/base/BaseRobot.kt | 6 +++ .../org/wikipedia/robots/feature/PageRobot.kt | 33 ++++++++++----- .../articles/ArticlePageActionItemTest.kt | 42 +++++++++++++++++++ .../tests/articles/ArticleTabTest.kt | 10 ++--- 4 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt diff --git a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt index 9b5f6ba8e80..02b0f218b82 100644 --- a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt @@ -49,6 +49,7 @@ import org.hamcrest.Description import org.hamcrest.Matcher import org.hamcrest.Matchers import org.hamcrest.Matchers.allOf +import org.hamcrest.Matchers.containsString import org.hamcrest.Matchers.not import org.hamcrest.TypeSafeMatcher import org.wikipedia.R @@ -168,6 +169,11 @@ abstract class BaseRobot { onView(withId(viewId)).check(matches(isDisplayed())) } + protected fun checkPartialString(text: String) { + onView(withText(containsString(text))) + .check(matches(isDisplayed())) + } + protected fun isViewWithTextVisible(text: String): Boolean { var isDisplayed = false onView(withText(text)).check { view, noViewFoundException -> diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt index 9257f918908..0b71e9a0a0d 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt @@ -131,11 +131,6 @@ class PageRobot : BaseRobot() { delay(TestConfig.DELAY_MEDIUM) } - fun openLanguageSelector() = apply { - clickOnDisplayedViewWithIdAnContentDescription(R.id.page_language, "Language") - delay(TestConfig.DELAY_MEDIUM) - } - fun clickLanguageListedAtFourthPosition() = apply { clickRecyclerViewItemAtPosition(R.id.langlinks_recycler, 3) delay(TestConfig.DELAY_MEDIUM) @@ -151,11 +146,6 @@ class PageRobot : BaseRobot() { delay(TestConfig.DELAY_MEDIUM) } - fun clickOnBookmarkIcon() = apply { - clickOnViewWithId(R.id.page_save) - delay(TestConfig.DELAY_MEDIUM) - } - fun removeArticleFromReadingList() = apply { clickOnViewWithText("Remove from Saved") delay(TestConfig.DELAY_LARGE) @@ -210,4 +200,27 @@ class PageRobot : BaseRobot() { fun assertCollapsingTableIsVisible(isVisible: Boolean) = apply { assertElementVisibility(".pcs-collapse-table-content", isVisible) } + + fun saveArticleToReadingList() = apply { + clickOnViewWithId(R.id.page_save) + } + + fun confirmArticleSaved(text: String) = apply { + checkPartialString(text) + } + + fun openLanguageSelector() = apply { + clickOnDisplayedViewWithIdAnContentDescription(R.id.page_language, "Language") + delay(TestConfig.DELAY_MEDIUM) + } + + fun selectSpanishLanguage() = apply { + val language = "Spanish" + scrollToRecyclerView( + recyclerViewId = R.id.langlinks_recycler, + title = language, + textViewId = R.id.non_localized_language_name + ) + clickOnViewWithText(language) + } } diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt new file mode 100644 index 00000000000..328d696cad7 --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt @@ -0,0 +1,42 @@ +package org.wikipedia.tests.articles + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import org.junit.Test +import org.junit.runner.RunWith +import org.wikipedia.Constants +import org.wikipedia.FakeData +import org.wikipedia.base.BaseTest +import org.wikipedia.base.DataInjector +import org.wikipedia.base.TestConfig.ARTICLE_TITLE_ESPANOL +import org.wikipedia.page.PageActivity +import org.wikipedia.page.PageActivity.Companion.ACTION_LOAD_IN_CURRENT_TAB +import org.wikipedia.page.PageActivity.Companion.EXTRA_HISTORYENTRY +import org.wikipedia.robots.feature.PageRobot + +@LargeTest +@RunWith(AndroidJUnit4::class) +class ArticlePageActionItemTest : BaseTest( + activityClass = PageActivity::class.java, + dataInjector = DataInjector( + intentBuilder = { + action = ACTION_LOAD_IN_CURRENT_TAB + putExtra(EXTRA_HISTORYENTRY, FakeData.historyEntry) + putExtra(Constants.ARG_TITLE, FakeData.historyEntry.title) + } + ) +) { + + private val pageRobot = PageRobot() + + @Test + fun runTest() { + pageRobot + .saveArticleToReadingList() + .confirmArticleSaved("Saved") + .openLanguageSelector() + .selectSpanishLanguage() + .verifyArticleTitle(ARTICLE_TITLE_ESPANOL) + } +} + diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt index 8fc0225ce2a..82dbf2f1fc7 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt @@ -4,8 +4,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.LargeTest import org.junit.Test import org.junit.runner.RunWith -import org.wikipedia.Constants import org.wikipedia.R +import org.wikipedia.TestConstants import org.wikipedia.base.BaseTest import org.wikipedia.main.MainActivity import org.wikipedia.robots.DialogRobot @@ -33,13 +33,13 @@ class ArticleTabTest : BaseTest( systemRobot .clickOnSystemDialogWithText("Allow") exploreFeedRobot - .scrollToItem(title = Constants.FEATURED_ARTICLE) + .scrollToItem(title = TestConstants.FEATURED_ARTICLE) .clickOnFeaturedArticle() pageRobot .dismissTooltip(activity) .navigateUp() exploreFeedRobot - .scrollToItem(title = Constants.FEATURED_ARTICLE) + .scrollToItem(title = TestConstants.FEATURED_ARTICLE) .clickOnFeaturedArticle() dialogRobot .dismissBigEnglishDialog() @@ -51,7 +51,7 @@ class ArticleTabTest : BaseTest( searchRobot .tapSearchView() - .typeTextInView(Constants.SEARCH_TERM) + .typeTextInView(TestConstants.SEARCH_TERM) .clickOnItemFromSearchList(0) tabsRobot .launchTabsScreen() @@ -59,7 +59,7 @@ class ArticleTabTest : BaseTest( .createNewTabWithContentDescription(context.getString(R.string.menu_new_tab)) searchRobot .tapSearchView() - .typeTextInView(Constants.SEARCH_TERM2) + .typeTextInView(TestConstants.SEARCH_TERM2) .clickOnItemFromSearchList(0) tabsRobot .launchTabsScreen() From c5b166bc38a26099cd573a19b55f4e02524acd08 Mon Sep 17 00:00:00 2001 From: williamrai Date: Tue, 10 Dec 2024 15:34:49 -0500 Subject: [PATCH 06/22] - adds res of test for page action item --- .../org/wikipedia/robots/feature/PageRobot.kt | 18 +++++++++++++++--- .../articles/ArticlePageActionItemTest.kt | 19 ++++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt index 0b71e9a0a0d..b4bd4eb1e2b 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt @@ -2,6 +2,7 @@ package org.wikipedia.robots.feature import android.annotation.SuppressLint import android.app.Activity +import android.content.Context import androidx.test.espresso.Espresso.onView import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.web.sugar.Web.onWebView @@ -209,9 +210,20 @@ class PageRobot : BaseRobot() { checkPartialString(text) } - fun openLanguageSelector() = apply { - clickOnDisplayedViewWithIdAnContentDescription(R.id.page_language, "Language") - delay(TestConfig.DELAY_MEDIUM) + fun openLanguageSelector(context: Context) = apply { + clickOnDisplayedViewWithIdAnContentDescription(R.id.page_language, context.getString(R.string.article_menu_bar_language_button)) + } + + fun openFindInArticle(context: Context) = apply { + clickOnDisplayedViewWithIdAnContentDescription(R.id.page_find_in_article, context.getString(R.string.menu_page_find_in_page)) + } + + fun openThemeSelector(context: Context) = apply { + clickOnDisplayedViewWithIdAnContentDescription(R.id.page_theme, context.getString(R.string.article_menu_bar_theme_button)) + } + + fun openTableOfContents(context: Context) = apply { + clickOnDisplayedViewWithIdAnContentDescription(R.id.page_contents, context.getString(R.string.article_menu_bar_contents_button)) } fun selectSpanishLanguage() = apply { diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt index 328d696cad7..fa860f2f5f4 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt @@ -13,6 +13,7 @@ import org.wikipedia.page.PageActivity import org.wikipedia.page.PageActivity.Companion.ACTION_LOAD_IN_CURRENT_TAB import org.wikipedia.page.PageActivity.Companion.EXTRA_HISTORYENTRY import org.wikipedia.robots.feature.PageRobot +import org.wikipedia.robots.feature.SearchRobot @LargeTest @RunWith(AndroidJUnit4::class) @@ -26,17 +27,29 @@ class ArticlePageActionItemTest : BaseTest( } ) ) { - + private val FIND_IN_ARTICLE_TEXT = "Hopf" private val pageRobot = PageRobot() + private val searchRobot = SearchRobot() @Test fun runTest() { pageRobot .saveArticleToReadingList() .confirmArticleSaved("Saved") - .openLanguageSelector() + .openLanguageSelector(context) .selectSpanishLanguage() .verifyArticleTitle(ARTICLE_TITLE_ESPANOL) + .openFindInArticle(context) + searchRobot + .typeTextInView(FIND_IN_ARTICLE_TEXT) + .pressBack() + pageRobot + .openTableOfContents(context) + .swipeTableOfContentsAllTheWayToBottom() + .pressBack() + .swipeLeftToShowTableOfContents() + .swipeTableOfContentsAllTheWayToBottom() + .pressBack() + .openThemeSelector(context) } } - From b71aa8b1d88ae9169e33da923550b3d3eef7a545 Mon Sep 17 00:00:00 2001 From: williamrai Date: Wed, 11 Dec 2024 12:23:05 -0500 Subject: [PATCH 07/22] - adds lead image test and edit icon test - code fixes --- .../wikipedia/base/AssertJavascriptAction.kt | 3 +- .../org/wikipedia/robots/feature/PageRobot.kt | 32 +++++++-- .../wikipedia/robots/feature/SearchRobot.kt | 4 +- .../articles/ArticlePageActionItemTest.kt | 10 +-- .../tests/articles/ArticleTabTest.kt | 2 +- .../wikipedia/tests/articles/EditIconTest.kt | 68 +++++++++++++++++++ .../LeadNonLeadImageAndPreviewLinkTest.kt | 41 +++++++++++ .../tests/settings/CollapseTablesTest.kt | 2 +- .../tests/settings/DownloadReadingListTest.kt | 2 +- .../tests/settings/LinkPreviewTest.kt | 2 +- .../tests/settings/ReadingFocusModeTest.kt | 2 +- 11 files changed, 150 insertions(+), 18 deletions(-) create mode 100644 app/src/androidTest/java/org/wikipedia/tests/articles/EditIconTest.kt create mode 100644 app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt diff --git a/app/src/androidTest/java/org/wikipedia/base/AssertJavascriptAction.kt b/app/src/androidTest/java/org/wikipedia/base/AssertJavascriptAction.kt index 287bd4132ba..2f63796d2d7 100644 --- a/app/src/androidTest/java/org/wikipedia/base/AssertJavascriptAction.kt +++ b/app/src/androidTest/java/org/wikipedia/base/AssertJavascriptAction.kt @@ -46,7 +46,8 @@ class AssertJavascriptAction(val script: String, val expectedResult: String) : V override fun onReceiveValue(value: String) { evaluateFinished.set(true) - if (value != expectedResult) { + val cleanValue = value.trim('"') + if (cleanValue != expectedResult) { throw exception .withCause(RuntimeException("Expected: $expectedResult, but got: $value")) .build() diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt index b4bd4eb1e2b..f6d40b77be5 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt @@ -15,7 +15,7 @@ import org.wikipedia.base.AssertJavascriptAction import org.wikipedia.base.BaseRobot import org.wikipedia.base.TestConfig -class PageRobot : BaseRobot() { +class PageRobot(private val context: Context) : BaseRobot() { fun clickEditPencilAtTopOfArticle() = apply { onWebView() @@ -162,6 +162,20 @@ class PageRobot : BaseRobot() { .perform(AssertJavascriptAction("(function() { return document.querySelector(\"$elementSelector\").checkVisibility() })();", isVisible.toString())) } + private fun assertEditIconProtection(elementSelector: String, expectedLabel: String) { + onView(withId(R.id.page_web_view)) + .perform(AssertJavascriptAction( + script = """ + (function checkEdit() { + const element = document.querySelector("$elementSelector") + const ariaLabel = element.getAttribute('aria-labelledby') + return ariaLabel === 'pcs-edit-section-aria-protected' ? 'protected' : 'normal' + })(); + """.trimIndent(), + expectedResult = expectedLabel + )) + } + fun verifyPreviewDialogAppears() = apply { checkViewExists(R.id.link_preview_title) delay(TestConfig.DELAY_SHORT) @@ -202,6 +216,14 @@ class PageRobot : BaseRobot() { assertElementVisibility(".pcs-collapse-table-content", isVisible) } + fun assertEditButtonProtection(isProtected: Boolean = false) = apply { + if (isProtected) { + assertEditIconProtection(".pcs-edit-section-link", "protected") + return@apply + } + assertEditIconProtection(".pcs-edit-section-link", "normal") + } + fun saveArticleToReadingList() = apply { clickOnViewWithId(R.id.page_save) } @@ -210,19 +232,19 @@ class PageRobot : BaseRobot() { checkPartialString(text) } - fun openLanguageSelector(context: Context) = apply { + fun openLanguageSelector() = apply { clickOnDisplayedViewWithIdAnContentDescription(R.id.page_language, context.getString(R.string.article_menu_bar_language_button)) } - fun openFindInArticle(context: Context) = apply { + fun openFindInArticle() = apply { clickOnDisplayedViewWithIdAnContentDescription(R.id.page_find_in_article, context.getString(R.string.menu_page_find_in_page)) } - fun openThemeSelector(context: Context) = apply { + fun openThemeSelector() = apply { clickOnDisplayedViewWithIdAnContentDescription(R.id.page_theme, context.getString(R.string.article_menu_bar_theme_button)) } - fun openTableOfContents(context: Context) = apply { + fun openTableOfContents() = apply { clickOnDisplayedViewWithIdAnContentDescription(R.id.page_contents, context.getString(R.string.article_menu_bar_contents_button)) } diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt index 6865a5bca92..184759402e0 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt @@ -47,8 +47,8 @@ class SearchRobot : BaseRobot() { } fun clickOnItemFromSearchList(position: Int) = apply { - clickOnItemInList(R.id.search_results_list, 0) - delay(TestConfig.DELAY_LARGE) + clickOnItemInList(R.id.search_results_list, position) + delay(TestConfig.DELAY_SHORT) } fun verifyRecentSearchesAppears() = apply { diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt index fa860f2f5f4..c90f876b6de 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt @@ -28,7 +28,7 @@ class ArticlePageActionItemTest : BaseTest( ) ) { private val FIND_IN_ARTICLE_TEXT = "Hopf" - private val pageRobot = PageRobot() + private val pageRobot = PageRobot(context) private val searchRobot = SearchRobot() @Test @@ -36,20 +36,20 @@ class ArticlePageActionItemTest : BaseTest( pageRobot .saveArticleToReadingList() .confirmArticleSaved("Saved") - .openLanguageSelector(context) + .openLanguageSelector() .selectSpanishLanguage() .verifyArticleTitle(ARTICLE_TITLE_ESPANOL) - .openFindInArticle(context) + .openFindInArticle() searchRobot .typeTextInView(FIND_IN_ARTICLE_TEXT) .pressBack() pageRobot - .openTableOfContents(context) + .openTableOfContents() .swipeTableOfContentsAllTheWayToBottom() .pressBack() .swipeLeftToShowTableOfContents() .swipeTableOfContentsAllTheWayToBottom() .pressBack() - .openThemeSelector(context) + .openThemeSelector() } } diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt index 82dbf2f1fc7..02f8ce86f10 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt @@ -21,7 +21,7 @@ class ArticleTabTest : BaseTest( activityClass = MainActivity::class.java ) { - private val pageRobot = PageRobot() + private val pageRobot = PageRobot(context) private val tabsRobot = TabsRobot() private val systemRobot = SystemRobot() private val exploreFeedRobot = ExploreFeedRobot() diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/EditIconTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/EditIconTest.kt new file mode 100644 index 00000000000..655ea8695a7 --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/EditIconTest.kt @@ -0,0 +1,68 @@ +package org.wikipedia.tests.articles + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import org.junit.Test +import org.junit.runner.RunWith +import org.wikipedia.base.BaseTest +import org.wikipedia.main.MainActivity +import org.wikipedia.robots.DialogRobot +import org.wikipedia.robots.SystemRobot +import org.wikipedia.robots.feature.PageRobot +import org.wikipedia.robots.feature.SearchRobot + +@LargeTest +@RunWith(AndroidJUnit4::class) +class EditIconTest : BaseTest( + activityClass = MainActivity::class.java +) { + private val SEARCH_TERM = "tom and jerry the movie" + private val SEARCH_TERM_AVATAR = "Avatar" + private val SEARCH_TERM_VLADIMIR_PUTIN = "Vladimir Putin" + private val SEARCH_TERM_KIM_JUNG_UN = "Kim Jong-un" + private val SEARCH_TERM_JOE_BIDEN = "Joe Biden" + private val SEARCH_TERM_KAMALA_HARRIS = "Kamala Harris" + private val SEARCH_TERM_DONALD_TRUMP = "Donald Trump" + private val SEARCH_TERM_MIKE_PENCE = "Mike Pence" + private val SEARCH_TERM_BARACK_OBAMA = "Barack Obama" + private val SEARCH_TERM_HILLARY_CLINTON = "Hillary Clinton" + private val searchRobot = SearchRobot() + private val systemRobot = SystemRobot() + private val pageRobot = PageRobot(context) + private val dialogRobot = DialogRobot() + + @Test + fun runTest() { + systemRobot + .clickOnSystemDialogWithText("Allow") + searchRobot + .tapSearchView() + .typeTextInView(SEARCH_TERM) + .clickOnItemFromSearchList(0) + pageRobot + .dismissTooltip(activity) + .assertEditButtonProtection(isProtected = false) + .pressBack() + assertEditIconProtection(SEARCH_TERM_AVATAR) + assertEditIconProtection(SEARCH_TERM_VLADIMIR_PUTIN) + assertEditIconProtection(SEARCH_TERM_KIM_JUNG_UN) + assertEditIconProtection(SEARCH_TERM_JOE_BIDEN) + assertEditIconProtection(SEARCH_TERM_KAMALA_HARRIS) + assertEditIconProtection(SEARCH_TERM_DONALD_TRUMP) + assertEditIconProtection(SEARCH_TERM_MIKE_PENCE) + assertEditIconProtection(SEARCH_TERM_BARACK_OBAMA) + assertEditIconProtection(SEARCH_TERM_HILLARY_CLINTON) + } + + private fun assertEditIconProtection(searchTerm: String, isProtected: Boolean = true) { + searchRobot + .typeTextInView(searchTerm) + .clickOnItemFromSearchList(0) + dialogRobot + .dismissBigEnglishDialog() + .dismissContributionDialog() + pageRobot + .assertEditButtonProtection(isProtected) + .pressBack() + } +} diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt new file mode 100644 index 00000000000..63bad94dfd9 --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt @@ -0,0 +1,41 @@ +package org.wikipedia.tests.articles + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import org.junit.Test +import org.junit.runner.RunWith +import org.wikipedia.Constants +import org.wikipedia.FakeData +import org.wikipedia.base.BaseTest +import org.wikipedia.base.DataInjector +import org.wikipedia.page.PageActivity +import org.wikipedia.page.PageActivity.Companion.ACTION_LOAD_IN_CURRENT_TAB +import org.wikipedia.page.PageActivity.Companion.EXTRA_HISTORYENTRY +import org.wikipedia.robots.feature.PageRobot + +@LargeTest +@RunWith(AndroidJUnit4::class) +class LeadNonLeadImageAndPreviewLinkTest : BaseTest( + activityClass = PageActivity::class.java, + dataInjector = DataInjector( + intentBuilder = { + action = ACTION_LOAD_IN_CURRENT_TAB + putExtra(EXTRA_HISTORYENTRY, FakeData.historyEntry) + putExtra(Constants.ARG_TITLE, FakeData.historyEntry.title) + } + ) +) { + + private val pageRobot = PageRobot(context) + + @Test + fun runTest() { + pageRobot + .verifyLeadImageIsNotVisible() + .clickLeadImage() + .swipePagerLeft() + .pressBack() + .clickLink("3-sphere") + .verifyPreviewDialogAppears() + } +} diff --git a/app/src/androidTest/java/org/wikipedia/tests/settings/CollapseTablesTest.kt b/app/src/androidTest/java/org/wikipedia/tests/settings/CollapseTablesTest.kt index a8d79b61dd5..0fdc4b03fe2 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/settings/CollapseTablesTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/settings/CollapseTablesTest.kt @@ -22,7 +22,7 @@ class CollapseTablesTest : BaseTest( private val bottomNavRobot = BottomNavRobot() private val settingsRobot = SettingsRobot() private val searchRobot = SearchRobot() - private val pageRobot = PageRobot() + private val pageRobot = PageRobot(context) private val systemRobot = SystemRobot() private val dialogRobot = DialogRobot() diff --git a/app/src/androidTest/java/org/wikipedia/tests/settings/DownloadReadingListTest.kt b/app/src/androidTest/java/org/wikipedia/tests/settings/DownloadReadingListTest.kt index cccc09f6b74..2db65fa3b87 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/settings/DownloadReadingListTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/settings/DownloadReadingListTest.kt @@ -23,7 +23,7 @@ class DownloadReadingListTest : BaseTest( private val systemRobot = SystemRobot() private val savedScreenRobot = SavedScreenRobot() private val searchRobot = SearchRobot() - private val pageRobot = PageRobot() + private val pageRobot = PageRobot(context) private val readingListRobot = ReadingListRobot() private val dialogRobot = DialogRobot() diff --git a/app/src/androidTest/java/org/wikipedia/tests/settings/LinkPreviewTest.kt b/app/src/androidTest/java/org/wikipedia/tests/settings/LinkPreviewTest.kt index 8f90e28a9cf..f0e19718acd 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/settings/LinkPreviewTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/settings/LinkPreviewTest.kt @@ -21,7 +21,7 @@ class LinkPreviewTest : BaseTest( private val bottomNavRobot = BottomNavRobot() private val settingsRobot = SettingsRobot() private val searchRobot = SearchRobot() - private val pageRobot = PageRobot() + private val pageRobot = PageRobot(context) private val systemRobot = SystemRobot() private val dialogRobot = DialogRobot() diff --git a/app/src/androidTest/java/org/wikipedia/tests/settings/ReadingFocusModeTest.kt b/app/src/androidTest/java/org/wikipedia/tests/settings/ReadingFocusModeTest.kt index d62c7f074c8..fd0d5a523a8 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/settings/ReadingFocusModeTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/settings/ReadingFocusModeTest.kt @@ -22,7 +22,7 @@ class ReadingFocusModeTest : BaseTest( private val settingsRobot = SettingsRobot() private val appThemeRobot = AppThemeRobot() private val searchRobot = SearchRobot() - private val pageRobot = PageRobot() + private val pageRobot = PageRobot(context) private val systemRobot = SystemRobot() @Test From 1fb0a7c26e0382b24e156f2a609b554c0ead7174 Mon Sep 17 00:00:00 2001 From: williamrai Date: Wed, 11 Dec 2024 17:32:55 -0500 Subject: [PATCH 08/22] - adds articles section test --- .../org/wikipedia/robots/feature/PageRobot.kt | 52 +++++++++++++++++++ .../tests/articles/ArticleSectionsTest.kt | 43 +++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 app/src/androidTest/java/org/wikipedia/tests/articles/ArticleSectionsTest.kt diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt index f6d40b77be5..4eaab5fe1f4 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt @@ -3,13 +3,20 @@ package org.wikipedia.robots.feature import android.annotation.SuppressLint import android.app.Activity import android.content.Context +import android.content.Intent +import android.net.Uri +import android.util.Log import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.intent.Intents.intended +import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction +import androidx.test.espresso.intent.matcher.IntentMatchers.hasData import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.web.sugar.Web.onWebView import androidx.test.espresso.web.webdriver.DriverAtoms.findElement import androidx.test.espresso.web.webdriver.DriverAtoms.webClick import androidx.test.espresso.web.webdriver.DriverAtoms.webScrollIntoView import androidx.test.espresso.web.webdriver.Locator +import org.hamcrest.Matchers.allOf import org.wikipedia.R import org.wikipedia.base.AssertJavascriptAction import org.wikipedia.base.BaseRobot @@ -114,6 +121,7 @@ class PageRobot(private val context: Context) : BaseRobot() { fun swipeTableOfContentsAllTheWayToBottom() = apply { swipeUp(R.id.toc_list) + delay(TestConfig.DELAY_MEDIUM) } fun clickAboutThisArticleText() = apply { @@ -188,6 +196,13 @@ class PageRobot(private val context: Context) : BaseRobot() { delay(TestConfig.DELAY_MEDIUM) } + fun clickToExpandQuickFactsTable() = apply { + onWebView() + .withElement(findElement(Locator.CSS_SELECTOR, ".pcs-table-infobox")) + .perform(webClick()) + delay(TestConfig.DELAY_MEDIUM) + } + @SuppressLint("CheckResult") fun verifyTableIsCollapsed() = apply { // checking if this class name exists @@ -257,4 +272,41 @@ class PageRobot(private val context: Context) : BaseRobot() { ) clickOnViewWithText(language) } + + fun scrollToAboutThisArticle() = apply { + onWebView() + .withElement(findElement(Locator.ID, "pcs-footer-container-menu-heading")) + .perform(webScrollIntoView()) + delay(TestConfig.DELAY_MEDIUM) + } + + fun goToViewEditHistory() = apply { + onWebView() + .withElement(findElement(Locator.CSS_SELECTOR, "a[title='View edit history']")) + .perform(webClick()) + delay(TestConfig.DELAY_MEDIUM) + } + + fun scrollToLegalSection() = apply { + onWebView() + .withElement(findElement(Locator.ID, "pcs-footer-container-legal")) + .perform(webScrollIntoView()) + delay(TestConfig.DELAY_MEDIUM) + } + + fun clickLegalLink() = apply { + try { + onWebView() + .withElement(findElement(Locator.CSS_SELECTOR, ".external")) + .perform(webClick()) + intended( + allOf( + hasAction(Intent.ACTION_VIEW), + hasData(Uri.parse("https://creativecommons.org/licenses/by-sa/4.0/")) + ) + ) + } catch (e: Exception) { + Log.e("PageRobot: ", "Link failed") + } + } } diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleSectionsTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleSectionsTest.kt new file mode 100644 index 00000000000..764241b318e --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleSectionsTest.kt @@ -0,0 +1,43 @@ +package org.wikipedia.tests.articles + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import org.junit.Test +import org.junit.runner.RunWith +import org.wikipedia.TestConstants.SEARCH_TERM +import org.wikipedia.base.BaseTest +import org.wikipedia.main.MainActivity +import org.wikipedia.robots.feature.PageRobot +import org.wikipedia.robots.feature.SearchRobot + +@LargeTest +@RunWith(AndroidJUnit4::class) +class ArticleSectionsTest : BaseTest( + activityClass = MainActivity::class.java, +) { + + private val searchRobot = SearchRobot() + private val pageRobot = PageRobot(context) + + @Test + fun runTest() { + searchRobot + .tapSearchView() + .typeTextInView(SEARCH_TERM) + .clickOnItemFromSearchList(0) + pageRobot + .dismissTooltip(activity) + setDeviceOrientation(isLandscape = true) + pageRobot + .scrollToCollapsingTables() + .clickToExpandQuickFactsTable() + .scrollToAboutThisArticle() + setDeviceOrientation(isLandscape = false) + pageRobot + .goToViewEditHistory() + .pressBack() + .goToTalkPage() + .pressBack() + .scrollToLegalSection() + } +} From c46ea624353311ee686aeaabbf41935431ccf51d Mon Sep 17 00:00:00 2001 From: williamrai Date: Thu, 12 Dec 2024 10:17:19 -0500 Subject: [PATCH 09/22] - adds table of contents test - adds support for clicking listView - adds support for clicking outside the view --- .../java/org/wikipedia/base/BaseRobot.kt | 46 +++++++++++++++ .../org/wikipedia/robots/feature/PageRobot.kt | 17 +++++- .../tests/articles/TableOfContentsTest.kt | 56 +++++++++++++++++++ 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 app/src/androidTest/java/org/wikipedia/tests/articles/TableOfContentsTest.kt diff --git a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt index 02b0f218b82..f90dfb4e25c 100644 --- a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt @@ -2,7 +2,9 @@ package org.wikipedia.base import android.app.Activity import android.graphics.Rect +import android.os.SystemClock import android.util.Log +import android.view.MotionEvent import android.view.View import android.widget.HorizontalScrollView import android.widget.ListView @@ -11,6 +13,7 @@ import android.widget.TextView import androidx.annotation.IdRes import androidx.core.widget.NestedScrollView import androidx.recyclerview.widget.RecyclerView +import androidx.test.espresso.Espresso.onData import androidx.test.espresso.Espresso.onView import androidx.test.espresso.Espresso.pressBack import androidx.test.espresso.UiController @@ -49,6 +52,7 @@ import org.hamcrest.Description import org.hamcrest.Matcher import org.hamcrest.Matchers import org.hamcrest.Matchers.allOf +import org.hamcrest.Matchers.anything import org.hamcrest.Matchers.containsString import org.hamcrest.Matchers.not import org.hamcrest.TypeSafeMatcher @@ -459,6 +463,48 @@ abstract class BaseRobot { .check(matches(atPosition(0, isLayoutDirectionRTL()))) } + protected fun clickXY(x: Int, y: Int): ViewAction { + return object : ViewAction { + override fun getConstraints(): Matcher { + return isDisplayed() + } + + override fun getDescription(): String { + return "Click at coordinates: $x, $y" + } + + override fun perform(uiController: UiController, view: View) { + uiController.injectMotionEvent( + MotionEvent.obtain( + SystemClock.uptimeMillis(), + SystemClock.uptimeMillis(), + MotionEvent.ACTION_DOWN, + x.toFloat(), + y.toFloat(), + 0 + )) + + uiController.injectMotionEvent( + MotionEvent.obtain( + SystemClock.uptimeMillis(), + SystemClock.uptimeMillis(), + MotionEvent.ACTION_UP, + x.toFloat(), + y.toFloat(), + 0 + )) + } + } + } + + protected fun clickOnListView(@IdRes viewId: Int, @IdRes childView: Int, position: Int) = apply { + onData(anything()) + .inAdapterView(withId(viewId)) + .atPosition(position) + .onChildView(withId(childView)) + .perform(click()) + } + private fun atPosition(position: Int, matcher: Matcher) = object : BoundedMatcher(RecyclerView::class.java) { override fun describeTo(description: Description) { description.appendText("has item at position $position") diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt index 4eaab5fe1f4..cf2d77a9522 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt @@ -119,12 +119,20 @@ class PageRobot(private val context: Context) : BaseRobot() { checkViewWithIdAndText(viewId = R.id.page_toc_item_text, text) } + fun clickOnTOCItem(position: Int) = apply { + clickOnListView( + viewId = R.id.toc_list, + childView = R.id.page_toc_item_text, + position = position + ) + } + fun swipeTableOfContentsAllTheWayToBottom() = apply { swipeUp(R.id.toc_list) delay(TestConfig.DELAY_MEDIUM) } - fun clickAboutThisArticleText() = apply { + fun clickAboutThisArticleTextInTOC() = apply { clickOnViewWithText("About this article") delay(TestConfig.DELAY_MEDIUM) } @@ -261,6 +269,7 @@ class PageRobot(private val context: Context) : BaseRobot() { fun openTableOfContents() = apply { clickOnDisplayedViewWithIdAnContentDescription(R.id.page_contents, context.getString(R.string.article_menu_bar_contents_button)) + delay(TestConfig.DELAY_SHORT) } fun selectSpanishLanguage() = apply { @@ -309,4 +318,10 @@ class PageRobot(private val context: Context) : BaseRobot() { Log.e("PageRobot: ", "Link failed") } } + + fun clickOutside() = apply { + onView(withId(R.id.navigation_drawer)) + .perform(clickXY(800, 500)) + delay(TestConfig.DELAY_SHORT) + } } diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/TableOfContentsTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/TableOfContentsTest.kt new file mode 100644 index 00000000000..1746966d052 --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/TableOfContentsTest.kt @@ -0,0 +1,56 @@ +package org.wikipedia.tests.articles + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import org.junit.Test +import org.junit.runner.RunWith +import org.wikipedia.Constants +import org.wikipedia.FakeData +import org.wikipedia.base.BaseTest +import org.wikipedia.base.DataInjector +import org.wikipedia.page.PageActivity +import org.wikipedia.page.PageActivity.Companion.ACTION_LOAD_IN_CURRENT_TAB +import org.wikipedia.page.PageActivity.Companion.EXTRA_HISTORYENTRY +import org.wikipedia.robots.DialogRobot +import org.wikipedia.robots.feature.PageRobot +import org.wikipedia.robots.screen.HomeScreenRobot + +@LargeTest +@RunWith(AndroidJUnit4::class) +class TableOfContentsTest : BaseTest( + activityClass = PageActivity::class.java, + dataInjector = DataInjector( + intentBuilder = { + action = ACTION_LOAD_IN_CURRENT_TAB + putExtra(EXTRA_HISTORYENTRY, FakeData.historyEntry) + putExtra(Constants.ARG_TITLE, FakeData.historyEntry.title) + } + ) +) { + private val pageRobot = PageRobot(context) + private val homeScreenRobot = HomeScreenRobot() + private val dialogRobot = DialogRobot() + + @Test + fun runTest() { + dialogRobot + .dismissBigEnglishDialog() + setDeviceOrientation(isLandscape = false) + homeScreenRobot + .dismissTooltip(activity) + tocTest() + setDeviceOrientation(isLandscape = true) + tocTest() + } + + private fun tocTest() { + pageRobot + .openTableOfContents() + .clickOutside() + .openTableOfContents() + .clickOnTOCItem(5) + .openTableOfContents() + .swipeTableOfContentsAllTheWayToBottom() + .clickAboutThisArticleTextInTOC() + } +} From 41d79c1f17ee426a5b7651a10bdd3a378d877ab7 Mon Sep 17 00:00:00 2001 From: williamrai Date: Thu, 12 Dec 2024 13:12:40 -0500 Subject: [PATCH 10/22] - adds OverflowMenuTest - creates a helper function for login user - adds function to verify user - adds new robot (PageActionItemRobot) --- .../wikipedia/robots/feature/LoginRobot.kt | 15 ++- .../robots/feature/PageActionItemRobot.kt | 98 ++++++++++++++++ .../org/wikipedia/robots/feature/PageRobot.kt | 5 + .../robots/screen/HomeScreenRobot.kt | 6 + .../tests/SuggestedEditScreenTest.kt | 5 +- .../tests/articles/OverflowMenuTest.kt | 109 ++++++++++++++++++ .../FeedScreenSuggestedEditTest.kt | 5 +- 7 files changed, 231 insertions(+), 12 deletions(-) create mode 100644 app/src/androidTest/java/org/wikipedia/robots/feature/PageActionItemRobot.kt create mode 100644 app/src/androidTest/java/org/wikipedia/tests/articles/OverflowMenuTest.kt diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/LoginRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/LoginRobot.kt index 4382a36a058..5b6f03c504e 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/LoginRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/LoginRobot.kt @@ -15,12 +15,19 @@ import org.wikipedia.base.TestConfig class LoginRobot : BaseRobot() { - fun clickLoginButton() = apply { + fun logInUser() = apply { + clickLoginButton() + setLoginUserNameFromBuildConfig() + setPasswordFromBuildConfig() + loginUser() + } + + private fun clickLoginButton() = apply { clicksOnDisplayedViewWithText(viewId = R.id.create_account_login_button, text = "Log in") delay(TestConfig.DELAY_MEDIUM) } - fun setLoginUserNameFromBuildConfig() = apply { + private fun setLoginUserNameFromBuildConfig() = apply { onView( allOf( TestUtil.withGrandparent(withId(R.id.login_username_text)), withClassName( @@ -30,12 +37,12 @@ class LoginRobot : BaseRobot() { .perform(replaceText(BuildConfig.TEST_LOGIN_USERNAME), closeSoftKeyboard()) } - fun setPasswordFromBuildConfig() = apply { + private fun setPasswordFromBuildConfig() = apply { onView(allOf(TestUtil.withGrandparent(withId(R.id.login_password_input)), withClassName(Matchers.`is`("org.wikipedia.views.PlainPasteEditText")))) .perform(replaceText(BuildConfig.TEST_LOGIN_PASSWORD), closeSoftKeyboard()) } - fun loginUser() = apply { + private fun loginUser() = apply { scrollToViewAndClick(R.id.login_button) delay(TestConfig.DELAY_LARGE) } diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/PageActionItemRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/PageActionItemRobot.kt new file mode 100644 index 00000000000..84b9fc5e7cb --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/PageActionItemRobot.kt @@ -0,0 +1,98 @@ +package org.wikipedia.robots.feature + +import android.app.Activity +import android.app.Instrumentation +import android.content.Intent +import androidx.test.espresso.intent.Intents.intending +import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction +import org.wikipedia.R +import org.wikipedia.base.BaseRobot +import org.wikipedia.base.TestConfig + +class PageActionItemRobot : BaseRobot() { + + fun clickShare() = apply { + // we are doing this because if we open the share dialog which is a system dialog and + // espresso cannot interact with it, so this tells the Espresso + // when the share dialog opens, pretend the user immediately pressed back + // or made a selection + intending(hasAction(Intent.ACTION_CHOOSER)).respondWith( + Instrumentation.ActivityResult(Activity.RESULT_OK, null) + ) + clickOnViewWithId(R.id.page_share) + delay(TestConfig.DELAY_SHORT) + } + + fun clickWatch() = apply { + clickOnViewWithId(R.id.page_watch) + delay(TestConfig.DELAY_SHORT) + } + + fun clickTalkPage() = apply { + clickOnViewWithId(R.id.page_view_talk_page) + delay(TestConfig.DELAY_SHORT) + } + + fun verifyTalkPageIsOpened() = apply { + checkViewWithTextDisplayed("Talk: Apple") + delay(TestConfig.DELAY_SHORT) + } + + fun clickEditHistory() = apply { + clickOnViewWithId(R.id.page_view_edit_history) + delay(TestConfig.DELAY_SHORT) + } + + fun verifyEditHistoryIsOpened() = apply { + checkViewWithTextDisplayed("Revision history: Apple") + delay(TestConfig.DELAY_SHORT) + } + + fun assertViewOnMapIsGreyed() = apply { + verifyTextViewColor( + textViewId = R.id.page_view_on_map, + colorResOrAttr = R.attr.inactive_color, + isAttr = true + ) + delay(TestConfig.DELAY_SHORT) + } + + fun clickNewTab() = apply { + clickOnViewWithId(R.id.page_new_tab) + delay(TestConfig.DELAY_SHORT) + } + + fun clickExplore() = apply { + clickOnViewWithId(R.id.page_explore) + delay(TestConfig.DELAY_SHORT) + } + + fun clickCategories() = apply { + clickOnViewWithId(R.id.page_categories) + delay(TestConfig.DELAY_SHORT) + } + + fun verifyCategoryDialogAppears() = apply { + checkViewWithTextDisplayed("Categories") + delay(TestConfig.DELAY_SHORT) + } + + fun clickEditArticles() = apply { + clickOnViewWithId(R.id.page_edit_article) + delay(TestConfig.DELAY_SHORT) + } + + fun clickCustomizeToolbar() = apply { + clickOnViewWithId(R.id.customize_toolbar) + delay(TestConfig.DELAY_SHORT) + } + + fun verifyCustomizeToolbarIsOpened() = apply { + checkViewWithTextDisplayed("Customize toolbar") + } + + fun pressBack() = apply { + goBack() + delay(TestConfig.DELAY_SHORT) + } +} diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt index cf2d77a9522..431b150f769 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt @@ -324,4 +324,9 @@ class PageRobot(private val context: Context) : BaseRobot() { .perform(clickXY(800, 500)) delay(TestConfig.DELAY_SHORT) } + + fun clickOverFlowMenuToolbar() = apply { + clickOnViewWithId(viewId = R.id.page_toolbar_button_show_overflow_menu) + delay(TestConfig.DELAY_SHORT) + } } diff --git a/app/src/androidTest/java/org/wikipedia/robots/screen/HomeScreenRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/screen/HomeScreenRobot.kt index fb8eaad6064..fd6534e15a4 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/screen/HomeScreenRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/screen/HomeScreenRobot.kt @@ -64,4 +64,10 @@ class HomeScreenRobot : BaseRobot() { Log.d("HomeScreenRobot", "no view because the device has no internet") } } + + fun verifyIfSnackBarAppears() = apply { + onView(withId(com.google.android.material.R.id.snackbar_text)) + .check(matches(isDisplayed())) + delay(TestConfig.DELAY_SHORT) + } } diff --git a/app/src/androidTest/java/org/wikipedia/tests/SuggestedEditScreenTest.kt b/app/src/androidTest/java/org/wikipedia/tests/SuggestedEditScreenTest.kt index 257ecc9bdb7..8fc769b825b 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/SuggestedEditScreenTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/SuggestedEditScreenTest.kt @@ -34,10 +34,7 @@ class SuggestedEditScreenTest : BaseTest( .navigateToMoreMenu() .clickLoginMenuItem() loginRobot - .clickLoginButton() - .setLoginUserNameFromBuildConfig() - .setPasswordFromBuildConfig() - .loginUser() + .logInUser() systemRobot .clickOnSystemDialogWithText("Allow") navRobot diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/OverflowMenuTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/OverflowMenuTest.kt new file mode 100644 index 00000000000..e26222a8cd4 --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/OverflowMenuTest.kt @@ -0,0 +1,109 @@ +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import org.junit.Test +import org.junit.runner.RunWith +import org.wikipedia.TestConstants.SEARCH_TERM +import org.wikipedia.base.BaseTest +import org.wikipedia.main.MainActivity +import org.wikipedia.robots.DialogRobot +import org.wikipedia.robots.SystemRobot +import org.wikipedia.robots.feature.LoginRobot +import org.wikipedia.robots.feature.PageActionItemRobot +import org.wikipedia.robots.feature.PageRobot +import org.wikipedia.robots.feature.SearchRobot +import org.wikipedia.robots.navigation.BottomNavRobot +import org.wikipedia.robots.screen.HomeScreenRobot + +@LargeTest +@RunWith(AndroidJUnit4::class) +class OverflowMenuTest : BaseTest( + activityClass = MainActivity::class.java, +) { + private val loginRobot = LoginRobot() + private val pageRobot = PageRobot(context) + private val homeScreenRobot = HomeScreenRobot() + private val dialogRobot = DialogRobot() + private val pageActionItemRobot = PageActionItemRobot() + private val bottomNavRobot = BottomNavRobot() + private val systemRobot = SystemRobot() + private val searchRobot = SearchRobot() + + @Test + fun runTest() { + setDeviceOrientation(isLandscape = false) + systemRobot + .clickOnSystemDialogWithText("Allow") + bottomNavRobot + .navigateToMoreMenu() + .clickLoginMenuItem() + loginRobot + .logInUser() + systemRobot + .clickOnSystemDialogWithText("Allow") + searchRobot + .tapSearchView() + .typeTextInView(SEARCH_TERM) + .clickOnItemFromSearchList(0) + dialogRobot + .dismissBigEnglishDialog() + homeScreenRobot + .dismissTooltip(activity) + pageRobot + .clickOverFlowMenuToolbar() + pageActionItemRobot + .clickShare() + pageRobot + .clickOverFlowMenuToolbar() + pageActionItemRobot + .clickWatch() + homeScreenRobot + .verifyIfSnackBarAppears() + pageRobot + .clickOverFlowMenuToolbar() + pageActionItemRobot + .clickTalkPage() + .verifyTalkPageIsOpened() + .pressBack() + pageRobot + .clickOverFlowMenuToolbar() + pageActionItemRobot + .clickEditHistory() + .verifyEditHistoryIsOpened() + .pressBack() + pageRobot + .clickOverFlowMenuToolbar() + pageActionItemRobot + .assertViewOnMapIsGreyed() + pageActionItemRobot + .clickNewTab() + .pressBack() + searchRobot + .clickOnItemFromSearchList(0) + dialogRobot + .dismissBigEnglishDialog() + pageRobot + .clickOverFlowMenuToolbar() + pageActionItemRobot + .clickExplore() + searchRobot + .tapSearchView() + .typeTextInView(SEARCH_TERM) + .clickOnItemFromSearchList(0) + pageRobot + .clickOverFlowMenuToolbar() + pageActionItemRobot + .clickCategories() + .verifyCategoryDialogAppears() + .pressBack() + pageRobot + .clickOverFlowMenuToolbar() + pageActionItemRobot + .clickEditArticles() + .pressBack() + pageRobot + .clickOverFlowMenuToolbar() + pageActionItemRobot + .clickCustomizeToolbar() + .verifyCustomizeToolbarIsOpened() + } +} diff --git a/app/src/androidTest/java/org/wikipedia/tests/explorefeed/FeedScreenSuggestedEditTest.kt b/app/src/androidTest/java/org/wikipedia/tests/explorefeed/FeedScreenSuggestedEditTest.kt index 66007f2b871..7da5f2c4453 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/explorefeed/FeedScreenSuggestedEditTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/explorefeed/FeedScreenSuggestedEditTest.kt @@ -36,10 +36,7 @@ class FeedScreenSuggestedEditTest : BaseTest( .navigateToMoreMenu() .clickLoginMenuItem() loginRobot - .clickLoginButton() - .setLoginUserNameFromBuildConfig() - .setPasswordFromBuildConfig() - .loginUser() + .logInUser() // After log in, notification dialog appears systemRobot .clickOnSystemDialogWithText(text = "Allow") From 5440d02afba54ed70ac24f3aacc0ef2d9b2b4314 Mon Sep 17 00:00:00 2001 From: williamrai Date: Thu, 12 Dec 2024 17:33:38 -0500 Subject: [PATCH 11/22] - adds an async loading function - adds a GifMatchers - adds new Robot (MediaRobot) - adds new scroll function to PageRobot - adds SpecialArticleTest --- .../java/org/wikipedia/TestConstants.kt | 5 ++ .../java/org/wikipedia/base/BaseRobot.kt | 16 ++++ .../java/org/wikipedia/base/GifMatchers.kt | 27 +++++++ .../wikipedia/robots/feature/MediaRobot.kt | 17 +++++ .../org/wikipedia/robots/feature/PageRobot.kt | 17 ++++- .../wikipedia/robots/feature/SearchRobot.kt | 5 ++ .../LeadNonLeadImageAndPreviewLinkTest.kt | 1 - .../tests/articles/SpecialArticleTest.kt | 76 +++++++++++++++++++ 8 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 app/src/androidTest/java/org/wikipedia/base/GifMatchers.kt create mode 100644 app/src/androidTest/java/org/wikipedia/robots/feature/MediaRobot.kt create mode 100644 app/src/androidTest/java/org/wikipedia/tests/articles/SpecialArticleTest.kt diff --git a/app/src/androidTest/java/org/wikipedia/TestConstants.kt b/app/src/androidTest/java/org/wikipedia/TestConstants.kt index 4bf2b738768..271cb199429 100644 --- a/app/src/androidTest/java/org/wikipedia/TestConstants.kt +++ b/app/src/androidTest/java/org/wikipedia/TestConstants.kt @@ -12,4 +12,9 @@ object TestConstants { const val SUGGESTED_EDITS = "Suggested edits" const val SEARCH_TERM = "apple" const val SEARCH_TERM2 = "orange" + const val SPECIAL_ARTICLE_VORTEX_SHEDDING = "Vortex shedding" + const val SPECIAL_ARTICLE_AVATAR_2009 = "Avatar 2009" + const val SPECIAL_ARTICLE_BILL_CLINTON = "Bill Clinton" + const val SPECIAL_ARTICLE_INDIA = "India" + const val SPECIAL_ARTICLE_USA = "USA" } diff --git a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt index f90dfb4e25c..08227db8cdd 100644 --- a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt @@ -505,6 +505,22 @@ abstract class BaseRobot { .perform(click()) } + protected fun waitForAsyncLoading(): ViewAction { + return object : ViewAction { + override fun getConstraints(): Matcher { + return isDisplayed() + } + + override fun getDescription(): String { + return "wait for async loading" + } + + override fun perform(uiController: UiController, view: View?) { + uiController.loopMainThreadForAtLeast(2000) + } + } + } + private fun atPosition(position: Int, matcher: Matcher) = object : BoundedMatcher(RecyclerView::class.java) { override fun describeTo(description: Description) { description.appendText("has item at position $position") diff --git a/app/src/androidTest/java/org/wikipedia/base/GifMatchers.kt b/app/src/androidTest/java/org/wikipedia/base/GifMatchers.kt new file mode 100644 index 00000000000..386227f45e9 --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/base/GifMatchers.kt @@ -0,0 +1,27 @@ +package org.wikipedia.base + +import android.view.View +import android.widget.ImageView +import androidx.test.espresso.matcher.BoundedMatcher +import com.bumptech.glide.load.resource.gif.GifDrawable +import org.hamcrest.Description +import org.hamcrest.Matcher + +object GifMatchers { + fun hasGifDrawable(): Matcher { + return object : BoundedMatcher(ImageView::class.java) { + override fun describeTo(description: Description) { + description.appendText("has gif drawable") + } + + override fun matchesSafely(imageView: ImageView): Boolean { + val drawable = imageView.drawable + + return when (drawable) { + is GifDrawable -> true + else -> false + } + } + } + } +} diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/MediaRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/MediaRobot.kt new file mode 100644 index 00000000000..abbf4ea6325 --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/MediaRobot.kt @@ -0,0 +1,17 @@ +package org.wikipedia.robots.feature + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.withId +import org.wikipedia.R +import org.wikipedia.base.BaseRobot +import org.wikipedia.base.GifMatchers + +class MediaRobot : BaseRobot() { + + fun verifyLeadImageHasGif() = apply { + onView(withId(R.id.view_page_header_image)) + .perform(waitForAsyncLoading()) + .check(matches(GifMatchers.hasGifDrawable())) + } +} diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt index 431b150f769..df92229cfe1 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt @@ -40,7 +40,7 @@ class PageRobot(private val context: Context) : BaseRobot() { verifyH1Title(expectedTitle) } - fun previewArticle() = apply { + fun verifyPreviewArticleDialogAppears() = apply { clickOnDisplayedView(R.id.link_preview_toolbar) delay(TestConfig.DELAY_MEDIUM) } @@ -303,6 +303,21 @@ class PageRobot(private val context: Context) : BaseRobot() { delay(TestConfig.DELAY_MEDIUM) } + fun scrollToAdministrativeDivisionOfIndiaArticle() = apply { + onWebView() + .withElement(findElement(Locator.ID, "Administrative_divisions")) + .perform(webClick()) + delay(TestConfig.DELAY_MEDIUM) + } + + fun scrollToAndhraPradeshOnIndiaArticle() = apply { + onWebView() + .withElement(findElement(Locator.CSS_SELECTOR, "a[title='Andhra Pradesh']")) + .perform(webScrollIntoView()) + .perform(webClick()) + delay(TestConfig.DELAY_MEDIUM) + } + fun clickLegalLink() = apply { try { onWebView() diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt index 184759402e0..a6b040a5b13 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt @@ -16,6 +16,11 @@ class SearchRobot : BaseRobot() { delay(TestConfig.DELAY_SHORT) } + fun clickSearchFromPageView() = apply { + clickOnViewWithId(viewId = R.id.page_toolbar_button_search) + delay(TestConfig.DELAY_SHORT) + } + fun clickSearchContainer() = apply { // Click the Search box clickOnDisplayedView(R.id.search_container) diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt index 63bad94dfd9..29d7c17225b 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt @@ -31,7 +31,6 @@ class LeadNonLeadImageAndPreviewLinkTest : BaseTest( @Test fun runTest() { pageRobot - .verifyLeadImageIsNotVisible() .clickLeadImage() .swipePagerLeft() .pressBack() diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/SpecialArticleTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/SpecialArticleTest.kt new file mode 100644 index 00000000000..f4b81ac6560 --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/SpecialArticleTest.kt @@ -0,0 +1,76 @@ +package org.wikipedia.tests.articles + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import org.junit.Test +import org.junit.runner.RunWith +import org.wikipedia.TestConstants +import org.wikipedia.base.BaseTest +import org.wikipedia.main.MainActivity +import org.wikipedia.robots.SystemRobot +import org.wikipedia.robots.feature.MediaRobot +import org.wikipedia.robots.feature.PageRobot +import org.wikipedia.robots.feature.SearchRobot +import org.wikipedia.robots.screen.HomeScreenRobot + +@LargeTest +@RunWith(AndroidJUnit4::class) +class SpecialArticleTest : BaseTest( + activityClass = MainActivity::class.java +) { + + private val homeScreenRobot = HomeScreenRobot() + private val searchRobot = SearchRobot() + private val systemRobot = SystemRobot() + private val mediaRobot = MediaRobot() + private val pageRobot = PageRobot(context) + + @Test + fun runTest() { + systemRobot + .clickOnSystemDialogWithText("Allow") + searchRobot + .tapSearchView() + .typeTextInView(TestConstants.SPECIAL_ARTICLE_VORTEX_SHEDDING) + .clickOnItemFromSearchList(0) + mediaRobot + .verifyLeadImageHasGif() + searchRobot + .clickSearchFromPageView() + .typeTextInView(TestConstants.SPECIAL_ARTICLE_AVATAR_2009) + .clickOnItemFromSearchList(0) + pageRobot + .clickLeadImage() + .swipePagerLeft() + .swipePagerLeft() + .swipePagerLeft() + .pressBack() + searchRobot + .clickSearchFromPageView() + .typeTextInView(TestConstants.SPECIAL_ARTICLE_BILL_CLINTON) + .clickOnItemFromSearchList(0) + pageRobot + .clickLeadImage() + .swipePagerLeft() + .swipePagerLeft() + .swipePagerLeft() + .pressBack() + searchRobot + .clickSearchFromPageView() + .typeTextInView(TestConstants.SPECIAL_ARTICLE_INDIA) + .clickOnItemFromSearchList(0) + pageRobot + .scrollToAdministrativeDivisionOfIndiaArticle() + .scrollToAndhraPradeshOnIndiaArticle() + .verifyPreviewDialogAppears() + .pressBack() + .pressBack() + searchRobot + .clickSearchFromPageView() + .typeTextInView(TestConstants.SPECIAL_ARTICLE_USA) + .clickOnItemFromSearchList(0) + pageRobot + .scrollToCollapsingTables() + .clickToExpandQuickFactsTable() + } +} From 1128119d14ee7dbf9f1a9a1c5ede8e9dcd4289e4 Mon Sep 17 00:00:00 2001 From: williamrai Date: Fri, 13 Dec 2024 15:16:50 -0500 Subject: [PATCH 12/22] - adds media test - adds pinch to zoom and drag espresso test - adds double click test --- .../java/org/wikipedia/base/BaseRobot.kt | 11 ++- .../wikipedia/robots/feature/MediaRobot.kt | 91 +++++++++++++++++++ .../org/wikipedia/tests/articles/MediaTest.kt | 59 ++++++++++++ 3 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 app/src/androidTest/java/org/wikipedia/tests/articles/MediaTest.kt diff --git a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt index 08227db8cdd..b4949499824 100644 --- a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt @@ -22,6 +22,7 @@ import androidx.test.espresso.ViewAssertion import androidx.test.espresso.action.ViewActions import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.action.ViewActions.closeSoftKeyboard +import androidx.test.espresso.action.ViewActions.doubleClick import androidx.test.espresso.action.ViewActions.replaceText import androidx.test.espresso.action.ViewActions.scrollTo import androidx.test.espresso.action.ViewActions.swipeLeft @@ -62,7 +63,6 @@ import org.wikipedia.TestUtil.waitOnId import java.util.concurrent.TimeUnit abstract class BaseRobot { - protected fun clickOnViewWithIdAndContainsString(@IdRes viewId: Int, text: String) { onView(allOf( withId(viewId), @@ -125,6 +125,15 @@ abstract class BaseRobot { ) } + protected fun doubleClickOnViewWithId(@IdRes viewId: Int) { + onView( + allOf( + withId(viewId), + isDisplayed() + ) + ).perform(doubleClick()) + } + protected fun assertColorForChildItemInAList( @IdRes listId: Int, @IdRes childItemId: Int, diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/MediaRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/MediaRobot.kt index abbf4ea6325..7e8c03e2b4f 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/MediaRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/MediaRobot.kt @@ -1,11 +1,25 @@ package org.wikipedia.robots.feature +import android.app.Activity +import android.app.Instrumentation +import android.content.Context +import android.content.Intent +import android.util.Log import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu +import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.intent.Intents.intending +import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.uiautomator.UiDevice +import androidx.test.uiautomator.UiSelector +import org.hamcrest.CoreMatchers.allOf import org.wikipedia.R import org.wikipedia.base.BaseRobot import org.wikipedia.base.GifMatchers +import org.wikipedia.base.TestConfig class MediaRobot : BaseRobot() { @@ -14,4 +28,81 @@ class MediaRobot : BaseRobot() { .perform(waitForAsyncLoading()) .check(matches(GifMatchers.hasGifDrawable())) } + + fun pinchZoomAction(context: Context, uiDevice: UiDevice) = apply { + val imageView = uiDevice.findObject(UiSelector().resourceId("${context.packageName}:id/imageView")) + imageView.pinchIn(75, 20) + imageView.pinchOut(75, 20) + imageView.dragTo(500, 700, 20) + } + + fun doubleTapToZoomOut() = apply { + doubleClickOnViewWithId(viewId = R.id.imageView) + delay(TestConfig.DELAY_SHORT) + } + + fun toggleOverlayVisibility() = apply { + onView( + allOf( + withId(R.id.imageView), + isDisplayed() + ) + ).perform(click()) + delay(TestConfig.DELAY_SHORT) + } + + fun verifyOverlayVisibility(isVisible: Boolean) = apply { + if (isVisible) { + checkViewExists(R.id.toolbar_container) + delay(TestConfig.DELAY_MEDIUM) + return@apply + } + + checkViewDoesNotExist(R.id.toolbar_container) + delay(TestConfig.DELAY_MEDIUM) + } + + fun navigateUp() = apply { + clickOnDisplayedViewWithContentDescription("Navigate up") + } + + fun clickCC() = apply { + clickOnViewWithId(R.id.license_icon) + delay(TestConfig.DELAY_SHORT) + } + + fun verifyCCisClicked() = apply { + checkPartialString("CC") + delay(TestConfig.DELAY_SHORT) + } + + fun tapHamburger(context: Context) = apply { + openActionBarOverflowOrOptionsMenu(context) + delay(TestConfig.DELAY_SHORT) + } + + fun goToImagePage(context: Context) = apply { + clickOnViewWithText(context.getString(R.string.menu_gallery_visit_image_page)) + delay(TestConfig.DELAY_SHORT) + } + + fun verifyImagePageIsVisible() = apply { + try { + clickOnViewWithId(R.id.filePageView) + } catch (e: Exception) { + Log.e("MediaRobot:", "filePageView must not be visible.") + } + } + + fun clickShareButton() = apply { + // we are doing this because if we open the share dialog which is a system dialog and + // espresso cannot interact with it, so this tells the Espresso + // when the share dialog opens, pretend the user immediately pressed back + // or made a selection + intending(hasAction(Intent.ACTION_CHOOSER)).respondWith( + Instrumentation.ActivityResult(Activity.RESULT_OK, null) + ) + clickOnViewWithId(R.id.menu_gallery_share) + delay(TestConfig.DELAY_SHORT) + } } diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/MediaTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/MediaTest.kt new file mode 100644 index 00000000000..b4e7911afe8 --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/MediaTest.kt @@ -0,0 +1,59 @@ +package org.wikipedia.tests.articles + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import org.junit.Test +import org.junit.runner.RunWith +import org.wikipedia.TestConstants +import org.wikipedia.base.BaseTest +import org.wikipedia.main.MainActivity +import org.wikipedia.robots.SystemRobot +import org.wikipedia.robots.feature.MediaRobot +import org.wikipedia.robots.feature.PageRobot +import org.wikipedia.robots.feature.SearchRobot + +@LargeTest +@RunWith(AndroidJUnit4::class) +class MediaTest : BaseTest( + activityClass = MainActivity::class.java +) { + private val searchRobot = SearchRobot() + private val systemRobot = SystemRobot() + private val mediaRobot = MediaRobot() + private val pageRobot = PageRobot(context) + + @Test + fun runTest() { + systemRobot + .clickOnSystemDialogWithText("Allow") + searchRobot + .tapSearchView() + .typeTextInView(TestConstants.SPECIAL_ARTICLE_VORTEX_SHEDDING) + .clickOnItemFromSearchList(0) + mediaRobot + .verifyLeadImageHasGif() + pageRobot + .clickLeadImage() + .swipePagerLeft() + mediaRobot + .pinchZoomAction(context, device) + pageRobot + .swipePagerLeft() + mediaRobot + .doubleTapToZoomOut() + .doubleTapToZoomOut() + .doubleTapToZoomOut() + .toggleOverlayVisibility() + .verifyOverlayVisibility(isVisible = false) + .toggleOverlayVisibility() + .verifyOverlayVisibility(isVisible = true) + .clickShareButton() + .clickCC() + .verifyCCisClicked() + .tapHamburger(context) + .goToImagePage(context) + .verifyImagePageIsVisible() + mediaRobot + .navigateUp() + } +} From 580fb2944ee78fccb40ba28c6dcd02a4b8cdf69e Mon Sep 17 00:00:00 2001 From: williamrai Date: Mon, 16 Dec 2024 17:07:25 -0500 Subject: [PATCH 13/22] - adds SavedArticleTest - adds helper functions for SavedArticleTest --- .../java/org/wikipedia/base/BaseRobot.kt | 11 +++ .../java/org/wikipedia/robots/DialogRobot.kt | 8 ++ .../robots/feature/ExploreFeedRobot.kt | 10 +++ .../wikipedia/robots/feature/SearchRobot.kt | 10 +++ .../robots/screen/SavedScreenRobot.kt | 42 ++++++++++- .../tests/articles/SavedArticleTest.kt | 73 +++++++++++++++++++ 6 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt diff --git a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt index b4949499824..dfe498be57b 100644 --- a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt @@ -23,6 +23,7 @@ import androidx.test.espresso.action.ViewActions import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.action.ViewActions.closeSoftKeyboard import androidx.test.espresso.action.ViewActions.doubleClick +import androidx.test.espresso.action.ViewActions.longClick import androidx.test.espresso.action.ViewActions.replaceText import androidx.test.espresso.action.ViewActions.scrollTo import androidx.test.espresso.action.ViewActions.swipeLeft @@ -114,6 +115,16 @@ abstract class BaseRobot { ) } + protected fun longClickOnItemInList(@IdRes listId: Int, position: Int) { + onView(withId(listId)) + .perform( + RecyclerViewActions.actionOnItemAtPosition( + position, + longClick() + ) + ) + } + protected fun clickOnSpecificItemInList(@IdRes listId: Int, @IdRes itemId: Int, position: Int) { onView(withId(listId)) .perform( diff --git a/app/src/androidTest/java/org/wikipedia/robots/DialogRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/DialogRobot.kt index 37629f28636..df61a8d01fb 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/DialogRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/DialogRobot.kt @@ -20,4 +20,12 @@ class DialogRobot : BaseRobot() { Log.d("DialogRobot: ", "No Big English dialog shown.") } } + + fun dismissShareReadingListDialog() = apply { + try { + clickOnViewWithText(text = "Got it") + } catch (e: Exception) { + Log.d("DialogRobot: ", "No share reading list dialog shown.") + } + } } diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt index 176e5c06d2b..381537571e4 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt @@ -206,6 +206,16 @@ class ExploreFeedRobot : BaseRobot() { )).check(ColorAssertions.hasColor(R.attr.primary_color, isAttr = true, ColorAssertions.ColorType.TextColor)) } + fun longClickFeaturedArticleCardContainer() = apply { + makeViewVisibleAndLongClick(viewId = R.id.view_featured_article_card_content_container, parentViewId = R.id.feed_view) + delay(TestConfig.DELAY_SHORT) + } + + fun clickSave() = apply { + clickOnViewWithText("Save") + delay(TestConfig.DELAY_SHORT) + } + private fun scrollToCardViewWithTitle( title: String, @IdRes textViewId: Int = R.id.view_card_header_title, diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt index a6b040a5b13..eb6a0040031 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt @@ -56,6 +56,11 @@ class SearchRobot : BaseRobot() { delay(TestConfig.DELAY_SHORT) } + fun longClickOnItemFromSearchList(position: Int) = apply { + longClickOnItemInList(R.id.search_results_list, position) + delay(TestConfig.DELAY_SHORT) + } + fun verifyRecentSearchesAppears() = apply { checkViewWithTextDisplayed("Recent searches:") } @@ -77,6 +82,11 @@ class SearchRobot : BaseRobot() { checkRTLDirectionOfRecyclerViewItem(R.id.search_results_list) } + fun clickSave() = apply { + clickOnViewWithText("Save") + delay(TestConfig.DELAY_SHORT) + } + fun pressBack() = apply { goBack() delay(TestConfig.DELAY_SHORT) diff --git a/app/src/androidTest/java/org/wikipedia/robots/screen/SavedScreenRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/screen/SavedScreenRobot.kt index 8699be93440..57a42dd3ce8 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/screen/SavedScreenRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/screen/SavedScreenRobot.kt @@ -1,14 +1,27 @@ package org.wikipedia.robots.screen import android.app.Activity +import androidx.recyclerview.widget.RecyclerView +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.assertion.ViewAssertions.doesNotExist +import androidx.test.espresso.contrib.RecyclerViewActions +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import org.hamcrest.Matchers.allOf import org.wikipedia.R import org.wikipedia.base.BaseRobot import org.wikipedia.base.TestConfig class SavedScreenRobot : BaseRobot() { - fun clickOnFirstItemInTheList() = apply { - clickRecyclerViewItemAtPosition(R.id.recycler_view, 0) + fun clickItemOnTheList(position: Int) = apply { + clickRecyclerViewItemAtPosition(R.id.recycler_view, position) + delay(TestConfig.DELAY_LARGE) + } + + fun clickItemOnReadingList(position: Int) = apply { + clickRecyclerViewItemAtPosition(R.id.reading_list_recycler_view, position) delay(TestConfig.DELAY_LARGE) } @@ -31,6 +44,31 @@ class SavedScreenRobot : BaseRobot() { delay(TestConfig.DELAY_SHORT) } + fun swipeToDelete(position: Int) = apply { + onView(withId(R.id.reading_list_recycler_view)) + .perform( + RecyclerViewActions.actionOnItemAtPosition( + position, + ViewActions.swipeLeft() + ) + ) + delay(TestConfig.DELAY_MEDIUM) + } + + fun verifySavedArticleIsRemoved(title: String) = apply { + onView( + allOf( + withId(R.id.page_list_item_title), + withText(title) + ) + ).check(doesNotExist()) + } + + fun clickFilterList() = apply { + clickOnViewWithId(R.id.menu_search_lists) + delay(TestConfig.DELAY_MEDIUM) + } + fun pressBack() = apply { goBack() delay(TestConfig.DELAY_SHORT) diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt new file mode 100644 index 00000000000..52e1f64d637 --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt @@ -0,0 +1,73 @@ +package org.wikipedia.tests.articles + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import org.junit.Test +import org.junit.runner.RunWith +import org.wikipedia.TestConstants +import org.wikipedia.TestConstants.FEATURED_ARTICLE +import org.wikipedia.base.BaseTest +import org.wikipedia.main.MainActivity +import org.wikipedia.robots.DialogRobot +import org.wikipedia.robots.SystemRobot +import org.wikipedia.robots.feature.ExploreFeedRobot +import org.wikipedia.robots.feature.PageRobot +import org.wikipedia.robots.feature.SearchRobot +import org.wikipedia.robots.navigation.BottomNavRobot +import org.wikipedia.robots.screen.SavedScreenRobot + +@LargeTest +@RunWith(AndroidJUnit4::class) +class SavedArticleTest : BaseTest( + activityClass = MainActivity::class.java +) { + private val pageRobot = PageRobot(context) + private val searchRobot = SearchRobot() + private val systemRobot = SystemRobot() + private val exploreFeedRobot = ExploreFeedRobot() + private val bottomNavRobot = BottomNavRobot() + private val savedScreenRobot = SavedScreenRobot() + private val dialogRobot = DialogRobot() + + @Test + fun runTest() { + systemRobot + .clickOnSystemDialogWithText("Allow") + searchRobot + .tapSearchView() + .typeTextInView(TestConstants.SEARCH_TERM) + .longClickOnItemFromSearchList(0) + .clickSave() + .pressBack() + .pressBack() + exploreFeedRobot + .scrollToItem(title = FEATURED_ARTICLE) + .longClickFeaturedArticleCardContainer() + .clickSave() + bottomNavRobot + .navigateToSavedPage() + setDeviceOrientation(isLandscape = true) + savedScreenRobot + .clickFilterList() + searchRobot + .typeTextInView(TestConstants.SEARCH_TERM) + .pressBack() + .pressBack() + setDeviceOrientation(isLandscape = false) + savedScreenRobot + .clickItemOnTheList(0) + dialogRobot + .dismissShareReadingListDialog() + savedScreenRobot + .clickFilterList() + searchRobot + .typeTextInView(TestConstants.SEARCH_TERM) + savedScreenRobot + .clickItemOnReadingList(0) + .pressBack() + .pressBack() + .pressBack() + .swipeToDelete(2) + .verifySavedArticleIsRemoved(TestConstants.SEARCH_TERM) + } +} From edfdff15b86fa1aae0739ddf0956ea151e7e09c3 Mon Sep 17 00:00:00 2001 From: williamrai Date: Tue, 17 Dec 2024 13:36:21 -0500 Subject: [PATCH 14/22] - adds SavedArticleOnlineOfflineTest - fixes test - adds ArticlesTestSuite --- .../java/org/wikipedia/base/BaseRobot.kt | 32 +++++---- .../robots/feature/PageActionItemRobot.kt | 9 ++- .../wikipedia/robots/feature/SearchRobot.kt | 5 ++ .../org/wikipedia/robots/feature/TabsRobot.kt | 10 ++- .../robots/screen/SavedScreenRobot.kt | 30 ++++++++ .../tests/articles/ArticleTabTest.kt | 7 +- .../org/wikipedia/tests/articles/MediaTest.kt | 2 + .../tests/articles/OverflowMenuTest.kt | 3 +- .../articles/SavedArticleOnlineOfflineTest.kt | 70 +++++++++++++++++++ .../tests/articles/SavedArticleTest.kt | 4 +- .../wikipedia/testsuites/ArticlesTestSuite.kt | 33 +++++++++ 11 files changed, 177 insertions(+), 28 deletions(-) create mode 100644 app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleOnlineOfflineTest.kt create mode 100644 app/src/androidTest/java/org/wikipedia/testsuites/ArticlesTestSuite.kt diff --git a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt index 0ee753109e9..65e5f81eff5 100644 --- a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt @@ -146,21 +146,6 @@ abstract class BaseRobot { ).perform(doubleClick()) } - protected fun assertColorForChildItemInAList( - @IdRes listId: Int, - @IdRes childItemId: Int, - colorResOrAttr: Int, - position: Int, - isAttr: Boolean = true, - colorType: ColorAssertions.ColorType = ColorAssertions.ColorType.TextColor - ) { - onView(withId(listId)) - .perform(RecyclerViewActions.scrollToPosition(position)) - .check(matchesAtPosition(position, targetViewId = childItemId, assertion = { view -> - ColorAssertions.hasColor(colorResOrAttr, isAttr, colorType) - .check(view, null) - })) - } protected fun scrollToView(@IdRes viewId: Int) { onView(withId(viewId)).perform(scrollTo()) @@ -267,6 +252,14 @@ abstract class BaseRobot { .check(matches(matcher)) } + protected fun verifyMessageOfSnackbar(text: String) { + onView( + allOf( + withId(com.google.android.material.R.id.snackbar_text), + withText(text) + )).check(matches(isDisplayed())) + } + protected fun swipeDownOnTheWebView(@IdRes viewId: Int) { onView(withId(viewId)).perform(TestUtil.swipeDownWebView()) delay(TestConfig.DELAY_LARGE) @@ -577,6 +570,15 @@ abstract class BaseRobot { })) } + protected fun checkImageIsVisibleInsideARecyclerView(@IdRes listId: Int, + @IdRes childItemId: Int, + position: Int) { + onView(withId(listId)) + .check(matchesAtPosition(position, targetViewId = childItemId, assertion = { view -> + matches(isDisplayed()) + })) + } + private fun clickChildViewWithId(@IdRes id: Int) = object : ViewAction { override fun getConstraints() = null diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/PageActionItemRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/PageActionItemRobot.kt index 84b9fc5e7cb..8ff26172be3 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/PageActionItemRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/PageActionItemRobot.kt @@ -8,6 +8,9 @@ import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction import org.wikipedia.R import org.wikipedia.base.BaseRobot import org.wikipedia.base.TestConfig +import org.wikipedia.base.TestThemeColorType +import org.wikipedia.base.TestWikipediaColors +import org.wikipedia.theme.Theme class PageActionItemRobot : BaseRobot() { @@ -48,11 +51,11 @@ class PageActionItemRobot : BaseRobot() { delay(TestConfig.DELAY_SHORT) } - fun assertViewOnMapIsGreyed() = apply { + fun assertViewOnMapIsGreyed(theme: Theme) = apply { + val color = TestWikipediaColors.getGetColor(theme, TestThemeColorType.INACTIVE) verifyTextViewColor( textViewId = R.id.page_view_on_map, - colorResOrAttr = R.attr.inactive_color, - isAttr = true + colorResId = color, ) delay(TestConfig.DELAY_SHORT) } diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt index eb6a0040031..2f141272344 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt @@ -27,6 +27,11 @@ class SearchRobot : BaseRobot() { delay(TestConfig.DELAY_SHORT) } + fun clickSearchInsideSearchFragment() = apply { + clickOnViewWithId(R.id.search_cab_view) + delay(TestConfig.DELAY_SHORT) + } + fun typeTextInView(searchTerm: String) = apply { // Type in our search term typeTextInView(androidx.appcompat.R.id.search_src_text, searchTerm) diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/TabsRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/TabsRobot.kt index bcfd171d299..9a852c683cb 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/TabsRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/TabsRobot.kt @@ -3,6 +3,9 @@ package org.wikipedia.robots.feature import org.wikipedia.R import org.wikipedia.base.BaseRobot import org.wikipedia.base.TestConfig +import org.wikipedia.base.TestThemeColorType +import org.wikipedia.base.TestWikipediaColors +import org.wikipedia.theme.Theme class TabsRobot : BaseRobot() { fun removeTab(position: Int) = apply { @@ -27,12 +30,13 @@ class TabsRobot : BaseRobot() { checkWithTextIsDisplayed(R.id.tabsCountText, count.toString()) } - fun assertColorOfTabsTitle(position: Int) = apply { + fun assertColorOfTabsTitle(position: Int, theme: Theme) = apply { + val color = TestWikipediaColors.getGetColor(theme, TestThemeColorType.PRIMARY) assertColorForChildItemInAList( listId = R.id.tabRecyclerView, childItemId = R.id.tabArticleTitle, - colorResOrAttr = R.attr.primary_color, - position = position + position = position, + colorResId = color ) } } diff --git a/app/src/androidTest/java/org/wikipedia/robots/screen/SavedScreenRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/screen/SavedScreenRobot.kt index 57a42dd3ce8..581d2028bb9 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/screen/SavedScreenRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/screen/SavedScreenRobot.kt @@ -1,11 +1,15 @@ package org.wikipedia.robots.screen import android.app.Activity +import android.content.Context +import android.util.Log import androidx.recyclerview.widget.RecyclerView import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions import androidx.test.espresso.assertion.ViewAssertions.doesNotExist +import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.contrib.RecyclerViewActions +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import org.hamcrest.Matchers.allOf @@ -64,6 +68,32 @@ class SavedScreenRobot : BaseRobot() { ).check(doesNotExist()) } + fun verifySavedArticle(title: String) = apply { + onView( + allOf( + withId(R.id.page_list_item_title), + withText(title) + ) + ).check(matches(isDisplayed())) + } + + fun verifyImageIsVisible(position: Int) = apply { + checkImageIsVisibleInsideARecyclerView( + listId = R.id.reading_list_recycler_view, + childItemId = R.id.page_list_item_image, + position = position + ) + delay(TestConfig.DELAY_SHORT) + } + + fun verifyPageIsOffline(context: Context) = apply { + try { + verifyMessageOfSnackbar(context.getString(R.string.page_offline_notice_last_date)) + } catch (e: Exception) { + Log.e("SavedScreenRobotError:", "Snackbar is not visible.") + } + } + fun clickFilterList() = apply { clickOnViewWithId(R.id.menu_search_lists) delay(TestConfig.DELAY_MEDIUM) diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt index 02f8ce86f10..97b32efbfe1 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt @@ -14,6 +14,7 @@ import org.wikipedia.robots.feature.ExploreFeedRobot import org.wikipedia.robots.feature.PageRobot import org.wikipedia.robots.feature.SearchRobot import org.wikipedia.robots.feature.TabsRobot +import org.wikipedia.theme.Theme @LargeTest @RunWith(AndroidJUnit4::class) @@ -46,7 +47,7 @@ class ArticleTabTest : BaseTest( .dismissContributionDialog() tabsRobot .launchTabsScreen() - .assertColorOfTabsTitle(0) + .assertColorOfTabsTitle(0, Theme.LIGHT) .createNewTabWithContentDescription(context.getString(R.string.menu_new_tab)) searchRobot @@ -55,7 +56,7 @@ class ArticleTabTest : BaseTest( .clickOnItemFromSearchList(0) tabsRobot .launchTabsScreen() - .assertColorOfTabsTitle(1) + .assertColorOfTabsTitle(1, Theme.LIGHT) .createNewTabWithContentDescription(context.getString(R.string.menu_new_tab)) searchRobot .tapSearchView() @@ -63,7 +64,7 @@ class ArticleTabTest : BaseTest( .clickOnItemFromSearchList(0) tabsRobot .launchTabsScreen() - .assertColorOfTabsTitle(2) + .assertColorOfTabsTitle(2, Theme.LIGHT) .verifyTabCount(3) .removeTab(0) .verifyTabCount(2) diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/MediaTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/MediaTest.kt index b4e7911afe8..8a2d8588b45 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/MediaTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/MediaTest.kt @@ -30,6 +30,8 @@ class MediaTest : BaseTest( .tapSearchView() .typeTextInView(TestConstants.SPECIAL_ARTICLE_VORTEX_SHEDDING) .clickOnItemFromSearchList(0) + pageRobot + .dismissTooltip(activity) mediaRobot .verifyLeadImageHasGif() pageRobot diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/OverflowMenuTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/OverflowMenuTest.kt index e26222a8cd4..d99b6c38905 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/OverflowMenuTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/OverflowMenuTest.kt @@ -13,6 +13,7 @@ import org.wikipedia.robots.feature.PageRobot import org.wikipedia.robots.feature.SearchRobot import org.wikipedia.robots.navigation.BottomNavRobot import org.wikipedia.robots.screen.HomeScreenRobot +import org.wikipedia.theme.Theme @LargeTest @RunWith(AndroidJUnit4::class) @@ -73,7 +74,7 @@ class OverflowMenuTest : BaseTest( pageRobot .clickOverFlowMenuToolbar() pageActionItemRobot - .assertViewOnMapIsGreyed() + .assertViewOnMapIsGreyed(Theme.LIGHT) pageActionItemRobot .clickNewTab() .pressBack() diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleOnlineOfflineTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleOnlineOfflineTest.kt new file mode 100644 index 00000000000..8e24ecfb4ba --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleOnlineOfflineTest.kt @@ -0,0 +1,70 @@ +package org.wikipedia.tests.articles + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import org.junit.Test +import org.junit.runner.RunWith +import org.wikipedia.TestConstants +import org.wikipedia.base.BaseTest +import org.wikipedia.main.MainActivity +import org.wikipedia.robots.DialogRobot +import org.wikipedia.robots.SystemRobot +import org.wikipedia.robots.feature.SearchRobot +import org.wikipedia.robots.navigation.BottomNavRobot +import org.wikipedia.robots.screen.SavedScreenRobot + +@LargeTest +@RunWith(AndroidJUnit4::class) +class SavedArticleOnlineOfflineTest : BaseTest( + activityClass = MainActivity::class.java +) { + private val searchRobot = SearchRobot() + private val systemRobot = SystemRobot() + private val bottomNavRobot = BottomNavRobot() + private val savedScreenRobot = SavedScreenRobot() + private val dialogRobot = DialogRobot() + + @Test + fun runTest() { + systemRobot + .clickOnSystemDialogWithText("Allow") + searchRobot + .tapSearchView() + .typeTextInView(TestConstants.SEARCH_TERM) + .longClickOnItemFromSearchList(0) + .clickSave() + .clickSearchInsideSearchFragment() + .typeTextInView(TestConstants.SEARCH_TERM2) + .longClickOnItemFromSearchList(0) + .clickSave() + .pressBack() + .pressBack() + bottomNavRobot + .navigateToSavedPage() + savedScreenRobot + .clickItemOnTheList(0) + dialogRobot + .dismissShareReadingListDialog() + savedScreenRobot + .verifySavedArticle("Apple") + .verifySavedArticle("Orange") + .clickItemOnReadingList(1) + .dismissTooltip(activity) + systemRobot + .turnOnAirplaneMode() + savedScreenRobot + .pressBack() + .pressBack() + bottomNavRobot + .navigateToExploreFeed() + .navigateToSavedPage() + savedScreenRobot + .clickItemOnTheList(0) + .verifyImageIsVisible(1) + .verifyImageIsVisible(2) + .clickItemOnReadingList(1) + .verifyPageIsOffline(context) + systemRobot + .turnOffAirplaneMode() + } +} diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt index 52e1f64d637..02bf9d2e030 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt @@ -11,7 +11,6 @@ import org.wikipedia.main.MainActivity import org.wikipedia.robots.DialogRobot import org.wikipedia.robots.SystemRobot import org.wikipedia.robots.feature.ExploreFeedRobot -import org.wikipedia.robots.feature.PageRobot import org.wikipedia.robots.feature.SearchRobot import org.wikipedia.robots.navigation.BottomNavRobot import org.wikipedia.robots.screen.SavedScreenRobot @@ -21,7 +20,6 @@ import org.wikipedia.robots.screen.SavedScreenRobot class SavedArticleTest : BaseTest( activityClass = MainActivity::class.java ) { - private val pageRobot = PageRobot(context) private val searchRobot = SearchRobot() private val systemRobot = SystemRobot() private val exploreFeedRobot = ExploreFeedRobot() @@ -44,9 +42,9 @@ class SavedArticleTest : BaseTest( .scrollToItem(title = FEATURED_ARTICLE) .longClickFeaturedArticleCardContainer() .clickSave() + setDeviceOrientation(isLandscape = true) bottomNavRobot .navigateToSavedPage() - setDeviceOrientation(isLandscape = true) savedScreenRobot .clickFilterList() searchRobot diff --git a/app/src/androidTest/java/org/wikipedia/testsuites/ArticlesTestSuite.kt b/app/src/androidTest/java/org/wikipedia/testsuites/ArticlesTestSuite.kt new file mode 100644 index 00000000000..a76f759625d --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/testsuites/ArticlesTestSuite.kt @@ -0,0 +1,33 @@ +package org.wikipedia.testsuites + +import OverflowMenuTest +import org.junit.runner.RunWith +import org.junit.runners.Suite +import org.junit.runners.Suite.SuiteClasses +import org.wikipedia.tests.articles.ArticlePageActionItemTest +import org.wikipedia.tests.articles.ArticleSectionsTest +import org.wikipedia.tests.articles.ArticleTabTest +import org.wikipedia.tests.articles.EditIconTest +import org.wikipedia.tests.articles.LeadNonLeadImageAndPreviewLinkTest +import org.wikipedia.tests.articles.MediaTest +import org.wikipedia.tests.articles.SavedArticleOnlineOfflineTest +import org.wikipedia.tests.articles.SavedArticleTest +import org.wikipedia.tests.articles.SpecialArticleTest +import org.wikipedia.tests.articles.TableOfContentsTest + +@RunWith(Suite::class) +@SuiteClasses( + ArticlePageActionItemTest::class, + ArticleSectionsTest::class, + ArticleTabTest::class, + EditIconTest::class, + LeadNonLeadImageAndPreviewLinkTest::class, + MediaTest::class, + OverflowMenuTest::class, + SavedArticleTest::class, + SpecialArticleTest::class, + TableOfContentsTest::class, + SavedArticleTest::class, + SavedArticleOnlineOfflineTest::class +) +class ArticlesTestSuite From c45ae2950cfa8352e0dab675051a2b97124f22a1 Mon Sep 17 00:00:00 2001 From: williamrai Date: Tue, 17 Dec 2024 17:10:54 -0500 Subject: [PATCH 15/22] - fixes test functions --- .../java/org/wikipedia/base/BaseRobot.kt | 1 - .../java/org/wikipedia/robots/DialogRobot.kt | 9 +++++++++ .../robots/feature/ExploreFeedRobot.kt | 8 ++++++-- .../org/wikipedia/robots/feature/LoginRobot.kt | 13 +++++++++---- .../org/wikipedia/robots/feature/MediaRobot.kt | 6 +++--- .../wikipedia/robots/feature/SearchRobot.kt | 13 ++++++++++--- .../wikipedia/robots/feature/SettingsRobot.kt | 10 ++++++++++ .../robots/navigation/BottomNavRobot.kt | 9 +++++++-- .../articles/ArticlePageActionItemTest.kt | 1 + .../org/wikipedia/tests/articles/MediaTest.kt | 4 +--- .../tests/articles/SavedArticleTest.kt | 18 +++++++++++++++--- .../tests/articles/TableOfContentsTest.kt | 4 ++++ 12 files changed, 75 insertions(+), 21 deletions(-) diff --git a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt index 65e5f81eff5..b1295913210 100644 --- a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt @@ -146,7 +146,6 @@ abstract class BaseRobot { ).perform(doubleClick()) } - protected fun scrollToView(@IdRes viewId: Int) { onView(withId(viewId)).perform(scrollTo()) } diff --git a/app/src/androidTest/java/org/wikipedia/robots/DialogRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/DialogRobot.kt index df61a8d01fb..b4d951b983a 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/DialogRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/DialogRobot.kt @@ -28,4 +28,13 @@ class DialogRobot : BaseRobot() { Log.d("DialogRobot: ", "No share reading list dialog shown.") } } + + fun clickLogOutUser() = apply { + try { + clickOnViewWithText(text = "Log out") + } catch (e: Exception) { + Log.d("DialogRobot: ", "Cannot click Log out.") + goBack() + } + } } diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt index 4ac6e373591..e93b5e5612e 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/ExploreFeedRobot.kt @@ -217,8 +217,12 @@ class ExploreFeedRobot : BaseRobot() { } fun clickSave() = apply { - clickOnViewWithText("Save") - delay(TestConfig.DELAY_SHORT) + try { + clickOnViewWithText("Save") + delay(TestConfig.DELAY_SHORT) + } catch (e: Exception) { + Log.e("ExploreFeedRobotError:", "Save text is not found.") + } } private fun scrollToCardViewWithTitle( diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/LoginRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/LoginRobot.kt index 5b6f03c504e..e90e1b05c91 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/LoginRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/LoginRobot.kt @@ -1,5 +1,6 @@ package org.wikipedia.robots.feature +import android.util.Log import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions.closeSoftKeyboard import androidx.test.espresso.action.ViewActions.replaceText @@ -16,10 +17,14 @@ import org.wikipedia.base.TestConfig class LoginRobot : BaseRobot() { fun logInUser() = apply { - clickLoginButton() - setLoginUserNameFromBuildConfig() - setPasswordFromBuildConfig() - loginUser() + try { + clickLoginButton() + setLoginUserNameFromBuildConfig() + setPasswordFromBuildConfig() + loginUser() + } catch (e: Exception) { + Log.e("LoginRobotError:", "User already logged in.") + } } private fun clickLoginButton() = apply { diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/MediaRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/MediaRobot.kt index 7e8c03e2b4f..59e648664d9 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/MediaRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/MediaRobot.kt @@ -31,9 +31,9 @@ class MediaRobot : BaseRobot() { fun pinchZoomAction(context: Context, uiDevice: UiDevice) = apply { val imageView = uiDevice.findObject(UiSelector().resourceId("${context.packageName}:id/imageView")) - imageView.pinchIn(75, 20) - imageView.pinchOut(75, 20) - imageView.dragTo(500, 700, 20) + imageView.pinchIn(60, 20) + imageView.pinchOut(60, 20) + imageView.dragTo(400, 600, 20) } fun doubleTapToZoomOut() = apply { diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt index 2f141272344..c2b0aa15a07 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt @@ -1,5 +1,6 @@ package org.wikipedia.robots.feature +import android.util.Log import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.assertion.ViewAssertions.matches @@ -87,9 +88,15 @@ class SearchRobot : BaseRobot() { checkRTLDirectionOfRecyclerViewItem(R.id.search_results_list) } - fun clickSave() = apply { - clickOnViewWithText("Save") - delay(TestConfig.DELAY_SHORT) + fun clickSave(action: ((isSaved: Boolean) -> Unit)? = null) = apply { + try { + clickOnViewWithText("Save") + delay(TestConfig.DELAY_SHORT) + action?.invoke(true) + } catch (e: Exception) { + Log.e("SearchRobotError:", "Already saved.") + action?.invoke(false) + } } fun pressBack() = apply { diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/SettingsRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/SettingsRobot.kt index a1af4477c3a..5ac1d492b6c 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/SettingsRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/SettingsRobot.kt @@ -107,6 +107,16 @@ class SettingsRobot : BaseRobot() { delay(TestConfig.DELAY_MEDIUM) } + fun clickLogOut(context: Context) = apply { + try { + scrollToSettingsPreferenceItem(R.string.preference_title_logout, scrollTo()) + clickOnViewWithText(context.getString(R.string.preference_title_logout)) + delay(TestConfig.DELAY_MEDIUM) + } catch (e: Exception) { + Log.e("SettingsRobotError:", "User is not logged in.") + } + } + fun toggleShowLinkPreviews() = apply { scrollToSettingsPreferenceItem(R.string.preference_title_show_link_previews, click()) delay(TestConfig.DELAY_MEDIUM) diff --git a/app/src/androidTest/java/org/wikipedia/robots/navigation/BottomNavRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/navigation/BottomNavRobot.kt index f2923605e7f..6b36969f4a6 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/navigation/BottomNavRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/navigation/BottomNavRobot.kt @@ -1,5 +1,6 @@ package org.wikipedia.robots.navigation +import android.util.Log import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.matcher.ViewMatchers.isDisplayed @@ -68,8 +69,12 @@ class BottomNavRobot : BaseRobot() { } fun clickLoginMenuItem() = apply { - clickOnViewWithId(R.id.main_drawer_login_button) - delay(TestConfig.DELAY_MEDIUM) + try { + clickOnViewWithId(R.id.main_drawer_login_button) + delay(TestConfig.DELAY_MEDIUM) + } catch (e: Exception) { + Log.e("BottomNavRobotError:", "User logged in.") + } } fun gotoWatchList() = apply { diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt index c90f876b6de..2cc136f91b4 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt @@ -34,6 +34,7 @@ class ArticlePageActionItemTest : BaseTest( @Test fun runTest() { pageRobot + .dismissTooltip(activity) .saveArticleToReadingList() .confirmArticleSaved("Saved") .openLanguageSelector() diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/MediaTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/MediaTest.kt index 8a2d8588b45..54c61e90a90 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/MediaTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/MediaTest.kt @@ -37,9 +37,6 @@ class MediaTest : BaseTest( pageRobot .clickLeadImage() .swipePagerLeft() - mediaRobot - .pinchZoomAction(context, device) - pageRobot .swipePagerLeft() mediaRobot .doubleTapToZoomOut() @@ -52,6 +49,7 @@ class MediaTest : BaseTest( .clickShareButton() .clickCC() .verifyCCisClicked() + .pinchZoomAction(context, device) .tapHamburger(context) .goToImagePage(context) .verifyImagePageIsVisible() diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt index 02bf9d2e030..8c0e75c43a8 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt @@ -12,6 +12,7 @@ import org.wikipedia.robots.DialogRobot import org.wikipedia.robots.SystemRobot import org.wikipedia.robots.feature.ExploreFeedRobot import org.wikipedia.robots.feature.SearchRobot +import org.wikipedia.robots.feature.SettingsRobot import org.wikipedia.robots.navigation.BottomNavRobot import org.wikipedia.robots.screen.SavedScreenRobot @@ -26,18 +27,29 @@ class SavedArticleTest : BaseTest( private val bottomNavRobot = BottomNavRobot() private val savedScreenRobot = SavedScreenRobot() private val dialogRobot = DialogRobot() + private val settingsRobot = SettingsRobot() @Test fun runTest() { + setDeviceOrientation(isLandscape = false) systemRobot .clickOnSystemDialogWithText("Allow") searchRobot .tapSearchView() .typeTextInView(TestConstants.SEARCH_TERM) .longClickOnItemFromSearchList(0) - .clickSave() - .pressBack() - .pressBack() + .clickSave(action = { isSaved -> + if (isSaved) { + searchRobot + .pressBack() + .pressBack() + } else { + searchRobot + .pressBack() + .pressBack() + .pressBack() + } + }) exploreFeedRobot .scrollToItem(title = FEATURED_ARTICLE) .longClickFeaturedArticleCardContainer() diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/TableOfContentsTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/TableOfContentsTest.kt index 1746966d052..c38641a5045 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/TableOfContentsTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/TableOfContentsTest.kt @@ -12,6 +12,7 @@ import org.wikipedia.page.PageActivity import org.wikipedia.page.PageActivity.Companion.ACTION_LOAD_IN_CURRENT_TAB import org.wikipedia.page.PageActivity.Companion.EXTRA_HISTORYENTRY import org.wikipedia.robots.DialogRobot +import org.wikipedia.robots.SystemRobot import org.wikipedia.robots.feature.PageRobot import org.wikipedia.robots.screen.HomeScreenRobot @@ -30,9 +31,12 @@ class TableOfContentsTest : BaseTest( private val pageRobot = PageRobot(context) private val homeScreenRobot = HomeScreenRobot() private val dialogRobot = DialogRobot() + private val systemRobot = SystemRobot() @Test fun runTest() { + systemRobot + .clickOnSystemDialogWithText("Allow") dialogRobot .dismissBigEnglishDialog() setDeviceOrientation(isLandscape = false) From 4798d0db15d2786e17028462d587e50917c88cf6 Mon Sep 17 00:00:00 2001 From: williamrai Date: Wed, 18 Dec 2024 11:40:44 -0500 Subject: [PATCH 16/22] - adds DrawableMatcher that asserts the id of the resources used for an imageview drawable - adds a new robot (LicenseRobot) - fixes test cases --- .../org/wikipedia/base/DrawableMatcher.kt | 34 ++++++++++++++++++ .../wikipedia/robots/feature/LicenseRobot.kt | 35 +++++++++++++++++++ .../articles/SavedArticleOnlineOfflineTest.kt | 3 ++ .../tests/articles/SpecialArticleTest.kt | 29 +++++++++++++-- 4 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 app/src/androidTest/java/org/wikipedia/base/DrawableMatcher.kt create mode 100644 app/src/androidTest/java/org/wikipedia/robots/feature/LicenseRobot.kt diff --git a/app/src/androidTest/java/org/wikipedia/base/DrawableMatcher.kt b/app/src/androidTest/java/org/wikipedia/base/DrawableMatcher.kt new file mode 100644 index 00000000000..aca948f1154 --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/base/DrawableMatcher.kt @@ -0,0 +1,34 @@ +package org.wikipedia.base + +import android.content.res.Resources +import android.view.View +import android.widget.ImageView +import androidx.annotation.DrawableRes +import androidx.test.espresso.matcher.BoundedMatcher +import org.hamcrest.Description + +object DrawableMatcher { + fun withDrawableId(@DrawableRes expectedId: Int) = + object : BoundedMatcher(ImageView::class.java) { + override fun describeTo(description: Description) { + description.appendText("with drawable from resource id: $expectedId") + } + + override fun matchesSafely(imageView: ImageView): Boolean { + if (expectedId < 0) return false + + val context = imageView.context + val resources = imageView.resources + + try { + val expectedName = resources.getResourceEntryName(expectedId) + val expectedType = resources.getResourceTypeName(expectedId) + + val foundId = resources.getIdentifier(expectedName, expectedType, context.packageName) + return foundId == expectedId + } catch (e: Resources.NotFoundException) { + return false + } + } + } +} diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/LicenseRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/LicenseRobot.kt new file mode 100644 index 00000000000..77fba9d674d --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/LicenseRobot.kt @@ -0,0 +1,35 @@ +package org.wikipedia.robots.feature + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.withId +import org.wikipedia.R +import org.wikipedia.base.BaseRobot +import org.wikipedia.base.DrawableMatcher +import org.wikipedia.base.TestConfig + +class LicenseRobot : BaseRobot() { + fun verifyImageIsCopyrighted() = apply { + onView(withId(R.id.license_icon)) + .check(matches(DrawableMatcher.withDrawableId(R.drawable.ic_license_cite))) + delay(TestConfig.DELAY_SHORT) + } + + fun verifyImageHasCCLicense() = apply { + onView(withId(R.id.license_icon)) + .check(matches(DrawableMatcher.withDrawableId(R.drawable.ic_license_cc))) + delay(TestConfig.DELAY_SHORT) + } + + fun verifyImageHasPdLicense() = apply { + onView(withId(R.id.license_icon)) + .check(matches(DrawableMatcher.withDrawableId(R.drawable.ic_license_pd))) + delay(TestConfig.DELAY_SHORT) + } + + fun verifyImageHasSaLicense() = apply { + onView(withId(R.id.license_icon)) + .check(matches(DrawableMatcher.withDrawableId(R.drawable.ic_license_by))) + delay(TestConfig.DELAY_SHORT) + } +} diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleOnlineOfflineTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleOnlineOfflineTest.kt index 8e24ecfb4ba..eebe99e978c 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleOnlineOfflineTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleOnlineOfflineTest.kt @@ -63,6 +63,9 @@ class SavedArticleOnlineOfflineTest : BaseTest( .verifyImageIsVisible(1) .verifyImageIsVisible(2) .clickItemOnReadingList(1) + dialogRobot + .dismissBigEnglishDialog() + savedScreenRobot .verifyPageIsOffline(context) systemRobot .turnOffAirplaneMode() diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/SpecialArticleTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/SpecialArticleTest.kt index f4b81ac6560..442cf29f7e8 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/SpecialArticleTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/SpecialArticleTest.kt @@ -8,22 +8,21 @@ import org.wikipedia.TestConstants import org.wikipedia.base.BaseTest import org.wikipedia.main.MainActivity import org.wikipedia.robots.SystemRobot +import org.wikipedia.robots.feature.LicenseRobot import org.wikipedia.robots.feature.MediaRobot import org.wikipedia.robots.feature.PageRobot import org.wikipedia.robots.feature.SearchRobot -import org.wikipedia.robots.screen.HomeScreenRobot @LargeTest @RunWith(AndroidJUnit4::class) class SpecialArticleTest : BaseTest( activityClass = MainActivity::class.java ) { - - private val homeScreenRobot = HomeScreenRobot() private val searchRobot = SearchRobot() private val systemRobot = SystemRobot() private val mediaRobot = MediaRobot() private val pageRobot = PageRobot(context) + private val licenseRobot = LicenseRobot() @Test fun runTest() { @@ -41,9 +40,21 @@ class SpecialArticleTest : BaseTest( .clickOnItemFromSearchList(0) pageRobot .clickLeadImage() + licenseRobot + .verifyImageIsCopyrighted() + pageRobot .swipePagerLeft() + licenseRobot + .verifyImageHasCCLicense() + pageRobot .swipePagerLeft() + licenseRobot + .verifyImageHasCCLicense() + pageRobot .swipePagerLeft() + licenseRobot + .verifyImageHasCCLicense() + pageRobot .pressBack() searchRobot .clickSearchFromPageView() @@ -51,9 +62,21 @@ class SpecialArticleTest : BaseTest( .clickOnItemFromSearchList(0) pageRobot .clickLeadImage() + licenseRobot + .verifyImageHasPdLicense() + pageRobot .swipePagerLeft() + licenseRobot + .verifyImageHasPdLicense() + pageRobot .swipePagerLeft() + licenseRobot + .verifyImageHasCCLicense() + pageRobot .swipePagerLeft() + licenseRobot + .verifyImageHasPdLicense() + pageRobot .pressBack() searchRobot .clickSearchFromPageView() From f012d91f3b8bb678614c8648b684c5ab98599ab6 Mon Sep 17 00:00:00 2001 From: williamrai Date: Wed, 18 Dec 2024 12:08:50 -0500 Subject: [PATCH 17/22] - adds test for find in article --- .../java/org/wikipedia/robots/feature/PageRobot.kt | 12 ++++++++++++ .../tests/articles/ArticlePageActionItemTest.kt | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt index df92229cfe1..70b129ce4d3 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt @@ -7,10 +7,13 @@ import android.content.Intent import android.net.Uri import android.util.Log import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.intent.Intents.intended import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction import androidx.test.espresso.intent.matcher.IntentMatchers.hasData +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.espresso.web.sugar.Web.onWebView import androidx.test.espresso.web.webdriver.DriverAtoms.findElement import androidx.test.espresso.web.webdriver.DriverAtoms.webClick @@ -249,6 +252,7 @@ class PageRobot(private val context: Context) : BaseRobot() { fun saveArticleToReadingList() = apply { clickOnViewWithId(R.id.page_save) + delay(TestConfig.DELAY_SHORT) } fun confirmArticleSaved(text: String) = apply { @@ -263,6 +267,14 @@ class PageRobot(private val context: Context) : BaseRobot() { clickOnDisplayedViewWithIdAnContentDescription(R.id.page_find_in_article, context.getString(R.string.menu_page_find_in_page)) } + fun verifyFindInArticleCount(count: String) = apply { + onView(allOf( + withId(R.id.find_in_page_match), + withText("1/$count") + )).check(matches(isDisplayed())) + delay(TestConfig.DELAY_SHORT) + } + fun openThemeSelector() = apply { clickOnDisplayedViewWithIdAnContentDescription(R.id.page_theme, context.getString(R.string.article_menu_bar_theme_button)) } diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt index 2cc136f91b4..d8e284f0c5a 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticlePageActionItemTest.kt @@ -34,7 +34,6 @@ class ArticlePageActionItemTest : BaseTest( @Test fun runTest() { pageRobot - .dismissTooltip(activity) .saveArticleToReadingList() .confirmArticleSaved("Saved") .openLanguageSelector() @@ -43,6 +42,8 @@ class ArticlePageActionItemTest : BaseTest( .openFindInArticle() searchRobot .typeTextInView(FIND_IN_ARTICLE_TEXT) + pageRobot + .verifyFindInArticleCount("23") .pressBack() pageRobot .openTableOfContents() From 04388dab2e9c774ab7e1ffcbaeab21fa3d1344e1 Mon Sep 17 00:00:00 2001 From: williamrai Date: Wed, 18 Dec 2024 14:20:48 -0500 Subject: [PATCH 18/22] - adds ExecuteJavascriptAction whose aim is to just execute javascript function as ViewAction for espresso - adds a function for scrolling to non-lead image which is an image in the web view --- .../java/org/wikipedia/TestConstants.kt | 1 + .../java/org/wikipedia/base/BaseRobot.kt | 15 ++++++ .../wikipedia/base/ExecuteJavascriptAction.kt | 51 +++++++++++++++++++ .../org/wikipedia/robots/feature/PageRobot.kt | 7 +++ .../LeadNonLeadImageAndPreviewLinkTest.kt | 4 ++ 5 files changed, 78 insertions(+) create mode 100644 app/src/androidTest/java/org/wikipedia/base/ExecuteJavascriptAction.kt diff --git a/app/src/androidTest/java/org/wikipedia/TestConstants.kt b/app/src/androidTest/java/org/wikipedia/TestConstants.kt index 271cb199429..d628c2b07d9 100644 --- a/app/src/androidTest/java/org/wikipedia/TestConstants.kt +++ b/app/src/androidTest/java/org/wikipedia/TestConstants.kt @@ -12,6 +12,7 @@ object TestConstants { const val SUGGESTED_EDITS = "Suggested edits" const val SEARCH_TERM = "apple" const val SEARCH_TERM2 = "orange" + const val SEARCH_HOPF_FIBRATION = "Hopf fibration" const val SPECIAL_ARTICLE_VORTEX_SHEDDING = "Vortex shedding" const val SPECIAL_ARTICLE_AVATAR_2009 = "Avatar 2009" const val SPECIAL_ARTICLE_BILL_CLINTON = "Bill Clinton" diff --git a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt index b1295913210..c47173bd3be 100644 --- a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt @@ -578,6 +578,21 @@ abstract class BaseRobot { })) } + protected fun scrollToImageInWebView(imageIndex: Int): ViewAction { + val scrollScript = """ + (function findContentImages() { + const contentImages = Array.from(document.querySelectorAll('img')) + .filter(img => img.complete && img.naturalWidth > 100 && img.naturalHeight > 100) + if (contentImages.length > $imageIndex) { + contentImages[$imageIndex].scrollIntoView({ behavior: 'smooth', block: 'center' }) + return 'success' + } + return 'image not found' + })() + """.trimIndent() + return ExecuteJavascriptAction(scrollScript) + } + private fun clickChildViewWithId(@IdRes id: Int) = object : ViewAction { override fun getConstraints() = null diff --git a/app/src/androidTest/java/org/wikipedia/base/ExecuteJavascriptAction.kt b/app/src/androidTest/java/org/wikipedia/base/ExecuteJavascriptAction.kt new file mode 100644 index 00000000000..1aff6735ede --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/base/ExecuteJavascriptAction.kt @@ -0,0 +1,51 @@ +package org.wikipedia.base + +import android.view.View +import android.webkit.ValueCallback +import android.webkit.WebView +import androidx.test.espresso.PerformException +import androidx.test.espresso.UiController +import androidx.test.espresso.ViewAction +import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom +import androidx.test.espresso.util.HumanReadables +import org.hamcrest.Matcher +import java.util.concurrent.atomic.AtomicBoolean + +class ExecuteJavascriptAction(private val script: String) : ViewAction, ValueCallback { + private val evaluateFinished = AtomicBoolean(false) + + override fun getConstraints(): Matcher { + return isAssignableFrom(WebView::class.java) + } + + override fun getDescription(): String { + return "Execute Javascript Action" + } + + override fun perform(uiController: UiController, view: View) { + uiController.loopMainThreadUntilIdle() + + val webView = view as WebView + val exception = PerformException.Builder() + .withActionDescription(this.description) + .withViewDescription(HumanReadables.describe(view)) + + webView.evaluateJavascript(script, this) + + val maxTime = System.currentTimeMillis() + 5000 + while (!evaluateFinished.get()) { + if (System.currentTimeMillis() > maxTime) { + throw exception + .withCause(RuntimeException("Evaluating Javascript timed out.")) + .build() + } + uiController.loopMainThreadForAtLeast(50) + } + + uiController.loopMainThreadForAtLeast(500) + } + + override fun onReceiveValue(value: String?) { + evaluateFinished.set(true) + } +} diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt index 70b129ce4d3..cbd77c15ecb 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt @@ -7,6 +7,7 @@ import android.content.Intent import android.net.Uri import android.util.Log import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.intent.Intents.intended import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction @@ -356,4 +357,10 @@ class PageRobot(private val context: Context) : BaseRobot() { clickOnViewWithId(viewId = R.id.page_toolbar_button_show_overflow_menu) delay(TestConfig.DELAY_SHORT) } + + fun scrollToNonLeadImage() = apply { + onView(withId(R.id.page_web_view)) + .perform(scrollToImageInWebView(1)) + .perform(click()) + } } diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt index 29d7c17225b..1580cb982ca 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt @@ -31,9 +31,13 @@ class LeadNonLeadImageAndPreviewLinkTest : BaseTest( @Test fun runTest() { pageRobot + .dismissTooltip(activity) .clickLeadImage() .swipePagerLeft() .pressBack() + .scrollToNonLeadImage() + .swipePagerLeft() + .pressBack() .clickLink("3-sphere") .verifyPreviewDialogAppears() } From 2ac2333e1a053e6884ca33e91e050715fcc3f7d3 Mon Sep 17 00:00:00 2001 From: williamrai Date: Wed, 18 Dec 2024 17:49:03 -0500 Subject: [PATCH 19/22] - fixes issues with dialogRobot - test cases fix for article test --- .../java/org/wikipedia/base/BaseRobot.kt | 24 ++++++++++------ .../java/org/wikipedia/robots/DialogRobot.kt | 28 ++----------------- .../LeadNonLeadImageAndPreviewLinkTest.kt | 1 - .../articles/SavedArticleOnlineOfflineTest.kt | 17 ++++++++--- .../tests/articles/SavedArticleTest.kt | 3 +- .../wikipedia/testsuites/ArticlesTestSuite.kt | 2 +- 6 files changed, 34 insertions(+), 41 deletions(-) diff --git a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt index c47173bd3be..1f278a7e61d 100644 --- a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt @@ -51,6 +51,10 @@ import androidx.test.espresso.web.webdriver.DriverAtoms import androidx.test.espresso.web.webdriver.DriverAtoms.findElement import androidx.test.espresso.web.webdriver.DriverAtoms.webClick import androidx.test.espresso.web.webdriver.Locator +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.uiautomator.By +import androidx.test.uiautomator.UiDevice +import androidx.test.uiautomator.Until import org.hamcrest.Description import org.hamcrest.Matcher import org.hamcrest.Matchers @@ -264,18 +268,22 @@ abstract class BaseRobot { delay(TestConfig.DELAY_LARGE) } - protected fun performIfDialogShown( + protected fun clickIfDialogShown( dialogText: String, - action: () -> Unit + errorString: String ) { - try { + val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) + val dialogExists = device.wait( + Until.findObject(By.text(dialogText)), + 1000 + ) != null + + if (dialogExists) { onView(withText(dialogText)) .inRoot(isDialog()) - .check(matches(isDisplayed())) - action() - } catch (e: Exception) { - // Dialog not shown or text not found - Log.e("error", "") + .perform(click()) + } else { + Log.d("BaseRobot", "error: $errorString") } } diff --git a/app/src/androidTest/java/org/wikipedia/robots/DialogRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/DialogRobot.kt index b4d951b983a..6ff9c388768 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/DialogRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/DialogRobot.kt @@ -1,40 +1,18 @@ package org.wikipedia.robots -import android.util.Log import org.wikipedia.base.BaseRobot class DialogRobot : BaseRobot() { fun dismissContributionDialog() = apply { - try { - clickOnViewWithText(text = "No, thanks") - } catch (e: Exception) { - Log.d("DialogRobot: ", "No Contribution dialog shown.") - } + clickIfDialogShown("No thanks", errorString = "No Contribution dialog shown.") } fun dismissBigEnglishDialog() = apply { - try { - clickOnViewWithText(text = "Maybe later") - } catch (e: Exception) { - Log.d("DialogRobot: ", "No Big English dialog shown.") - } - } - - fun dismissShareReadingListDialog() = apply { - try { - clickOnViewWithText(text = "Got it") - } catch (e: Exception) { - Log.d("DialogRobot: ", "No share reading list dialog shown.") - } + clickIfDialogShown("Maybe later", errorString = "No Big English dialog shown.") } fun clickLogOutUser() = apply { - try { - clickOnViewWithText(text = "Log out") - } catch (e: Exception) { - Log.d("DialogRobot: ", "Cannot click Log out.") - goBack() - } + clickIfDialogShown("Log out", errorString = "Cannot click Log out.") } } diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt index 1580cb982ca..cc3c89afd37 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt @@ -31,7 +31,6 @@ class LeadNonLeadImageAndPreviewLinkTest : BaseTest( @Test fun runTest() { pageRobot - .dismissTooltip(activity) .clickLeadImage() .swipePagerLeft() .pressBack() diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleOnlineOfflineTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleOnlineOfflineTest.kt index eebe99e978c..9a8ff8d98dd 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleOnlineOfflineTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleOnlineOfflineTest.kt @@ -32,19 +32,28 @@ class SavedArticleOnlineOfflineTest : BaseTest( .tapSearchView() .typeTextInView(TestConstants.SEARCH_TERM) .longClickOnItemFromSearchList(0) - .clickSave() + .clickSave(action = { isSaved -> + if (!isSaved) { + searchRobot + .pressBack() + } + }) .clickSearchInsideSearchFragment() .typeTextInView(TestConstants.SEARCH_TERM2) .longClickOnItemFromSearchList(0) - .clickSave() + .clickSave(action = { isSaved -> + if (!isSaved) { + searchRobot + .pressBack() + } + }) .pressBack() .pressBack() bottomNavRobot .navigateToSavedPage() savedScreenRobot .clickItemOnTheList(0) - dialogRobot - .dismissShareReadingListDialog() + .dismissTooltip(activity) savedScreenRobot .verifySavedArticle("Apple") .verifySavedArticle("Orange") diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt index 8c0e75c43a8..ea54545d709 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt @@ -66,8 +66,7 @@ class SavedArticleTest : BaseTest( setDeviceOrientation(isLandscape = false) savedScreenRobot .clickItemOnTheList(0) - dialogRobot - .dismissShareReadingListDialog() + .dismissTooltip(activity) savedScreenRobot .clickFilterList() searchRobot diff --git a/app/src/androidTest/java/org/wikipedia/testsuites/ArticlesTestSuite.kt b/app/src/androidTest/java/org/wikipedia/testsuites/ArticlesTestSuite.kt index a76f759625d..8c6a00f7ea4 100644 --- a/app/src/androidTest/java/org/wikipedia/testsuites/ArticlesTestSuite.kt +++ b/app/src/androidTest/java/org/wikipedia/testsuites/ArticlesTestSuite.kt @@ -20,8 +20,8 @@ import org.wikipedia.tests.articles.TableOfContentsTest ArticlePageActionItemTest::class, ArticleSectionsTest::class, ArticleTabTest::class, - EditIconTest::class, LeadNonLeadImageAndPreviewLinkTest::class, + EditIconTest::class, MediaTest::class, OverflowMenuTest::class, SavedArticleTest::class, From a7302672f129e462ba0e0227c3845f373baff44d Mon Sep 17 00:00:00 2001 From: williamrai Date: Thu, 19 Dec 2024 13:09:11 -0500 Subject: [PATCH 20/22] - fixes gallery offline crash issue - disable tooltips --- .../java/org/wikipedia/base/BaseRobot.kt | 39 ++++++++++++------- .../java/org/wikipedia/base/BaseTest.kt | 6 ++- .../org/wikipedia/robots/feature/PageRobot.kt | 9 +++++ .../tests/articles/ArticleSectionsTest.kt | 2 - .../tests/articles/ArticleTabTest.kt | 1 - .../wikipedia/tests/articles/EditIconTest.kt | 23 +++++------ .../LeadNonLeadImageAndPreviewLinkTest.kt | 11 ++++-- .../org/wikipedia/tests/articles/MediaTest.kt | 2 - .../tests/articles/OverflowMenuTest.kt | 2 - .../articles/SavedArticleOnlineOfflineTest.kt | 2 - .../tests/articles/SavedArticleTest.kt | 5 --- .../tests/articles/TableOfContentsTest.kt | 2 - .../tests/settings/CollapseTablesTest.kt | 1 - .../tests/settings/DownloadReadingListTest.kt | 3 -- .../tests/settings/LinkPreviewTest.kt | 1 - .../tests/settings/ReadingFocusModeTest.kt | 1 - 16 files changed, 59 insertions(+), 51 deletions(-) diff --git a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt index 1f278a7e61d..2c854d7445f 100644 --- a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt @@ -17,6 +17,7 @@ import androidx.recyclerview.widget.RecyclerView import androidx.test.espresso.Espresso.onData import androidx.test.espresso.Espresso.onView import androidx.test.espresso.Espresso.pressBack +import androidx.test.espresso.NoMatchingViewException import androidx.test.espresso.UiController import androidx.test.espresso.ViewAction import androidx.test.espresso.ViewAssertion @@ -51,10 +52,6 @@ import androidx.test.espresso.web.webdriver.DriverAtoms import androidx.test.espresso.web.webdriver.DriverAtoms.findElement import androidx.test.espresso.web.webdriver.DriverAtoms.webClick import androidx.test.espresso.web.webdriver.Locator -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.uiautomator.By -import androidx.test.uiautomator.UiDevice -import androidx.test.uiautomator.Until import org.hamcrest.Description import org.hamcrest.Matcher import org.hamcrest.Matchers @@ -272,18 +269,15 @@ abstract class BaseRobot { dialogText: String, errorString: String ) { - val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - val dialogExists = device.wait( - Until.findObject(By.text(dialogText)), - 1000 - ) != null - - if (dialogExists) { + try { onView(withText(dialogText)) + .perform(waitForAsyncLoading()) .inRoot(isDialog()) .perform(click()) - } else { - Log.d("BaseRobot", "error: $errorString") + } catch (e: NoMatchingViewException) { + Log.e("BaseRobot", "$errorString") + } catch (e: Exception) { + Log.e("BaseRobot", "Unexpected Error: ${e.message}") } } @@ -601,6 +595,25 @@ abstract class BaseRobot { return ExecuteJavascriptAction(scrollScript) } + protected fun performActionIfSnackbarVisible( + text: String, + action: () -> Unit + ) = apply { + try { + onView( + allOf( + withId(com.google.android.material.R.id.snackbar_text), + withText(text) + ) + ).check(matches(isDisplayed())) + action.invoke() + } catch (e: NoMatchingViewException) { + Log.e("BaseRobot", "No snackbar visible, skipping action") + } catch (e: Exception) { + Log.e("BaseRobot", "Unexpected error: ${e.message}") + } + } + private fun clickChildViewWithId(@IdRes id: Int) = object : ViewAction { override fun getConstraints() = null diff --git a/app/src/androidTest/java/org/wikipedia/base/BaseTest.kt b/app/src/androidTest/java/org/wikipedia/base/BaseTest.kt index cb7af43194a..0df4494f6d4 100644 --- a/app/src/androidTest/java/org/wikipedia/base/BaseTest.kt +++ b/app/src/androidTest/java/org/wikipedia/base/BaseTest.kt @@ -28,7 +28,9 @@ object TestConfig { data class DataInjector( val isInitialOnboardingEnabled: Boolean = false, val overrideEditsContribution: Int? = null, - val intentBuilder: (Intent.() -> Unit)? = null + val intentBuilder: (Intent.() -> Unit)? = null, + val showOneTimeCustomizeToolbarTooltip: Boolean = false, + val readingListShareTooltipShown: Boolean = true ) abstract class BaseTest( @@ -49,6 +51,8 @@ abstract class BaseTest( val intent = Intent(context, activityClass) activityScenarioRule = ActivityScenarioRule(intent) Prefs.isInitialOnboardingEnabled = dataInjector.isInitialOnboardingEnabled + Prefs.showOneTimeCustomizeToolbarTooltip = dataInjector.showOneTimeCustomizeToolbarTooltip + Prefs.readingListShareTooltipShown = dataInjector.readingListShareTooltipShown dataInjector.overrideEditsContribution?.let { Prefs.overrideSuggestedEditContribution = it } diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt index cbd77c15ecb..caca090d9b2 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/PageRobot.kt @@ -64,6 +64,7 @@ class PageRobot(private val context: Context) : BaseRobot() { } fun clickLeadImage() = apply { + delay(TestConfig.DELAY_SHORT) clickOnDisplayedView(R.id.view_page_header_image) delay(TestConfig.DELAY_MEDIUM) } @@ -252,6 +253,7 @@ class PageRobot(private val context: Context) : BaseRobot() { } fun saveArticleToReadingList() = apply { + delay(TestConfig.DELAY_SHORT) clickOnViewWithId(R.id.page_save) delay(TestConfig.DELAY_SHORT) } @@ -363,4 +365,11 @@ class PageRobot(private val context: Context) : BaseRobot() { .perform(scrollToImageInWebView(1)) .perform(click()) } + + fun isGalleryActivityOffline(context: Context, action: () -> Unit) = apply { + performActionIfSnackbarVisible( + text = context.getString(R.string.gallery_not_available_offline_snackbar), + action = action + ) + } } diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleSectionsTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleSectionsTest.kt index 764241b318e..1e6afb195ea 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleSectionsTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleSectionsTest.kt @@ -25,8 +25,6 @@ class ArticleSectionsTest : BaseTest( .tapSearchView() .typeTextInView(SEARCH_TERM) .clickOnItemFromSearchList(0) - pageRobot - .dismissTooltip(activity) setDeviceOrientation(isLandscape = true) pageRobot .scrollToCollapsingTables() diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt index 97b32efbfe1..760fabdaa24 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/ArticleTabTest.kt @@ -37,7 +37,6 @@ class ArticleTabTest : BaseTest( .scrollToItem(title = TestConstants.FEATURED_ARTICLE) .clickOnFeaturedArticle() pageRobot - .dismissTooltip(activity) .navigateUp() exploreFeedRobot .scrollToItem(title = TestConstants.FEATURED_ARTICLE) diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/EditIconTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/EditIconTest.kt index 655ea8695a7..b8b05ae0e67 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/EditIconTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/EditIconTest.kt @@ -37,13 +37,12 @@ class EditIconTest : BaseTest( .clickOnSystemDialogWithText("Allow") searchRobot .tapSearchView() - .typeTextInView(SEARCH_TERM) - .clickOnItemFromSearchList(0) - pageRobot - .dismissTooltip(activity) - .assertEditButtonProtection(isProtected = false) - .pressBack() - assertEditIconProtection(SEARCH_TERM_AVATAR) + assertEditIconProtection(SEARCH_TERM, isProtected = false) + assertEditIconProtection(SEARCH_TERM_AVATAR, action = { + dialogRobot + .dismissBigEnglishDialog() + .dismissContributionDialog() + }) assertEditIconProtection(SEARCH_TERM_VLADIMIR_PUTIN) assertEditIconProtection(SEARCH_TERM_KIM_JUNG_UN) assertEditIconProtection(SEARCH_TERM_JOE_BIDEN) @@ -54,13 +53,15 @@ class EditIconTest : BaseTest( assertEditIconProtection(SEARCH_TERM_HILLARY_CLINTON) } - private fun assertEditIconProtection(searchTerm: String, isProtected: Boolean = true) { + private fun assertEditIconProtection( + searchTerm: String, + isProtected: Boolean = true, + action: (() -> Unit)? = null + ) { searchRobot .typeTextInView(searchTerm) .clickOnItemFromSearchList(0) - dialogRobot - .dismissBigEnglishDialog() - .dismissContributionDialog() + action?.invoke() pageRobot .assertEditButtonProtection(isProtected) .pressBack() diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt index cc3c89afd37..2f81d0d22d3 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/LeadNonLeadImageAndPreviewLinkTest.kt @@ -35,9 +35,12 @@ class LeadNonLeadImageAndPreviewLinkTest : BaseTest( .swipePagerLeft() .pressBack() .scrollToNonLeadImage() - .swipePagerLeft() - .pressBack() - .clickLink("3-sphere") - .verifyPreviewDialogAppears() + .isGalleryActivityOffline(context, action = { + pageRobot + .swipePagerLeft() + .pressBack() + .clickLink("3-sphere") + .verifyPreviewDialogAppears() + }) } } diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/MediaTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/MediaTest.kt index 54c61e90a90..83fbe5e9857 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/MediaTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/MediaTest.kt @@ -30,8 +30,6 @@ class MediaTest : BaseTest( .tapSearchView() .typeTextInView(TestConstants.SPECIAL_ARTICLE_VORTEX_SHEDDING) .clickOnItemFromSearchList(0) - pageRobot - .dismissTooltip(activity) mediaRobot .verifyLeadImageHasGif() pageRobot diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/OverflowMenuTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/OverflowMenuTest.kt index d99b6c38905..0c8cc06e81e 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/OverflowMenuTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/OverflowMenuTest.kt @@ -47,8 +47,6 @@ class OverflowMenuTest : BaseTest( .clickOnItemFromSearchList(0) dialogRobot .dismissBigEnglishDialog() - homeScreenRobot - .dismissTooltip(activity) pageRobot .clickOverFlowMenuToolbar() pageActionItemRobot diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleOnlineOfflineTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleOnlineOfflineTest.kt index 9a8ff8d98dd..90a7e318331 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleOnlineOfflineTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleOnlineOfflineTest.kt @@ -53,12 +53,10 @@ class SavedArticleOnlineOfflineTest : BaseTest( .navigateToSavedPage() savedScreenRobot .clickItemOnTheList(0) - .dismissTooltip(activity) savedScreenRobot .verifySavedArticle("Apple") .verifySavedArticle("Orange") .clickItemOnReadingList(1) - .dismissTooltip(activity) systemRobot .turnOnAirplaneMode() savedScreenRobot diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt index ea54545d709..490cbee718c 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/SavedArticleTest.kt @@ -8,11 +8,9 @@ import org.wikipedia.TestConstants import org.wikipedia.TestConstants.FEATURED_ARTICLE import org.wikipedia.base.BaseTest import org.wikipedia.main.MainActivity -import org.wikipedia.robots.DialogRobot import org.wikipedia.robots.SystemRobot import org.wikipedia.robots.feature.ExploreFeedRobot import org.wikipedia.robots.feature.SearchRobot -import org.wikipedia.robots.feature.SettingsRobot import org.wikipedia.robots.navigation.BottomNavRobot import org.wikipedia.robots.screen.SavedScreenRobot @@ -26,8 +24,6 @@ class SavedArticleTest : BaseTest( private val exploreFeedRobot = ExploreFeedRobot() private val bottomNavRobot = BottomNavRobot() private val savedScreenRobot = SavedScreenRobot() - private val dialogRobot = DialogRobot() - private val settingsRobot = SettingsRobot() @Test fun runTest() { @@ -66,7 +62,6 @@ class SavedArticleTest : BaseTest( setDeviceOrientation(isLandscape = false) savedScreenRobot .clickItemOnTheList(0) - .dismissTooltip(activity) savedScreenRobot .clickFilterList() searchRobot diff --git a/app/src/androidTest/java/org/wikipedia/tests/articles/TableOfContentsTest.kt b/app/src/androidTest/java/org/wikipedia/tests/articles/TableOfContentsTest.kt index c38641a5045..ed8336e03e6 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/articles/TableOfContentsTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/articles/TableOfContentsTest.kt @@ -40,8 +40,6 @@ class TableOfContentsTest : BaseTest( dialogRobot .dismissBigEnglishDialog() setDeviceOrientation(isLandscape = false) - homeScreenRobot - .dismissTooltip(activity) tocTest() setDeviceOrientation(isLandscape = true) tocTest() diff --git a/app/src/androidTest/java/org/wikipedia/tests/settings/CollapseTablesTest.kt b/app/src/androidTest/java/org/wikipedia/tests/settings/CollapseTablesTest.kt index 0fdc4b03fe2..a1160987bd9 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/settings/CollapseTablesTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/settings/CollapseTablesTest.kt @@ -37,7 +37,6 @@ class CollapseTablesTest : BaseTest( .typeTextInView("apple") .clickOnItemFromSearchList(0) pageRobot - .dismissTooltip(activity) .scrollToCollapsingTables() .assertCollapsingTableIsVisible(isVisible = false) .pressBack() diff --git a/app/src/androidTest/java/org/wikipedia/tests/settings/DownloadReadingListTest.kt b/app/src/androidTest/java/org/wikipedia/tests/settings/DownloadReadingListTest.kt index 2db65fa3b87..0129e06e508 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/settings/DownloadReadingListTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/settings/DownloadReadingListTest.kt @@ -41,9 +41,6 @@ class DownloadReadingListTest : BaseTest( .tapSearchView() .typeTextInView("apple") .clickOnItemFromSearchList(0) - pageRobot - .dismissTooltip(activity) - readingListRobot .saveArticleToReadingList() .addToReadingList(context) diff --git a/app/src/androidTest/java/org/wikipedia/tests/settings/LinkPreviewTest.kt b/app/src/androidTest/java/org/wikipedia/tests/settings/LinkPreviewTest.kt index f0e19718acd..e2d10abb5d4 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/settings/LinkPreviewTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/settings/LinkPreviewTest.kt @@ -36,7 +36,6 @@ class LinkPreviewTest : BaseTest( .typeTextInView("apple") .clickOnItemFromSearchList(0) pageRobot - .dismissTooltip(activity) .clickLink(linkTitle = "Fruit") .verifyPreviewDialogAppears() .pressBack() diff --git a/app/src/androidTest/java/org/wikipedia/tests/settings/ReadingFocusModeTest.kt b/app/src/androidTest/java/org/wikipedia/tests/settings/ReadingFocusModeTest.kt index fd0d5a523a8..d587f631fb9 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/settings/ReadingFocusModeTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/settings/ReadingFocusModeTest.kt @@ -42,7 +42,6 @@ class ReadingFocusModeTest : BaseTest( .typeTextInView("apple") .clickOnItemFromSearchList(0) pageRobot - .dismissTooltip(activity) .assertEditPencilVisibility(isVisible = false) appThemeRobot .toggleTheme() From aecc709e94063c05af7642b154bbd0070c3c497e Mon Sep 17 00:00:00 2001 From: williamrai Date: Wed, 8 Jan 2025 11:01:41 -0500 Subject: [PATCH 21/22] - test fixes --- app/src/androidTest/java/org/wikipedia/tests/DeepLinkingTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/androidTest/java/org/wikipedia/tests/DeepLinkingTest.kt b/app/src/androidTest/java/org/wikipedia/tests/DeepLinkingTest.kt index a657a2e5983..b97d77e0a3c 100644 --- a/app/src/androidTest/java/org/wikipedia/tests/DeepLinkingTest.kt +++ b/app/src/androidTest/java/org/wikipedia/tests/DeepLinkingTest.kt @@ -25,7 +25,7 @@ class DeepLinkingTest : BaseTest( ) ) { - private val pageRobot = PageRobot() + private val pageRobot = PageRobot(context) @Test fun runTest() { From 32bff8a65ce76de72586a31ecef18f7cd9e9e26b Mon Sep 17 00:00:00 2001 From: williamrai Date: Fri, 10 Jan 2025 16:01:22 -0500 Subject: [PATCH 22/22] - test fixes --- app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt | 1 - .../java/org/wikipedia/robots/feature/SearchRobot.kt | 6 ------ .../androidTest/java/org/wikipedia/testsuites/TestSuite.kt | 3 ++- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt index fb2cec29623..fc73332c1f6 100644 --- a/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt @@ -26,7 +26,6 @@ import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.action.ViewActions.closeSoftKeyboard import androidx.test.espresso.action.ViewActions.doubleClick import androidx.test.espresso.action.ViewActions.longClick -import androidx.test.espresso.action.ViewActions.longClick import androidx.test.espresso.action.ViewActions.replaceText import androidx.test.espresso.action.ViewActions.scrollTo import androidx.test.espresso.action.ViewActions.swipeLeft diff --git a/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt b/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt index c0368b54c1d..d5a2a73044e 100644 --- a/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt +++ b/app/src/androidTest/java/org/wikipedia/robots/feature/SearchRobot.kt @@ -131,12 +131,6 @@ class SearchRobot : BaseRobot() { pressBack() } - fun dismissDialogIfShown() = apply { - performIfDialogShown(dialogText = "No, thanks", action = { - clickOnViewWithText("No, thanks") - }) - } - fun backToHistoryScreen() = apply { pressBack() pressBack() diff --git a/app/src/androidTest/java/org/wikipedia/testsuites/TestSuite.kt b/app/src/androidTest/java/org/wikipedia/testsuites/TestSuite.kt index ff140692919..ca796e0d321 100644 --- a/app/src/androidTest/java/org/wikipedia/testsuites/TestSuite.kt +++ b/app/src/androidTest/java/org/wikipedia/testsuites/TestSuite.kt @@ -17,6 +17,7 @@ import org.wikipedia.tests.SuggestedEditScreenTest SearchTest::class, SuggestedEditScreenTest::class, SettingsTestSuite::class, - DeepLinkingTest::class + DeepLinkingTest::class, + ArticlesTestSuite::class ) class TestSuite