Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Espresso test explore feed #5130

Open
wants to merge 17 commits into
base: espresso-test-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions app/src/androidTest/java/org/wikipedia/TestSuite.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,12 @@ package org.wikipedia
import org.junit.runner.RunWith
import org.junit.runners.Suite
import org.junit.runners.Suite.SuiteClasses
import org.wikipedia.robots.feature.SettingsRobot
import org.wikipedia.test.loggedinuser.ContributionScreenTest
import org.wikipedia.test.loggedinuser.NotificationScreenTest
import org.wikipedia.test.loggedoutuser.EditArticleTest
import org.wikipedia.test.loggedoutuser.ExploreFeedTest
import org.wikipedia.test.loggedoutuser.HistoryScreenTest
import org.wikipedia.test.loggedoutuser.HomeScreenTest
import org.wikipedia.test.loggedoutuser.OnboardingTest
import org.wikipedia.test.loggedoutuser.PageTest
import org.wikipedia.test.loggedoutuser.SavedScreenTest

@RunWith(Suite::class)
@SuiteClasses(
EditArticleTest::class,
ExploreFeedTest::class,
HistoryScreenTest::class,
HomeScreenTest::class,
OnboardingTest::class,
PageTest::class,
SavedScreenTest::class,
SettingsRobot::class,
ContributionScreenTest::class,
NotificationScreenTest::class
ExploreFeedTest::class,
)
class TestSuite
28 changes: 27 additions & 1 deletion app/src/androidTest/java/org/wikipedia/base/BaseRobot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package org.wikipedia.base

import android.app.Activity
import android.graphics.Rect
import android.util.Log
import android.view.View
import android.widget.TextView
import androidx.annotation.IdRes
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso.onView
Expand All @@ -18,6 +20,7 @@ import androidx.test.espresso.action.ViewActions.swipeRight
import androidx.test.espresso.action.ViewActions.swipeUp
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.matcher.BoundedMatcher
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.RootMatchers.withDecorView
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
Expand All @@ -33,17 +36,24 @@ 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 org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matchers
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.not
import org.wikipedia.TestUtil
import org.wikipedia.TestUtil.isDisplayed
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),
hasText(text),
)).perform(scrollAndClick())
}

protected fun clickOnViewWithId(@IdRes viewId: Int) {
onView(withId(viewId)).perform(click())
}
Expand Down Expand Up @@ -200,6 +210,7 @@ abstract class BaseRobot {
action()
} catch (e: Exception) {
// Dialog not shown or text not found
Log.e("error", "")
}
}

Expand Down Expand Up @@ -276,6 +287,11 @@ abstract class BaseRobot {
.perform(click())
}

protected fun makeViewVisibleAndClick(@IdRes viewId: Int, @IdRes parentViewId: Int) {
onView(allOf(withId(viewId), isDescendantOfA(withId(parentViewId))))
.perform(scrollAndClick())
}

private fun scrollAndClick() = object : ViewAction {
override fun getConstraints(): Matcher<View> {
return isDisplayingAtLeast(10)
Expand All @@ -298,4 +314,14 @@ abstract class BaseRobot {
uiController.loopMainThreadForAtLeast(1000)
}
}

private fun hasText(text: String) = object : BoundedMatcher<View, TextView>(TextView::class.java) {
override fun describeTo(description: Description?) {
description?.appendText("contains text $text")
}

override fun matchesSafely(item: TextView): Boolean {
return item.text.toString().contains(text, ignoreCase = true)
}
}
}
1 change: 1 addition & 0 deletions app/src/androidTest/java/org/wikipedia/base/BaseTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ object TestConfig {
const val DELAY_SHORT = 1L
const val DELAY_MEDIUM = 2L
const val DELAY_LARGE = 5L
const val DELAY_SWIPE_TO_REFRESH = 8L
const val SEARCH_TERM = "hopf fibration"
const val ARTICLE_TITLE = "Hopf fibration"
const val ARTICLE_TITLE_ESPANOL = "Fibración de Hopf"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ class SystemRobot : BaseRobot() {
} catch (e: Exception) {
Log.d("dialog", "Dialog did not appear or couldn't be clicked.")
}
delay(TestConfig.DELAY_MEDIUM)
}
}
Loading
Loading