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

EspressoTest #846

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ android {
dependencies {
implementation project(':core')
implementation "androidx.appcompat:appcompat:${versions.appcompat}"
//noinspection OutdatedLibrary
implementation "com.crashlytics.sdk.android:crashlytics:${versions.crashlytics}"
implementation "com.google.firebase:firebase-core:${versions.firebase}"
implementation "com.github.bumptech.glide:glide:${versions.glide}"
Expand Down
86 changes: 86 additions & 0 deletions app/src/androidTest/java/io/plaidapp/ui/AboutActivityTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package io.plaidapp.ui


import android.view.View
import android.view.ViewGroup
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import androidx.test.runner.AndroidJUnit4
import io.plaidapp.R
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.hamcrest.TypeSafeMatcher
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@LargeTest
@RunWith(AndroidJUnit4::class)
class AboutActivityTest {

@Rule
@JvmField
var mActivityTestRule = ActivityTestRule(HomeActivity::class.java)

@Test
fun aboutActivityTest() {
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
Thread.sleep(7000)

val overflowMenuButton = onView(
allOf(withContentDescription("More options"),
childAtPosition(
childAtPosition(
withId(R.id.toolbar),
1),
3),
isDisplayed()))
overflowMenuButton.perform(click())

// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
Thread.sleep(250)

val appCompatTextView = onView(
allOf(withId(R.id.title), withText("About"),
childAtPosition(
childAtPosition(
withId(R.id.content),
0),
0),
isDisplayed()))
appCompatTextView.perform(click())

// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
Thread.sleep(7000)

pressBack()
}

private fun childAtPosition(
parentMatcher: Matcher<View>, position: Int): Matcher<View> {

return object : TypeSafeMatcher<View>() {
override fun describeTo(description: Description) {
description.appendText("Child at position $position in parent ")
parentMatcher.describeTo(description)
}

public override fun matchesSafely(view: View): Boolean {
val parent = view.parent
return parent is ViewGroup && parentMatcher.matches(parent)
&& view == parent.getChildAt(position)
}
}
}
}
69 changes: 69 additions & 0 deletions app/src/androidTest/java/io/plaidapp/ui/CheckingToolbarItems.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package io.plaidapp.ui


import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import androidx.test.runner.AndroidJUnit4
import io.plaidapp.R
import org.hamcrest.Matchers.allOf
import org.hamcrest.core.IsInstanceOf
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@LargeTest
@RunWith(AndroidJUnit4::class)
class CheckingToolbarItems {

@Rule
@JvmField
var mActivityTestRule = ActivityTestRule(HomeActivity::class.java)

@Test
fun checkingToolbarItems() {
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
Thread.sleep(7000)

val viewGroup = onView(
allOf(withId(R.id.toolbar),
withParent(withParent(withId(R.id.drawer))),
isDisplayed()))
viewGroup.check(matches(isDisplayed()))

val textView = onView(
allOf(withText("Plaid"),
withParent(allOf(withId(R.id.toolbar),
withParent(IsInstanceOf.instanceOf(android.widget.FrameLayout::class.java)))),
isDisplayed()))
textView.check(matches(withText("Plaid")))

val textView2 = onView(
allOf(withId(R.id.menu_search), withContentDescription("Search"),
withParent(withParent(withId(R.id.toolbar))),
isDisplayed()))
textView2.check(matches(isDisplayed()))

val checkBox = onView(
allOf(withId(R.id.menu_theme),
withParent(withParent(withId(R.id.toolbar))),
isDisplayed()))
checkBox.check(matches(isDisplayed()))

val textView3 = onView(
allOf(withId(R.id.menu_filter), withContentDescription("Filter"),
withParent(withParent(withId(R.id.toolbar))),
isDisplayed()))
textView3.check(matches(isDisplayed()))

val imageView = onView(
allOf(withContentDescription("More options"),
withParent(withParent(withId(R.id.toolbar))),
isDisplayed()))
imageView.check(matches(isDisplayed()))
}
}
170 changes: 170 additions & 0 deletions app/src/androidTest/java/io/plaidapp/ui/FilterActivityTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package io.plaidapp.ui


import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import androidx.test.runner.AndroidJUnit4
import io.plaidapp.R
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.hamcrest.TypeSafeMatcher
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@LargeTest
@RunWith(AndroidJUnit4::class)
class FilterActivityTest {

@Rule
@JvmField
var mActivityTestRule = ActivityTestRule(HomeActivity::class.java)

@Test
fun filterActivityTest() {
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
Thread.sleep(7000)

val actionMenuItemView = onView(
allOf(
withId(R.id.menu_filter), withContentDescription("Filter"),
childAtPosition(
childAtPosition(
withId(R.id.toolbar),
1
),
2
),
isDisplayed()
)
)
actionMenuItemView.perform(click())

val recyclerView = onView(
allOf(
withId(R.id.filters),
childAtPosition(
withId(R.id.drawer),
1
)
)
)
recyclerView.perform(actionOnItemAtPosition<ViewHolder>(0, click()))

val recyclerView2 = onView(
allOf(
withId(R.id.filters),
childAtPosition(
withId(R.id.drawer),
1
)
)
)
recyclerView2.perform(actionOnItemAtPosition<ViewHolder>(1, click()))

val actionMenuItemView2 = onView(
allOf(
withId(R.id.menu_filter), withContentDescription("Filter"),
childAtPosition(
childAtPosition(
withId(R.id.toolbar),
1
),
2
),
isDisplayed()
)
)
actionMenuItemView2.perform(click())

val recyclerView3 = onView(
allOf(
withId(R.id.filters),
childAtPosition(
withId(R.id.drawer),
1
)
)
)
recyclerView3.perform(actionOnItemAtPosition<ViewHolder>(0, click()))

val recyclerView4 = onView(
allOf(
withId(R.id.filters),
childAtPosition(
withId(R.id.drawer),
1
)
)
)
recyclerView4.perform(actionOnItemAtPosition<ViewHolder>(2, click()))

val actionMenuItemView3 = onView(
allOf(
withId(R.id.menu_filter), withContentDescription("Filter"),
childAtPosition(
childAtPosition(
withId(R.id.toolbar),
1
),
2
),
isDisplayed()
)
)
actionMenuItemView3.perform(click())

val recyclerView5 = onView(
allOf(
withId(R.id.filters),
childAtPosition(
withId(R.id.drawer),
1
)
)
)
recyclerView5.perform(actionOnItemAtPosition<ViewHolder>(2, click()))

val recyclerView6 = onView(
allOf(
withId(R.id.filters),
childAtPosition(
withId(R.id.drawer),
1
)
)
)
recyclerView6.perform(actionOnItemAtPosition<ViewHolder>(1, click()))

pressBack()
}

private fun childAtPosition(
parentMatcher: Matcher<View>, position: Int
): Matcher<View> {

return object : TypeSafeMatcher<View>() {
override fun describeTo(description: Description) {
description.appendText("Child at position $position in parent ")
parentMatcher.describeTo(description)
}

public override fun matchesSafely(view: View): Boolean {
val parent = view.parent
return parent is ViewGroup && parentMatcher.matches(parent)
&& view == parent.getChildAt(position)
}
}
}
}
Loading