android: fix MainActivityTest

-Permissions are shown after 'Get Started' screen, fix ordering in test
-Tap 'Authorize Tailscale'
-Re-add instrumentation test runner in build.gradle

Updates tailscale/corp#24242

Signed-off-by: kari-ts <kari@tailscale.com>
pull/550/head
kari-ts 1 year ago
parent 0bd4ef932b
commit 179d93db68

@ -39,6 +39,7 @@ android {
targetSdkVersion 34 targetSdkVersion 34
versionCode 241 versionCode 241
versionName "1.77.44-tc0a1ed86c-gcafb114ae0a" versionName "1.77.44-tc0a1ed86c-gcafb114ae0a"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// This setting, which defaults to 'true', will cause Tailscale to fall // This setting, which defaults to 'true', will cause Tailscale to fall
// back to the Google DNS servers if it cannot determine what the // back to the Google DNS servers if it cannot determine what the

@ -17,6 +17,11 @@ import androidx.test.uiautomator.UiSelector
import dev.turingcomplete.kotlinonetimepassword.HmacAlgorithm import dev.turingcomplete.kotlinonetimepassword.HmacAlgorithm
import dev.turingcomplete.kotlinonetimepassword.TimeBasedOneTimePasswordConfig import dev.turingcomplete.kotlinonetimepassword.TimeBasedOneTimePasswordConfig
import dev.turingcomplete.kotlinonetimepassword.TimeBasedOneTimePasswordGenerator import dev.turingcomplete.kotlinonetimepassword.TimeBasedOneTimePasswordGenerator
import java.net.HttpURLConnection
import java.net.URL
import java.util.concurrent.TimeUnit
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds
import org.apache.commons.codec.binary.Base32 import org.apache.commons.codec.binary.Base32
import org.junit.After import org.junit.After
import org.junit.Assert import org.junit.Assert
@ -24,11 +29,6 @@ import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import java.net.HttpURLConnection
import java.net.URL
import java.util.concurrent.TimeUnit
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
@LargeTest @LargeTest
@ -59,18 +59,18 @@ class MainActivityTest {
timeStep = 30, timeStep = 30,
timeStepUnit = TimeUnit.SECONDS) timeStepUnit = TimeUnit.SECONDS)
val githubTOTP = TimeBasedOneTimePasswordGenerator(github2FASecret, config) val githubTOTP = TimeBasedOneTimePasswordGenerator(github2FASecret, config)
val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
Log.d(TAG, "Wait for VPN permission prompt and accept")
device.find(By.text("Connection request"))
device.find(By.text("OK")).click()
Log.d(TAG, "Click through Get Started screen") Log.d(TAG, "Click through Get Started screen")
device.find(By.text("Get Started")) device.find(By.text("Get Started"))
device.find(By.text("Get Started")).click() device.find(By.text("Get Started")).click()
Log.d(TAG, "Wait for VPN permission prompt and accept")
device.find(By.text("Connection request"))
device.find(By.text("OK")).click()
asNecessary( asNecessary(
timeout = 2.minutes, 2.minutes,
{ {
Log.d(TAG, "Log in") Log.d(TAG, "Log in")
device.find(By.text("Log in")).click() device.find(By.text("Log in")).click()
@ -93,7 +93,6 @@ class MainActivityTest {
}, },
{ {
Log.d(TAG, "Make sure GitHub page has loaded") Log.d(TAG, "Make sure GitHub page has loaded")
device.find(By.text("New to GitHub"))
device.find(By.text("Username or email address")) device.find(By.text("Username or email address"))
device.find(By.text("Sign in")) device.find(By.text("Sign in"))
}, },
@ -115,10 +114,15 @@ class MainActivityTest {
.setText(githubTOTP.generate()) .setText(githubTOTP.generate())
device.find(UiSelector().instance(0).className(Button::class.java)).click() device.find(UiSelector().instance(0).className(Button::class.java)).click()
}, },
{
Log.d(TAG, "Authorizing Tailscale")
device.find(By.text("Authorize tailscale")).click()
},
{ {
Log.d(TAG, "Accept Tailscale app") Log.d(TAG, "Accept Tailscale app")
device.find(By.text("Learn more about OAuth")) device.find(By.text("Learn more about OAuth"))
// Sleep a little to give button time to activate // Sleep a little to give button time to activate
Thread.sleep(5.seconds.inWholeMilliseconds) Thread.sleep(5.seconds.inWholeMilliseconds)
device.find(UiSelector().instance(1).className(Button::class.java)).click() device.find(UiSelector().instance(1).className(Button::class.java)).click()
}, },
@ -126,8 +130,7 @@ class MainActivityTest {
Log.d(TAG, "Connect device") Log.d(TAG, "Connect device")
device.find(By.text("Connect device")) device.find(By.text("Connect device"))
device.find(UiSelector().instance(0).className(Button::class.java)).click() device.find(UiSelector().instance(0).className(Button::class.java)).click()
}, })
)
try { try {
Log.d(TAG, "Accept Permission (Either Storage or Notifications)") Log.d(TAG, "Accept Permission (Either Storage or Notifications)")

Loading…
Cancel
Save