Improve SetupWizardTest to be runnable on real device
This commit is contained in:
parent
9098eb2da0
commit
f111b731e7
3 changed files with 44 additions and 26 deletions
|
@ -315,6 +315,7 @@ dependencies {
|
|||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test:rules:1.3.0-alpha03'
|
||||
androidTestImplementation 'com.google.code.findbugs:jsr305:3.0.2'
|
||||
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,6 +4,9 @@ import androidx.test.espresso.ViewAction
|
|||
import androidx.test.espresso.ViewInteraction
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.matcher.ViewMatchers
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import androidx.test.uiautomator.UiSelector
|
||||
|
||||
fun ViewInteraction.isDisplayed(): Boolean {
|
||||
try {
|
||||
|
@ -25,3 +28,8 @@ fun ViewInteraction.waitAndPerform(viewActions: ViewAction): ViewInteraction? {
|
|||
return perform(viewActions)
|
||||
}
|
||||
|
||||
fun clickOkInDialog() {
|
||||
val uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
val button = uiDevice.findObject(UiSelector().clickable(true).checkable(false).index(1))
|
||||
if (button.exists() && button.isEnabled) button.click()
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package info.nightscout.androidaps
|
||||
|
||||
|
||||
import android.os.SystemClock
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
@ -9,12 +8,15 @@ import androidx.test.espresso.Espresso.onView
|
|||
import androidx.test.espresso.action.ViewActions
|
||||
import androidx.test.espresso.action.ViewActions.click
|
||||
import androidx.test.espresso.action.ViewActions.scrollTo
|
||||
import androidx.test.espresso.matcher.ViewMatchers.*
|
||||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withClassName
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withTagValue
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.LargeTest
|
||||
import androidx.test.rule.ActivityTestRule
|
||||
import androidx.test.rule.GrantPermissionRule
|
||||
import info.nightscout.androidaps.data.Profile
|
||||
import info.nightscout.androidaps.interfaces.PluginType
|
||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin
|
||||
|
@ -39,7 +41,6 @@ import org.junit.Rule
|
|||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
|
||||
@LargeTest
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class SetupWizardActivityTest {
|
||||
|
@ -50,7 +51,7 @@ class SetupWizardActivityTest {
|
|||
|
||||
@Rule
|
||||
@JvmField
|
||||
var mGrantPermissionRule =
|
||||
var mGrantPermissionRule: GrantPermissionRule =
|
||||
GrantPermissionRule.grant(
|
||||
android.Manifest.permission.ACCESS_FINE_LOCATION,
|
||||
android.Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
|
||||
|
@ -74,9 +75,9 @@ adb shell settings put global transition_animation_scale 0 &
|
|||
adb shell settings put global animator_duration_scale 0 &
|
||||
*/
|
||||
|
||||
|
||||
@Test
|
||||
fun setupWizardActivityTest() {
|
||||
SP.clear()
|
||||
Assert.assertTrue(isRunningTest())
|
||||
// Welcome page
|
||||
onView(withId(R.id.next_button)).perform(click())
|
||||
|
@ -86,7 +87,7 @@ adb shell settings put global animator_duration_scale 0 &
|
|||
// Agreement page
|
||||
onView(withText("I UNDERSTAND AND AGREE")).perform(scrollTo(), click())
|
||||
onView(withId(R.id.next_button)).waitAndPerform(click())
|
||||
// Loction permission
|
||||
// Location permission
|
||||
var askButton = onView(withText("Ask for permission"))
|
||||
if (askButton.isDisplayed()) {
|
||||
askButton.perform(scrollTo(), click())
|
||||
|
@ -99,6 +100,11 @@ adb shell settings put global animator_duration_scale 0 &
|
|||
onView(withText("OK")).perform(click())
|
||||
onView(withId(R.id.next_button)).waitAndPerform(click())
|
||||
}
|
||||
// Import settings : skip of found
|
||||
askButton = onView(withText("IMPORT SETTINGS"))
|
||||
if (askButton.isDisplayed()) {
|
||||
onView(withId(R.id.next_button)).waitAndPerform(click())
|
||||
}
|
||||
// Units selection
|
||||
onView(withText("mmol/L")).perform(scrollTo(), click())
|
||||
onView(withId(R.id.next_button)).perform(click())
|
||||
|
@ -152,14 +158,17 @@ adb shell settings put global animator_duration_scale 0 &
|
|||
onView(Matchers.allOf(withId(R.id.localprofile_profileswitch), isDisplayed()))
|
||||
.perform(scrollTo(), click())
|
||||
onView(allOf(withId(R.id.ok), isDisplayed())).perform(click())
|
||||
onView(Matchers.allOf(withText("OK"), isDisplayed())).perform(click())
|
||||
// confirm dialog
|
||||
//onView(Matchers.allOf(withText("OK"), isDisplayed())).perform(click()) not working on real phone
|
||||
clickOkInDialog()
|
||||
onView(withId(R.id.next_button)).waitAndPerform(click())
|
||||
// Profile switch
|
||||
askButton = onView(withText("Do Profile Switch"))
|
||||
if (askButton.isDisplayed()) {
|
||||
askButton.perform(scrollTo(), click())
|
||||
onView(allOf(withId(R.id.ok), isDisplayed())).perform(click())
|
||||
onView(Matchers.allOf(withText("OK"), isDisplayed())).perform(click())
|
||||
// onView(Matchers.allOf(withText("OK"), isDisplayed())).perform(click()) not working on real phone
|
||||
clickOkInDialog()
|
||||
while (ProfileFunctions.getInstance().profile == null) SystemClock.sleep(100)
|
||||
onView(withId(R.id.next_button)).waitAndPerform(click())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue