summaryrefslogtreecommitdiff
path: root/app/src/androidTest/java/utils
diff options
context:
space:
mode:
authorcyberta <cyberta@riseup.net>2026-07-03 13:23:32 +0200
committercyberta <cyberta@riseup.net>2026-07-03 17:49:31 +0200
commitbe186e4eda72f14eb3b8f6fab76fbeda9d9fb175 (patch)
tree0a35c05944b7888aecf406bfb721434e8903f318 /app/src/androidTest/java/utils
parent1784fb5e60414808f21f4596959adf7a8b46e675 (diff)
fix and extend instrumentation tests used for automatted screenshots
Diffstat (limited to 'app/src/androidTest/java/utils')
-rw-r--r--app/src/androidTest/java/utils/CustomInteractions.java8
-rw-r--r--app/src/androidTest/java/utils/ProviderSetupUtils.java137
2 files changed, 86 insertions, 59 deletions
diff --git a/app/src/androidTest/java/utils/CustomInteractions.java b/app/src/androidTest/java/utils/CustomInteractions.java
index 4890c20c..35f8b48f 100644
--- a/app/src/androidTest/java/utils/CustomInteractions.java
+++ b/app/src/androidTest/java/utils/CustomInteractions.java
@@ -18,7 +18,11 @@ public class CustomInteractions {
return tryResolve(viewInteraction, assertion, 10);
}
- public static @Nullable ViewInteraction tryResolve(ViewInteraction viewInteraction, ViewAssertion assertion, int maxTries) {
+ public static @Nullable ViewInteraction tryResolve(ViewInteraction viewInteraction, ViewAssertion assertion, int maxTries) {
+ return tryResolve(viewInteraction, assertion, maxTries, "");
+ }
+
+ public static @Nullable ViewInteraction tryResolve(ViewInteraction viewInteraction, ViewAssertion assertion, int maxTries, String message) {
ViewInteraction resolvedViewInteraction = null;
int attempt = 0;
boolean hasFound = false;
@@ -30,7 +34,7 @@ public class CustomInteractions {
}
hasFound = true;
} catch (NoMatchingViewException exception) {
- System.out.println("NoMatchingViewException - attempt: " + attempt + ". " + exception.getLocalizedMessage());
+ System.out.println("NoMatchingViewException " + message +" - attempt: " + attempt + ". " + exception.getLocalizedMessage());
attempt++;
if (attempt == maxTries) {
throw exception;
diff --git a/app/src/androidTest/java/utils/ProviderSetupUtils.java b/app/src/androidTest/java/utils/ProviderSetupUtils.java
index 9b76ffbd..f72d8a50 100644
--- a/app/src/androidTest/java/utils/ProviderSetupUtils.java
+++ b/app/src/androidTest/java/utils/ProviderSetupUtils.java
@@ -12,10 +12,11 @@ import static utils.CustomInteractions.tryResolve;
import android.content.Context;
import android.net.VpnService;
+import android.os.Bundle;
import androidx.test.espresso.NoMatchingViewException;
import androidx.test.espresso.ViewInteraction;
-import androidx.test.espresso.matcher.ViewMatchers;
+import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject;
import androidx.test.uiautomator.UiObjectNotFoundException;
@@ -31,62 +32,11 @@ public class ProviderSetupUtils {
public static void runProviderSetup(UiDevice device, boolean takeConfigurationScreenshots, boolean useCircumvention, Context targetContext) {
try {
- // ------- PROVIDER SELECTION --------------
- if ("normal".equals(BuildConfig.FLAVOR_branding)) {
- System.out.println("next: provider selection");
- ViewInteraction radioButtonSelection = tryResolve(onView(withText("Riseup")), matches(isDisplayed()));
- if (takeConfigurationScreenshots) Screengrab.screenshot("provider_selection");
- radioButtonSelection.perform(click());
- // next button click
- onView(withText(R.string.next)).perform(click());
- }
-
- // ------- CIRCUMVENTION SELECTION --------------
- System.out.println("next: standard/circumvention selection");
- if (useCircumvention) {
- onView(withText(targetContext.getString(R.string.use_circumvention_tech))).perform(click());
- } else {
- onView(withText(targetContext.getString(R.string.use_standard_vpn, targetContext.getString(R.string.app_name)))).perform(click());
- }
- if (takeConfigurationScreenshots) Screengrab.screenshot("circumvention_selection");
-
- // ------- CONFIGURATION PROGRESS --------------
- System.out.println("next: configuring");
- onView(withText(R.string.next)).perform(click());
- tryResolve(
- onView(
- Matchers.allOf(
- withText(R.string.configuring_provider),
- withId(R.id.tv_title)
- )
- ),
- matches(isDisplayed())
- );
- if (takeConfigurationScreenshots) Screengrab.screenshot("configuring_provider");
-
- // ------- VPN PERMISSON DIALOG --------------
- boolean showPermissionDialog = false;
- if (VpnService.prepare(getApplicationContext()) != null) {
- showPermissionDialog = true;
- tryResolve(onView(withText(R.string.upcoming_connection_request_description)), matches(isDisplayed()), useCircumvention ? 180 : 20);
- System.out.println("next: next permission request");
- if (takeConfigurationScreenshots) Screengrab.screenshot("vpn_permission_rationale");
- onView(withText(R.string.next)).perform(click());
- UiObject okButton = device.findObject(new UiSelector().packageName("com.android.vpndialogs").resourceId("android:id/button1"));
- okButton.waitForExists(30000);
- okButton.click();
- device.waitForWindowUpdate("com.android.vpndialogs", 1000);
- }
-
- // ------- START VPN --------------
- System.out.println("next: perform click on VPN button");
- ViewInteraction interaction = tryResolve(onView(withTagValue(Matchers.is("button_setup_circle_custom"))), matches(isDisplayed()), useCircumvention && !showPermissionDialog ? 180 : 20);
- if (takeConfigurationScreenshots) {
- Screengrab.screenshot("all_set_start_vpn");
- } else {
- // we only want to start the VPN in case we're not running the ProviderSetupTest
- interaction.perform(click());
- }
+ runProviderSelection(takeConfigurationScreenshots);
+ runCircumventionSelection(takeConfigurationScreenshots, useCircumvention, true, targetContext);
+ boolean showPermissionDialog = runVPNPermissionApproval(device, takeConfigurationScreenshots, useCircumvention);
+ runConfiguration(takeConfigurationScreenshots);
+ runStartVPN(takeConfigurationScreenshots, useCircumvention, showPermissionDialog);
} catch (NoMatchingViewException e) {
// it might be that the provider was already configured, so we print the stack
// trace here and try to continue
@@ -95,4 +45,77 @@ public class ProviderSetupUtils {
e.printStackTrace();
}
}
+
+ public static void runStartVPN(boolean takeConfigurationScreenshots, boolean useCircumvention, boolean showPermissionDialog) {
+ // ------- START VPN --------------
+ System.out.println("next: perform click on VPN button");
+ ViewInteraction interaction = tryResolve(onView(withTagValue(Matchers.is("button_setup_circle_custom"))), matches(isDisplayed()), useCircumvention && !showPermissionDialog ? 180 : 20);
+ if (takeConfigurationScreenshots) {
+ Screengrab.screenshot("all_set_start_vpn");
+ } else {
+ // we only want to start the VPN in case we're not running the ProviderSetupTest
+ interaction.perform(click());
+ }
+ }
+
+ public static boolean runVPNPermissionApproval(UiDevice device, boolean takeConfigurationScreenshots, boolean useCircumvention) throws UiObjectNotFoundException {
+ // ------- VPN PERMISSON DIALOG --------------
+ if (VpnService.prepare(getApplicationContext()) != null) {
+ tryResolve(onView(withId(R.id.tv_title)), matches(withText(R.string.title_upcoming_connection_request)));
+ Screengrab.screenshot("permissions_screen");
+ onView(withId(R.id.setup_next_button)).perform(click());
+
+ UiObject okButton = device.findObject(new UiSelector().packageName("com.android.vpndialogs").resourceId("android:id/button1"));
+ okButton.waitForExists(30000);
+ okButton.click();
+ device.waitForWindowUpdate("com.android.vpndialogs", 1000);
+ return true;
+ }
+ return false;
+ }
+
+ public static void runConfiguration(boolean takeConfigurationScreenshots) {
+ // ------- CONFIGURATION PROGRESS --------------
+ System.out.println("next: configuring");
+ tryResolve(
+ onView(
+ Matchers.allOf(
+ withText(R.string.configuring_provider),
+ withId(R.id.tv_title)
+ )
+ ),
+ matches(isDisplayed())
+ );
+ if (takeConfigurationScreenshots) Screengrab.screenshot("configuring_provider");
+ }
+
+ public static void runCircumventionSelection(boolean takeConfigurationScreenshots, boolean useCircumvention, boolean clickNext, Context targetContext) {
+ // ------- CIRCUMVENTION SELECTION --------------
+ if (useCircumvention) {
+ onView(withText(targetContext.getString(R.string.use_circumvention_tech))).perform(click());
+ } else {
+ onView(withText(targetContext.getString(R.string.use_standard_vpn, targetContext.getString(R.string.app_name)))).perform(click());
+ }
+ if (takeConfigurationScreenshots) Screengrab.screenshot("041_circumvention_selection");
+ if (clickNext) onView(withText(R.string.next)).perform(click());
+ }
+
+
+ public static void runProviderSelection(boolean takeConfigurationScreenshots) {
+ // ------- PROVIDER SELECTION --------------
+ if ("normal".equals(BuildConfig.FLAVOR_branding)) {
+ System.out.println("next: provider selection");
+ ViewInteraction radioButtonSelection = tryResolve(onView(withText("CoopVPN Beta")), matches(isDisplayed()));
+ radioButtonSelection.perform(click());
+ if (takeConfigurationScreenshots) Screengrab.screenshot("040_provider_selection");
+ // next button click
+ onView(withText(R.string.next)).perform(click());
+ }
+ }
+
+ public static boolean isVerboseScreenshots() {
+ Bundle arguments = InstrumentationRegistry.getArguments();
+ String verbose = arguments.getString("verbose_screenshots", "false");
+ return "true".equalsIgnoreCase(verbose);
+ }
}