diff options
| author | Niklas Berglund <niklas.berglund@gmail.com> | 2024-08-26 17:05:00 +0200 |
|---|---|---|
| committer | David Göransson <david.goransson@mullvad.net> | 2024-10-15 14:47:12 +0200 |
| commit | 74cfcf0546724c1c7ee82597ea28ccd7801fc74d (patch) | |
| tree | b88a5b8fc4212d5f3968b55d2159fe785ac14f44 /android/test/common | |
| parent | 14be3654e0c77fea3741312acc6ac7da126e18bd (diff) | |
| download | mullvadvpn-74cfcf0546724c1c7ee82597ea28ccd7801fc74d.tar.xz mullvadvpn-74cfcf0546724c1c7ee82597ea28ccd7801fc74d.zip | |
Add minimal leak tests for Android
Diffstat (limited to 'android/test/common')
2 files changed, 48 insertions, 0 deletions
diff --git a/android/test/common/src/main/kotlin/net/mullvad/mullvadvpn/test/common/interactor/AppInteractor.kt b/android/test/common/src/main/kotlin/net/mullvad/mullvadvpn/test/common/interactor/AppInteractor.kt index b18a10d504..34690022c9 100644 --- a/android/test/common/src/main/kotlin/net/mullvad/mullvadvpn/test/common/interactor/AppInteractor.kt +++ b/android/test/common/src/main/kotlin/net/mullvad/mullvadvpn/test/common/interactor/AppInteractor.kt @@ -95,6 +95,20 @@ class AppInteractor( .text } + fun extractInIpv4Address(): String { + device.findObjectWithTimeout(By.res("location_info_test_tag")).click() + val inString = + device + .findObjectWithTimeout( + By.res("location_info_connection_in_test_tag"), + VERY_LONG_TIMEOUT, + ) + .text + + val extractedIpAddress = inString.split(" ")[1].split(":")[0] + return extractedIpAddress + } + fun clickSettingsCog() { device.findObjectWithTimeout(By.res("top_bar_settings_button")).click() } diff --git a/android/test/common/src/main/kotlin/net/mullvad/mullvadvpn/test/common/misc/Attachment.kt b/android/test/common/src/main/kotlin/net/mullvad/mullvadvpn/test/common/misc/Attachment.kt new file mode 100644 index 0000000000..57e6ab542b --- /dev/null +++ b/android/test/common/src/main/kotlin/net/mullvad/mullvadvpn/test/common/misc/Attachment.kt @@ -0,0 +1,34 @@ +package net.mullvad.mullvadvpn.test.common.misc + +import android.os.Environment +import co.touchlab.kermit.Logger +import java.io.File +import java.io.IOException +import org.junit.jupiter.api.fail + +object Attachment { + private const val DIRECTORY_NAME = "test-attachments" + private val testAttachmentsDirectory = + File( + Environment.getExternalStorageDirectory(), + "${Environment.DIRECTORY_DOWNLOADS}/$DIRECTORY_NAME", + ) + + fun saveAttachment(fileName: String, data: ByteArray) { + createAttachmentsDirectoryIfNotExists() + + val file = File(testAttachmentsDirectory, fileName) + try { + file.writeBytes(data) + Logger.v("Saved attachment ${file.absolutePath}") + } catch (e: IOException) { + fail("Failed to save attachment $fileName: ${e.message}") + } + } + + private fun createAttachmentsDirectoryIfNotExists() { + if (!testAttachmentsDirectory.exists() && !testAttachmentsDirectory.mkdirs()) { + fail("Failed to create directory ${testAttachmentsDirectory.absolutePath}") + } + } +} |
