-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android UI instrumented tests (#150)
- Loading branch information
Showing
23 changed files
with
781 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Android Instrumented Tests | ||
on: workflow_dispatch | ||
|
||
jobs: | ||
android-instrumented-tests: | ||
name: Android Instrumented Tests | ||
runs-on: macos-13 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup | ||
uses: ./.github/actions/setup | ||
|
||
- name: Run tests | ||
uses: reactivecircus/android-emulator-runner@v2 | ||
with: | ||
api-level: 29 | ||
arch: x86_64 | ||
script: ./gradlew copyBrandingToCommonResources connectedDebugAndroidTest | ||
|
||
- name: Uploads test reports | ||
uses: actions/upload-artifact@v4 | ||
if: failure() | ||
with: | ||
name: android-instrumented-tests-report | ||
path: composeApp/build/reports/androidTests/connected/debug/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/test/OnboardingTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.ooni.probe.test | ||
|
||
import androidx.compose.ui.test.isDisplayed | ||
import androidx.compose.ui.test.junit4.createEmptyComposeRule | ||
import androidx.compose.ui.test.onNodeWithContentDescription | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.ooni.probe.data.models.SettingsKey | ||
import org.ooni.probe.test.helpers.CleanTestRule | ||
import org.ooni.probe.test.helpers.FlakyTestRule | ||
import org.ooni.probe.test.helpers.clickOnTag | ||
import org.ooni.probe.test.helpers.clickOnText | ||
import org.ooni.probe.test.helpers.dependencies | ||
import org.ooni.probe.test.helpers.preferences | ||
import org.ooni.probe.test.helpers.start | ||
import org.ooni.probe.test.helpers.wait | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class OnboardingTest { | ||
@get:Rule | ||
val clean = CleanTestRule() | ||
|
||
@get:Rule | ||
val flakyTestRule = FlakyTestRule() | ||
|
||
@get:Rule | ||
val compose = createEmptyComposeRule() | ||
|
||
@Before | ||
fun setUp() { | ||
start() | ||
} | ||
|
||
@Test | ||
fun onboarding() = | ||
runTest { | ||
with(compose) { | ||
wait { onNodeWithText("What is OONI Probe?").isDisplayed() } | ||
clickOnText("Got It") | ||
|
||
wait { onNodeWithText("Heads-up!").isDisplayed() } | ||
clickOnText("I understand") | ||
|
||
// Quiz | ||
clickOnText("True") | ||
clickOnText("True") | ||
|
||
wait { onNodeWithText("Automated testing").isDisplayed() } | ||
clickOnTag("Yes-AutoTest") | ||
|
||
wait { onNodeWithText("Crash Reporting").isDisplayed() } | ||
clickOnTag("Yes-CrashReporting") | ||
|
||
if (dependencies.platformInfo.needsToRequestNotificationsPermission) { | ||
wait { onNodeWithText("Get updates on internet censorship").isDisplayed() } | ||
clickOnTag("No-Notifications") | ||
} | ||
|
||
wait { onNodeWithText("Default Settings").isDisplayed() } | ||
clickOnText("Let’s go") | ||
|
||
wait { onNodeWithContentDescription("OONI Probe").isDisplayed() } | ||
} | ||
|
||
assertEquals( | ||
true, | ||
preferences.getValueByKey(SettingsKey.AUTOMATED_TESTING_ENABLED).first(), | ||
) | ||
assertEquals(true, preferences.getValueByKey(SettingsKey.SEND_CRASH).first()) | ||
} | ||
} |
143 changes: 143 additions & 0 deletions
143
composeApp/src/androidInstrumentedTest/kotlin/org/ooni/probe/test/RunningTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package org.ooni.probe.test | ||
|
||
import androidx.compose.ui.test.hasText | ||
import androidx.compose.ui.test.isDisplayed | ||
import androidx.compose.ui.test.junit4.createEmptyComposeRule | ||
import androidx.compose.ui.test.onAllNodesWithText | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performClick | ||
import androidx.compose.ui.test.performScrollToNode | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.ooni.probe.data.models.SettingsKey | ||
import org.ooni.probe.test.helpers.CleanTestRule | ||
import org.ooni.probe.test.helpers.FlakyTestRule | ||
import org.ooni.probe.test.helpers.checkLinkInsideWebView | ||
import org.ooni.probe.test.helpers.checkSummaryInsideWebView | ||
import org.ooni.probe.test.helpers.clickOnText | ||
import org.ooni.probe.test.helpers.preferences | ||
import org.ooni.probe.test.helpers.skipOnboarding | ||
import org.ooni.probe.test.helpers.start | ||
import org.ooni.probe.test.helpers.wait | ||
import kotlin.time.Duration.Companion.minutes | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class RunningTest { | ||
@get:Rule | ||
val clean = CleanTestRule() | ||
|
||
@get:Rule | ||
val flakyTestRule = FlakyTestRule() | ||
|
||
@get:Rule | ||
val compose = createEmptyComposeRule() | ||
|
||
@Before | ||
fun setUp() = | ||
runTest { | ||
skipOnboarding() | ||
preferences.setValueByKey(SettingsKey.UPLOAD_RESULTS, true) | ||
start() | ||
} | ||
|
||
@Test | ||
fun signal() = | ||
runTest { | ||
with(compose) { | ||
clickOnText("Run") | ||
|
||
clickOnText("Deselect all tests") | ||
clickOnText("Signal Test") | ||
clickOnText("Run 1 test") | ||
|
||
wait(TEST_WAIT_TIMEOUT) { | ||
onNodeWithText("Run finished. Tap to view results.").isDisplayed() | ||
} | ||
clickOnText("Run finished. Tap to view results.") | ||
|
||
clickOnText("Instant Messaging") | ||
clickOnText("Signal Test") | ||
wait { onNodeWithText("Measurement").isDisplayed() } | ||
checkSummaryInsideWebView("Signal") | ||
} | ||
} | ||
|
||
@Test | ||
fun psiphon() = | ||
runTest { | ||
with(compose) { | ||
clickOnText("Run") | ||
|
||
clickOnText("Deselect all tests") | ||
clickOnText("Psiphon Test") | ||
clickOnText("Run 1 test") | ||
|
||
wait(TEST_WAIT_TIMEOUT) { | ||
onNodeWithText("Run finished. Tap to view results.").isDisplayed() | ||
} | ||
clickOnText("Run finished. Tap to view results.") | ||
|
||
clickOnText("Circumvention") | ||
clickOnText("Psiphon Test") | ||
wait { onNodeWithText("Measurement").isDisplayed() } | ||
checkSummaryInsideWebView("Psiphon") | ||
} | ||
} | ||
|
||
@Test | ||
fun httpHeader() = | ||
runTest { | ||
with(compose) { | ||
clickOnText("Run") | ||
|
||
clickOnText("Deselect all tests") | ||
onNodeWithTag("Run-DescriptorsList") | ||
.performScrollToNode(hasText("HTTP Header", substring = true)) | ||
clickOnText("HTTP Header", substring = true) | ||
clickOnText("Run 1 test") | ||
|
||
wait(TEST_WAIT_TIMEOUT) { | ||
onNodeWithText("Run finished. Tap to view results.").isDisplayed() | ||
} | ||
clickOnText("Run finished. Tap to view results.") | ||
|
||
clickOnText("Performance") | ||
clickOnText("HTTP Header", substring = true) | ||
wait { onNodeWithText("Measurement").isDisplayed() } | ||
checkSummaryInsideWebView("middleboxes") | ||
} | ||
} | ||
|
||
@Test | ||
fun stunReachability() = | ||
runTest { | ||
with(compose) { | ||
clickOnText("Run") | ||
|
||
clickOnText("Deselect all tests") | ||
onNodeWithTag("Run-DescriptorsList") | ||
.performScrollToNode(hasText("stunreachability")) | ||
clickOnText("stunreachability", substring = true) | ||
clickOnText("Run 1 test") | ||
|
||
wait(TEST_WAIT_TIMEOUT) { | ||
onNodeWithText("Run finished. Tap to view results.").isDisplayed() | ||
} | ||
clickOnText("Run finished. Tap to view results.") | ||
|
||
clickOnText("Experimental") | ||
compose.onAllNodesWithText("stunreachability")[0].performClick() | ||
wait { onNodeWithText("Measurement").isDisplayed() } | ||
checkLinkInsideWebView("https://ooni.org/nettest/http-requests/", "STUN Reachability") | ||
} | ||
} | ||
|
||
companion object { | ||
private val TEST_WAIT_TIMEOUT = 1.minutes | ||
} | ||
} |
Oops, something went wrong.