1
0
Fork 0
fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt

65 lines
2.7 KiB
Kotlin
Raw Normal View History

2019-04-10 18:59:38 +02:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@file:Suppress("TooManyFunctions")
package org.mozilla.fenix.ui.robots
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
2019-04-10 18:59:38 +02:00
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import org.hamcrest.Matchers.allOf
import org.mozilla.fenix.R
2019-04-10 18:59:38 +02:00
/**
* Implementation of Robot Pattern for the home screen menu.
*/
2019-04-10 18:59:38 +02:00
class HomeScreenRobot {
fun verifyHomeScreen() = assertHomeScreen()
fun verifyHomePrivateBrowsingButton() = assertHomePrivateBrowsingButton()
fun verifyHomeMenu() = assertHomeMenu()
fun verifyHomeWordmark() = assertHomeWordmark()
fun verifyHomeToolbar() = assertHomeToolbar()
fun verifyHomeComponent() = assertHomeComponent()
class Transition {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
fun openThreeDotMenu(interact: ThreeDotMenuRobot.() -> Unit): ThreeDotMenuRobot.Transition {
mDevice.waitForIdle()
threeDotButton().perform(click())
ThreeDotMenuRobot().interact()
return ThreeDotMenuRobot.Transition()
}
}
2019-04-10 18:59:38 +02:00
}
fun homeScreen(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition {
2019-04-10 18:59:38 +02:00
HomeScreenRobot().interact()
return HomeScreenRobot.Transition()
2019-04-10 18:59:38 +02:00
}
private fun assertHomeScreen() = onView(ViewMatchers.withResourceName("homeLayout"))
2019-04-10 18:59:38 +02:00
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertHomeMenu() = onView(ViewMatchers.withResourceName("menuButton"))
2019-04-10 18:59:38 +02:00
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertHomePrivateBrowsingButton() = onView(ViewMatchers.withResourceName("privateBrowsingButton"))
2019-04-10 18:59:38 +02:00
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertHomeWordmark() = onView(ViewMatchers.withResourceName("wordmark"))
2019-04-10 18:59:38 +02:00
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertHomeToolbar() = onView(ViewMatchers.withResourceName("toolbar"))
2019-04-10 18:59:38 +02:00
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertHomeComponent() = onView(ViewMatchers.withResourceName("home_component"))
2019-04-10 18:59:38 +02:00
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun threeDotButton() = onView(allOf(ViewMatchers.withId(R.id.menuButton)))