diff options
| author | Albin <albin@mullvad.net> | 2022-12-28 15:10:27 +0100 |
|---|---|---|
| committer | Albin <albin@mullvad.net> | 2023-01-10 15:32:44 +0100 |
| commit | 88fcc41c3595166db2893a70f7d77bacde4ad1cc (patch) | |
| tree | ee6bc58b0d6a88897f4a1da3697f753d6d22249d /android/test | |
| parent | aaae3e6c79fc0f684f261b1d607aad69542bf404 (diff) | |
| download | mullvadvpn-88fcc41c3595166db2893a70f7d77bacde4ad1cc.tar.xz mullvadvpn-88fcc41c3595166db2893a70f7d77bacde4ad1cc.zip | |
Replace e2e conncheck webview with volley
The reason for this change is that ui automator
doesn't work well with webviews.
Diffstat (limited to 'android/test')
6 files changed, 28 insertions, 58 deletions
diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/ConnectionTest.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/ConnectionTest.kt index 719aedf641..8f72fef0be 100644 --- a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/ConnectionTest.kt +++ b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/ConnectionTest.kt @@ -3,9 +3,10 @@ package net.mullvad.mullvadvpn.test.e2e import androidx.test.uiautomator.By import junit.framework.Assert.assertEquals import net.mullvad.mullvadvpn.test.common.extension.findObjectWithTimeout -import net.mullvad.mullvadvpn.test.e2e.interactor.WebViewInteractor import net.mullvad.mullvadvpn.test.common.rule.ForgetAllVpnAppsInSettingsTestRule import net.mullvad.mullvadvpn.test.e2e.misc.CleanupAccountTestRule +import net.mullvad.mullvadvpn.test.e2e.misc.ConnCheckState +import net.mullvad.mullvadvpn.test.e2e.misc.SimpleMullvadHttpClient import org.junit.Rule import org.junit.Test @@ -28,10 +29,10 @@ class ConnectionTest : EndToEndTest() { device.findObjectWithTimeout(By.text("Secure my connection")).click() device.findObjectWithTimeout(By.text("OK")).click() device.findObjectWithTimeout(By.text("SECURE CONNECTION")) - val expected = WebViewInteractor.ConnCheckState(true, app.extractIpAddress()) + val expected = ConnCheckState(true, app.extractIpAddress()) // Then - val result = web.launchAndExtractConnCheckState() + val result = SimpleMullvadHttpClient(targetContext).runConnectionCheck() assertEquals(expected, result) } } diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/EndToEndTest.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/EndToEndTest.kt index b65c43e23c..f8f5bb8f6c 100644 --- a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/EndToEndTest.kt +++ b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/EndToEndTest.kt @@ -12,7 +12,6 @@ import net.mullvad.mullvadvpn.test.e2e.constant.INVALID_TEST_ACCOUNT_TOKEN_ARGUM import net.mullvad.mullvadvpn.test.e2e.constant.LOG_TAG import net.mullvad.mullvadvpn.test.e2e.constant.VALID_TEST_ACCOUNT_TOKEN_ARGUMENT_KEY import net.mullvad.mullvadvpn.test.e2e.extension.getRequiredArgument -import net.mullvad.mullvadvpn.test.e2e.interactor.WebViewInteractor import org.junit.Before import org.junit.Rule import org.junit.runner.RunWith @@ -51,10 +50,5 @@ abstract class EndToEndTest { device, targetContext ) - - web = WebViewInteractor( - targetContext, - device - ) } } diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/constant/ConnCheckConstants.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/constant/ConnCheckConstants.kt index 825b6a20c7..5357ce0e75 100644 --- a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/constant/ConnCheckConstants.kt +++ b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/constant/ConnCheckConstants.kt @@ -1,5 +1,3 @@ package net.mullvad.mullvadvpn.test.e2e.constant -const val CONN_CHECK_URL = "https://mullvad.net/en/check/" -const val CONN_CHECK_IS_CONNECTED = "Using Mullvad VPN" -const val CONN_CHECK_IS_NOT_CONNECTED = "Not using Mullvad VPN" +const val CONN_CHECK_URL = "https://am.i.mullvad.net/json" diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/interactor/WebViewInteractor.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/interactor/WebViewInteractor.kt deleted file mode 100644 index f244aed5e7..0000000000 --- a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/interactor/WebViewInteractor.kt +++ /dev/null @@ -1,46 +0,0 @@ -package net.mullvad.mullvadvpn.test.e2e.interactor - -import android.content.Context -import android.content.Intent -import android.view.View -import android.webkit.WebView -import androidx.test.uiautomator.By -import androidx.test.uiautomator.UiDevice -import net.mullvad.mullvadvpn.TestActivity -import net.mullvad.mullvadvpn.test.common.extension.findObjectByCaseInsensitiveText -import net.mullvad.mullvadvpn.test.common.extension.findObjectWithTimeout -import net.mullvad.mullvadvpn.test.e2e.constant.CONN_CHECK_IS_CONNECTED -import net.mullvad.mullvadvpn.test.e2e.constant.CONN_CHECK_URL -class WebViewInteractor( - private val context: Context, - private val device: UiDevice -) { - fun launchWebView(context: Context, url: String) { - val intent = Intent(context, TestActivity::class.java).apply { - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - putExtra("url", url) - } - context.startActivity(intent) - } - - fun launchAndExtractConnCheckState(): ConnCheckState { - launchWebView(context, CONN_CHECK_URL) - val webView = device.findObjectWithTimeout(By.clazz(WebView::class.java)) - val stateText = device.findObjectByCaseInsensitiveText("using Mullvad VPN").apply { - click() - } - - // Wait for view to expand after click. - Thread.sleep(1000) - - val wireGuardIpv4ConnectionRow = webView.findObjects(By.clazz(View::class.java)) - .first { it.text?.endsWith("(WireGuard)") == true } - val wireGuardIpv4Address = wireGuardIpv4ConnectionRow.text.split(" ")[0].trim() - return ConnCheckState(stateText.text == CONN_CHECK_IS_CONNECTED, wireGuardIpv4Address) - } - - data class ConnCheckState( - val isConnected: Boolean, - val ipAddress: String - ) -} diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/ConnCheckState.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/ConnCheckState.kt new file mode 100644 index 0000000000..744e80124e --- /dev/null +++ b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/ConnCheckState.kt @@ -0,0 +1,6 @@ +package net.mullvad.mullvadvpn.test.e2e.misc + +data class ConnCheckState( + val isConnected: Boolean, + val ipAddress: String +) diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/SimpleMullvadHttpClient.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/SimpleMullvadHttpClient.kt index b06ecee780..bc56737b04 100644 --- a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/SimpleMullvadHttpClient.kt +++ b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/SimpleMullvadHttpClient.kt @@ -10,6 +10,7 @@ import com.android.volley.toolbox.RequestFuture import com.android.volley.toolbox.StringRequest import com.android.volley.toolbox.Volley import net.mullvad.mullvadvpn.test.e2e.BuildConfig +import net.mullvad.mullvadvpn.test.e2e.constant.CONN_CHECK_URL import net.mullvad.mullvadvpn.test.e2e.constant.LOG_TAG import org.json.JSONArray import org.json.JSONObject @@ -72,6 +73,22 @@ class SimpleMullvadHttpClient(context: Context) { ) } + fun runConnectionCheck(): ConnCheckState? { + return sendSimpleSynchronousRequestString( + Request.Method.GET, + CONN_CHECK_URL + ) + ?.let { respose -> + JSONObject(respose) + } + ?.let { json -> + ConnCheckState( + isConnected = json.getBoolean("mullvad_exit_ip"), + ipAddress = json.getString("ip") + ) + } + } + private fun sendSimpleSynchronousRequest( method: Int, url: String, |
