|
1 | 1 | package net.mullvad.mullvadvpn.test.common.page
|
2 | 2 |
|
3 | 3 | import androidx.test.uiautomator.By
|
| 4 | +import net.mullvad.mullvadvpn.test.common.constant.VERY_LONG_TIMEOUT |
4 | 5 | import net.mullvad.mullvadvpn.test.common.extension.findObjectWithTimeout
|
5 | 6 |
|
6 | 7 | class ConnectPage internal constructor() : Page() {
|
| 8 | + private val disconnectSelector = By.text("Disconnect") |
| 9 | + private val cancelSelector = By.text("Cancel") |
| 10 | + private val connectedSelector = By.text("CONNECTED") |
| 11 | + private val connectingSelector = By.text("CONNECTING...") |
| 12 | + |
7 | 13 | override fun assertIsDisplayed() {
|
8 |
| - uiDevice.findObjectWithTimeout(By.res("connect_card_header_test_tag")) |
| 14 | + uiDevice.findObjectWithTimeout(By.res(CONNECT_CARD_HEADER_TEST_TAG)) |
| 15 | + } |
| 16 | + |
| 17 | + fun clickSelectLocation() { |
| 18 | + uiDevice.findObjectWithTimeout(By.res(SELECT_LOCATION_BUTTON_TEST_TAG)).click() |
| 19 | + } |
| 20 | + |
| 21 | + fun clickConnect() { |
| 22 | + uiDevice.findObjectWithTimeout(By.res(CONNECT_BUTTON_TEST_TAG)).click() |
| 23 | + } |
| 24 | + |
| 25 | + fun clickDisconnect() { |
| 26 | + uiDevice.findObjectWithTimeout(disconnectSelector).click() |
| 27 | + } |
| 28 | + |
| 29 | + fun clickCancel() { |
| 30 | + uiDevice.findObjectWithTimeout(cancelSelector).click() |
| 31 | + } |
| 32 | + |
| 33 | + fun waitForConnectedLabel(timeout: Long = VERY_LONG_TIMEOUT) { |
| 34 | + uiDevice.findObjectWithTimeout(connectedSelector, timeout) |
| 35 | + } |
| 36 | + |
| 37 | + fun waitForConnectingLabel() { |
| 38 | + uiDevice.findObjectWithTimeout(connectingSelector) |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Extracts the in IPv4 address from the connection card. It is a prerequisite that the |
| 43 | + * connection card is in collapsed state. |
| 44 | + */ |
| 45 | + fun extractInIpv4Address(): String { |
| 46 | + uiDevice.findObjectWithTimeout(By.res("connect_card_header_test_tag")).click() |
| 47 | + val inString = |
| 48 | + uiDevice |
| 49 | + .findObjectWithTimeout( |
| 50 | + By.res("location_info_connection_in_test_tag"), |
| 51 | + VERY_LONG_TIMEOUT, |
| 52 | + ) |
| 53 | + .text |
| 54 | + |
| 55 | + val extractedIpAddress = inString.split(" ")[0].split(":")[0] |
| 56 | + return extractedIpAddress |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Extracts the out IPv4 address from the connection card. It is a prerequisite that the |
| 61 | + * connection card is in collapsed state. |
| 62 | + */ |
| 63 | + fun extractOutIpv4Address(): String { |
| 64 | + uiDevice.findObjectWithTimeout(By.res("connect_card_header_test_tag")).click() |
| 65 | + return uiDevice |
| 66 | + .findObjectWithTimeout( |
| 67 | + // Text exist and contains IP address |
| 68 | + By.res("location_info_connection_out_test_tag").textContains("."), |
| 69 | + VERY_LONG_TIMEOUT, |
| 70 | + ) |
| 71 | + .text |
| 72 | + } |
| 73 | + |
| 74 | + companion object { |
| 75 | + const val CONNECT_CARD_HEADER_TEST_TAG = "connect_card_header_test_tag" |
| 76 | + const val SELECT_LOCATION_BUTTON_TEST_TAG = "select_location_button_test_tag" |
| 77 | + const val CONNECT_BUTTON_TEST_TAG = "connect_button_test_tag" |
9 | 78 | }
|
10 | 79 | }
|
0 commit comments