Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Testing for NewsMediaScan #236

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/instrumented-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@ name: Android Instrumented Tests
on:
push:
branches:
- main
- master
workflow_dispatch:

jobs:
instrumentation-tests:
name: Run Android Instrumented Tests
runs-on: macos-latest

strategy:
matrix:
organization: [ ooni, dw ]

steps:
- uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup

- name: Build APKs
run: ./gradlew copyBrandingToCommonResources assembleFullDebug assembleFullDebugAndroidTest
run: ./gradlew copyBrandingToCommonResources assembleFullDebug assembleFullDebugAndroidTest -Porganization=${{ matrix.organization }}

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ import androidx.compose.ui.test.swipeDown
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runTest
import ooniprobe.composeapp.generated.resources.AddDescriptor_Action
import ooniprobe.composeapp.generated.resources.AddDescriptor_AutoUpdate
import ooniprobe.composeapp.generated.resources.AddDescriptor_Title
import ooniprobe.composeapp.generated.resources.Dashboard_Progress_ReviewLink_Action
import ooniprobe.composeapp.generated.resources.Dashboard_ReviewDescriptor_Button_Last
import ooniprobe.composeapp.generated.resources.Dashboard_Runv2_Overview_UninstallLink
import ooniprobe.composeapp.generated.resources.Res
import org.jetbrains.compose.resources.getString
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Before
Expand All @@ -30,6 +38,9 @@ import org.ooni.probe.MainActivity
import org.ooni.probe.uitesting.helpers.clickOnText
import org.ooni.probe.uitesting.helpers.context
import org.ooni.probe.uitesting.helpers.dependencies
import org.ooni.probe.uitesting.helpers.isNewsMediaScan
import org.ooni.probe.uitesting.helpers.onAllNodesWithText
import org.ooni.probe.uitesting.helpers.onNodeWithText
import org.ooni.probe.uitesting.helpers.preferences
import org.ooni.probe.uitesting.helpers.skipOnboarding
import org.ooni.probe.uitesting.helpers.start
Expand All @@ -50,6 +61,8 @@ class DescriptorsTest {
@Test
fun installAndUninstall() {
runTest {
if (isNewsMediaScan) return@runTest

start(
Intent(context, MainActivity::class.java)
.setAction(Intent.ACTION_VIEW)
Expand All @@ -58,7 +71,7 @@ class DescriptorsTest {

with(compose) {
wait(DESCRIPTOR_DOWNLOAD_WAIT_TIMEOUT) {
onNodeWithText("Install New Link").isDisplayed()
onNodeWithText(Res.string.AddDescriptor_Title).isDisplayed()
}

onNodeWithText("Testing").assertIsDisplayed()
Expand All @@ -81,9 +94,10 @@ class DescriptorsTest {
assertTrue(preferences.isNetTestEnabled(descriptor, test, isAutoRun = true).first())

clickOnText("Android instrumented tests")
clickOnText("Uninstall Link")
clickOnText(Res.string.Dashboard_Runv2_Overview_UninstallLink)

compose.onAllNodesWithText("Uninstall Link").onLast().performClick()
onAllNodesWithText(Res.string.Dashboard_Runv2_Overview_UninstallLink).onLast()
.performClick()

onNodeWithText("Testing").assertIsNotDisplayed()
}
Expand All @@ -93,6 +107,8 @@ class DescriptorsTest {
@Test
fun installAndUpdate() =
runTest {
if (isNewsMediaScan) return@runTest

start(
Intent(context, MainActivity::class.java)
.setAction(Intent.ACTION_VIEW)
Expand All @@ -101,10 +117,10 @@ class DescriptorsTest {

with(compose) {
wait(DESCRIPTOR_DOWNLOAD_WAIT_TIMEOUT) {
onNodeWithText("Install New Link").isDisplayed()
onNodeWithText(Res.string.AddDescriptor_Title).isDisplayed()
}
clickOnText("Install updates automatically")
clickOnText("Install Link")
clickOnText(Res.string.AddDescriptor_AutoUpdate)
clickOnText(Res.string.AddDescriptor_Action)

Thread.sleep(2000)

Expand All @@ -114,15 +130,14 @@ class DescriptorsTest {
// Pull down to refresh
onNodeWithTag("Dashboard-List").performTouchInput { swipeDown() }

wait(DESCRIPTOR_DOWNLOAD_WAIT_TIMEOUT) {
onNodeWithText("Review").isDisplayed()
}

clickOnText("Review")
clickOnText(
Res.string.Dashboard_Progress_ReviewLink_Action,
timeout = DESCRIPTOR_DOWNLOAD_WAIT_TIMEOUT,
)

wait { onNodeWithText("Testing 2").isDisplayed() }

clickOnText("UPDATE AND FINISH (1 of 1)")
clickOnText(getString(Res.string.Dashboard_ReviewDescriptor_Button_Last, 1, 1))

onNodeWithTag("Dashboard-List")
.performScrollToNode(hasText("Android instrumented tests"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ package org.ooni.probe.uitesting

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 ooniprobe.composeapp.generated.resources.Modal_EnableNotifications_Title
import ooniprobe.composeapp.generated.resources.Onboarding_AutomatedTesting_Title
import ooniprobe.composeapp.generated.resources.Onboarding_Crash_Title
import ooniprobe.composeapp.generated.resources.Onboarding_DefaultSettings_Button_Go
import ooniprobe.composeapp.generated.resources.Onboarding_DefaultSettings_Title
import ooniprobe.composeapp.generated.resources.Onboarding_PopQuiz_True
import ooniprobe.composeapp.generated.resources.Onboarding_ThingsToKnow_Button
import ooniprobe.composeapp.generated.resources.Onboarding_ThingsToKnow_Title
import ooniprobe.composeapp.generated.resources.Onboarding_WhatIsOONIProbe_GotIt
import ooniprobe.composeapp.generated.resources.Onboarding_WhatIsOONIProbe_Title
import ooniprobe.composeapp.generated.resources.Res
import ooniprobe.composeapp.generated.resources.app_name
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
Expand All @@ -16,6 +26,8 @@ import org.ooni.probe.data.models.SettingsKey
import org.ooni.probe.uitesting.helpers.clickOnTag
import org.ooni.probe.uitesting.helpers.clickOnText
import org.ooni.probe.uitesting.helpers.dependencies
import org.ooni.probe.uitesting.helpers.onNodeWithContentDescription
import org.ooni.probe.uitesting.helpers.onNodeWithText
import org.ooni.probe.uitesting.helpers.preferences
import org.ooni.probe.uitesting.helpers.start
import org.ooni.probe.uitesting.helpers.wait
Expand All @@ -35,31 +47,39 @@ class OnboardingTest {
fun onboarding() =
runTest {
with(compose) {
wait { onNodeWithText("What is OONI Probe?").isDisplayed() }
clickOnText("Got It")
wait {
onNodeWithText(Res.string.Onboarding_WhatIsOONIProbe_Title)
.isDisplayed()
}
clickOnText(Res.string.Onboarding_WhatIsOONIProbe_GotIt)

wait { onNodeWithText("Heads-up!").isDisplayed() }
clickOnText("I understand")
wait {
onNodeWithText(Res.string.Onboarding_ThingsToKnow_Title)
.isDisplayed()
}
clickOnText(Res.string.Onboarding_ThingsToKnow_Button)

// Quiz
clickOnText("True")
clickOnText("True")
clickOnText(Res.string.Onboarding_PopQuiz_True)
clickOnText(Res.string.Onboarding_PopQuiz_True)

wait { onNodeWithText("Automated testing").isDisplayed() }
wait { onNodeWithText(Res.string.Onboarding_AutomatedTesting_Title).isDisplayed() }
clickOnTag("No-AutoTest")

wait { onNodeWithText("Crash Reporting").isDisplayed() }
wait { onNodeWithText(Res.string.Onboarding_Crash_Title).isDisplayed() }
clickOnTag("Yes-CrashReporting")

if (dependencies.platformInfo.needsToRequestNotificationsPermission) {
wait { onNodeWithText("Get updates on internet censorship").isDisplayed() }
wait {
onNodeWithText(Res.string.Modal_EnableNotifications_Title).isDisplayed()
}
clickOnTag("No-Notifications")
}

wait { onNodeWithText("Default Settings").isDisplayed() }
clickOnText("Let’s go")
wait { onNodeWithText(Res.string.Onboarding_DefaultSettings_Title).isDisplayed() }
clickOnText(Res.string.Onboarding_DefaultSettings_Button_Go)

wait { onNodeWithContentDescription("OONI Probe").isDisplayed() }
wait { onNodeWithContentDescription(Res.string.app_name).isDisplayed() }
}

assertEquals(
Expand Down
Loading