modified concerned tests to replace swipe calls

This commit is contained in:
Ulysse Widmer 2020-03-30 19:31:36 +02:00
parent 35d11512c1
commit 827db70972
3 changed files with 18 additions and 18 deletions

View File

@ -10,6 +10,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.google.android.material.tabs.TabLayout
import okhttp3.mockwebserver.Dispatcher
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
@ -77,13 +78,12 @@ class MockedServerTest {
.targetContext.getSharedPreferences("com.h.pixeldroid.pref", Context.MODE_PRIVATE)
preferences.edit().putString("accessToken", "azerty").apply()
preferences.edit().putString("domain", baseUrl.toString()).apply()
ActivityScenario.launch(MainActivity::class.java)
}
@Test
fun testFollowersTextView() {
onView(withId(R.id.view_pager)).perform(ViewActions.swipeLeft()).perform(ViewActions.swipeLeft()).perform(
ViewActions.swipeLeft()
).perform(ViewActions.swipeLeft())
ActivityScenario.launch(MainActivity::class.java).onActivity{
a -> a.findViewById<TabLayout>(R.id.tabs).getTabAt(4)?.select()
}
Thread.sleep(1000)
onView(withId(R.id.nbFollowersTextView)).check(matches(withText("68\nFollowers")))
onView(withId(R.id.accountNameTextView)).check(matches(withText("deerbard_photo")))
@ -94,16 +94,17 @@ class MockedServerTest {
Thread.sleep(1000)
val firstDesc = withId(R.id.description)
onView(withId(R.id.view_pager)).perform(ViewActions.swipeUp()).perform(ViewActions.swipeDown()).perform(
ViewActions.swipeDown()
)
onView(withId(R.id.description)).check(matches(firstDesc))
onView(withId(R.id.view_pager))
.perform(ViewActions.swipeUp())
.perform(ViewActions.swipeDown())
.perform(ViewActions.swipeDown())
onView(firstDesc).check(matches(firstDesc))
}
@Test
fun testNotificationsList() {
onView(withId(R.id.view_pager)).perform(ViewActions.swipeLeft()).perform(
ViewActions.swipeLeft()
).perform(ViewActions.swipeLeft())
ActivityScenario.launch(MainActivity::class.java).onActivity{
a -> a.findViewById<TabLayout>(R.id.tabs).getTabAt(3)?.select()
}
Thread.sleep(1000)
onView(withId(R.id.view_pager)).perform(ViewActions.swipeUp()).perform(ViewActions.swipeDown())
@ -115,9 +116,9 @@ class MockedServerTest {
}
@Test
fun clickNotification() {
onView(withId(R.id.view_pager)).perform(ViewActions.swipeLeft()).perform(
ViewActions.swipeLeft()
).perform(ViewActions.swipeLeft())
ActivityScenario.launch(MainActivity::class.java).onActivity{
a -> a.findViewById<TabLayout>(R.id.tabs).getTabAt(3)?.select()
}
Thread.sleep(1000)
onView(withId(R.id.view_pager)).perform(ViewActions.swipeUp()).perform(ViewActions.swipeDown())

View File

@ -16,7 +16,6 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import kotlin.concurrent.thread
@RunWith(AndroidJUnit4::class)

View File

@ -8,9 +8,9 @@ import androidx.test.espresso.action.ViewActions.swipeRight
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.rule.ActivityTestRule
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -19,8 +19,8 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class SwipeTest {
@get:Rule
var activityRule: ActivityTestRule<MainActivity>
= ActivityTestRule(MainActivity::class.java)
var activityRule: ActivityScenarioRule<MainActivity>
= ActivityScenarioRule(MainActivity::class.java)
@Before
fun before(){
val preferences = getInstrumentation()