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.ext:junit:1.1.1'
|
||||||
androidTestImplementation 'androidx.test:rules:1.3.0-alpha03'
|
androidTestImplementation 'androidx.test:rules:1.3.0-alpha03'
|
||||||
androidTestImplementation 'com.google.code.findbugs:jsr305:3.0.2'
|
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.ViewInteraction
|
||||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||||
import androidx.test.espresso.matcher.ViewMatchers
|
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 {
|
fun ViewInteraction.isDisplayed(): Boolean {
|
||||||
try {
|
try {
|
||||||
|
@ -25,3 +28,8 @@ fun ViewInteraction.waitAndPerform(viewActions: ViewAction): ViewInteraction? {
|
||||||
return perform(viewActions)
|
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
|
package info.nightscout.androidaps
|
||||||
|
|
||||||
|
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
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
|
||||||
import androidx.test.espresso.action.ViewActions.click
|
import androidx.test.espresso.action.ViewActions.click
|
||||||
import androidx.test.espresso.action.ViewActions.scrollTo
|
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.ext.junit.runners.AndroidJUnit4
|
||||||
import androidx.test.filters.LargeTest
|
import androidx.test.filters.LargeTest
|
||||||
import androidx.test.rule.ActivityTestRule
|
import androidx.test.rule.ActivityTestRule
|
||||||
import androidx.test.rule.GrantPermissionRule
|
import androidx.test.rule.GrantPermissionRule
|
||||||
import info.nightscout.androidaps.data.Profile
|
|
||||||
import info.nightscout.androidaps.interfaces.PluginType
|
import info.nightscout.androidaps.interfaces.PluginType
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin
|
||||||
|
@ -39,7 +41,6 @@ import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
|
|
||||||
|
|
||||||
@LargeTest
|
@LargeTest
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
class SetupWizardActivityTest {
|
class SetupWizardActivityTest {
|
||||||
|
@ -50,7 +51,7 @@ class SetupWizardActivityTest {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
@JvmField
|
@JvmField
|
||||||
var mGrantPermissionRule =
|
var mGrantPermissionRule: GrantPermissionRule =
|
||||||
GrantPermissionRule.grant(
|
GrantPermissionRule.grant(
|
||||||
android.Manifest.permission.ACCESS_FINE_LOCATION,
|
android.Manifest.permission.ACCESS_FINE_LOCATION,
|
||||||
android.Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
|
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 &
|
adb shell settings put global animator_duration_scale 0 &
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun setupWizardActivityTest() {
|
fun setupWizardActivityTest() {
|
||||||
|
SP.clear()
|
||||||
Assert.assertTrue(isRunningTest())
|
Assert.assertTrue(isRunningTest())
|
||||||
// Welcome page
|
// Welcome page
|
||||||
onView(withId(R.id.next_button)).perform(click())
|
onView(withId(R.id.next_button)).perform(click())
|
||||||
|
@ -86,7 +87,7 @@ adb shell settings put global animator_duration_scale 0 &
|
||||||
// Agreement page
|
// Agreement page
|
||||||
onView(withText("I UNDERSTAND AND AGREE")).perform(scrollTo(), click())
|
onView(withText("I UNDERSTAND AND AGREE")).perform(scrollTo(), click())
|
||||||
onView(withId(R.id.next_button)).waitAndPerform(click())
|
onView(withId(R.id.next_button)).waitAndPerform(click())
|
||||||
// Loction permission
|
// Location permission
|
||||||
var askButton = onView(withText("Ask for permission"))
|
var askButton = onView(withText("Ask for permission"))
|
||||||
if (askButton.isDisplayed()) {
|
if (askButton.isDisplayed()) {
|
||||||
askButton.perform(scrollTo(), click())
|
askButton.perform(scrollTo(), click())
|
||||||
|
@ -99,6 +100,11 @@ adb shell settings put global animator_duration_scale 0 &
|
||||||
onView(withText("OK")).perform(click())
|
onView(withText("OK")).perform(click())
|
||||||
onView(withId(R.id.next_button)).waitAndPerform(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
|
// Units selection
|
||||||
onView(withText("mmol/L")).perform(scrollTo(), click())
|
onView(withText("mmol/L")).perform(scrollTo(), click())
|
||||||
onView(withId(R.id.next_button)).perform(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()))
|
onView(Matchers.allOf(withId(R.id.localprofile_profileswitch), isDisplayed()))
|
||||||
.perform(scrollTo(), click())
|
.perform(scrollTo(), click())
|
||||||
onView(allOf(withId(R.id.ok), isDisplayed())).perform(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())
|
onView(withId(R.id.next_button)).waitAndPerform(click())
|
||||||
// Profile switch
|
// Profile switch
|
||||||
askButton = onView(withText("Do Profile Switch"))
|
askButton = onView(withText("Do Profile Switch"))
|
||||||
if (askButton.isDisplayed()) {
|
if (askButton.isDisplayed()) {
|
||||||
askButton.perform(scrollTo(), click())
|
askButton.perform(scrollTo(), click())
|
||||||
onView(allOf(withId(R.id.ok), isDisplayed())).perform(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)
|
while (ProfileFunctions.getInstance().profile == null) SystemClock.sleep(100)
|
||||||
onView(withId(R.id.next_button)).waitAndPerform(click())
|
onView(withId(R.id.next_button)).waitAndPerform(click())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue