From e201e92acf17e3a71e2bffb73419fdd3726b0569 Mon Sep 17 00:00:00 2001 From: cyberta Date: Mon, 2 Jan 2023 21:08:29 +0100 Subject: simple example setup for fastlane, doing some screenshots in different languages, including screenshots with phone frames for use in an app store --- .../androidTest/java/base/ProviderSetupTest.java | 68 ++++++++++++++++++++++ app/src/debug/AndroidManifest.xml | 43 ++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 app/src/androidTest/java/base/ProviderSetupTest.java create mode 100644 app/src/debug/AndroidManifest.xml (limited to 'app/src') diff --git a/app/src/androidTest/java/base/ProviderSetupTest.java b/app/src/androidTest/java/base/ProviderSetupTest.java new file mode 100644 index 00000000..fd46a093 --- /dev/null +++ b/app/src/androidTest/java/base/ProviderSetupTest.java @@ -0,0 +1,68 @@ +package base; + + +import static android.content.Context.MODE_PRIVATE; +import static androidx.test.core.app.ApplicationProvider.getApplicationContext; +import static androidx.test.espresso.Espresso.onData; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static org.hamcrest.Matchers.anything; + +import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; + +import android.content.SharedPreferences; + +import androidx.test.ext.junit.rules.ActivityScenarioRule; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; + +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Locale; + +import se.leap.bitmaskclient.R; +import se.leap.bitmaskclient.base.StartActivity; +import se.leap.bitmaskclient.base.utils.PreferenceHelper; +import se.leap.bitmaskclient.providersetup.ProviderListActivity; +import se.leap.bitmaskclient.providersetup.activities.ProviderSetupBaseActivity; +import se.leap.bitmaskclient.testutils.ForceLocaleRule; +import tools.fastlane.screengrab.Screengrab; +import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy; +import tools.fastlane.screengrab.locale.LocaleTestRule; + +@LargeTest +@RunWith(AndroidJUnit4.class) +public class ProviderSetupTest { + + @ClassRule + public static final LocaleTestRule localeTestRule = new LocaleTestRule(); + + @Rule + public ActivityScenarioRule mActivityScenarioRule = + new ActivityScenarioRule<>(ProviderListActivity.class); + + @Before + public void setup() { + Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy()); + SharedPreferences preferences = getApplicationContext().getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); + preferences.edit().clear().commit(); + } + + @Test + public void testConfigureRiseupVPNScreenshot() { + Screengrab.screenshot("configureRiseupVPN_before_button_click"); + onData(anything()).inAdapterView(withId(R.id.provider_list)).atPosition(2).perform(click()); + Screengrab.screenshot("configureRiseupVPN_after_button_click"); + } + + @Test + public void testaddManuallyNewProviderScreenshot() { + Screengrab.screenshot("addManuallyNewProvider_before_button_click"); + onData(anything()).inAdapterView(withId(R.id.provider_list)).atPosition(3).perform(click()); + Screengrab.screenshot("addManuallyNewProvider_after_button_click"); + } +} diff --git a/app/src/debug/AndroidManifest.xml b/app/src/debug/AndroidManifest.xml new file mode 100644 index 00000000..51e17015 --- /dev/null +++ b/app/src/debug/AndroidManifest.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3 From b0f96ee9ca2c612836f1a59222b1148b763fbedd Mon Sep 17 00:00:00 2001 From: cyberta Date: Mon, 2 Jan 2023 21:55:17 +0100 Subject: remove unused imports --- app/src/androidTest/java/base/ProviderSetupTest.java | 7 ------- 1 file changed, 7 deletions(-) (limited to 'app/src') diff --git a/app/src/androidTest/java/base/ProviderSetupTest.java b/app/src/androidTest/java/base/ProviderSetupTest.java index fd46a093..d5a363aa 100644 --- a/app/src/androidTest/java/base/ProviderSetupTest.java +++ b/app/src/androidTest/java/base/ProviderSetupTest.java @@ -7,7 +7,6 @@ import static androidx.test.espresso.Espresso.onData; import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static org.hamcrest.Matchers.anything; - import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; import android.content.SharedPreferences; @@ -22,14 +21,8 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import java.util.Locale; - import se.leap.bitmaskclient.R; -import se.leap.bitmaskclient.base.StartActivity; -import se.leap.bitmaskclient.base.utils.PreferenceHelper; import se.leap.bitmaskclient.providersetup.ProviderListActivity; -import se.leap.bitmaskclient.providersetup.activities.ProviderSetupBaseActivity; -import se.leap.bitmaskclient.testutils.ForceLocaleRule; import tools.fastlane.screengrab.Screengrab; import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy; import tools.fastlane.screengrab.locale.LocaleTestRule; -- cgit v1.2.3 From 108b886f43feeb861807deddfcb1ab241330e242 Mon Sep 17 00:00:00 2001 From: cyberta Date: Thu, 19 Jan 2023 18:47:14 +0100 Subject: improve screenshot tests, run in different languages, test more Fragments/Activities --- .../androidTest/java/base/ProviderSetupTest.java | 61 ------- .../leap/bitmaskclient/base/ProviderSetupTest.java | 68 ++++++++ .../se/leap/bitmaskclient/base/VpnStartTest.java | 176 +++++++++++++++++++++ .../leap/bitmaskclient/suite/ScreenshotTest.java | 19 +++ .../androidTest/java/utils/CustomInteractions.java | 81 ++++++++++ app/src/androidTest/java/utils/CustomMatchers.java | 31 ++++ .../androidTest/java/utils/CustomViewActions.java | 89 +++++++++++ .../leap/bitmaskclient/base/views/MainButton.java | 2 + .../testutils/TestSetupHelper.java | 108 ------------- .../bitmaskclient/testutils/TestSetupHelper.java | 108 +++++++++++++ 10 files changed, 574 insertions(+), 169 deletions(-) delete mode 100644 app/src/androidTest/java/base/ProviderSetupTest.java create mode 100644 app/src/androidTest/java/se/leap/bitmaskclient/base/ProviderSetupTest.java create mode 100644 app/src/androidTest/java/se/leap/bitmaskclient/base/VpnStartTest.java create mode 100644 app/src/androidTest/java/se/leap/bitmaskclient/suite/ScreenshotTest.java create mode 100644 app/src/androidTest/java/utils/CustomInteractions.java create mode 100644 app/src/androidTest/java/utils/CustomMatchers.java create mode 100644 app/src/androidTest/java/utils/CustomViewActions.java delete mode 100644 app/src/sharedTest/java/se.leap.bitmaskclient/testutils/TestSetupHelper.java create mode 100644 app/src/test/java/se/leap/bitmaskclient/testutils/TestSetupHelper.java (limited to 'app/src') diff --git a/app/src/androidTest/java/base/ProviderSetupTest.java b/app/src/androidTest/java/base/ProviderSetupTest.java deleted file mode 100644 index d5a363aa..00000000 --- a/app/src/androidTest/java/base/ProviderSetupTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package base; - - -import static android.content.Context.MODE_PRIVATE; -import static androidx.test.core.app.ApplicationProvider.getApplicationContext; -import static androidx.test.espresso.Espresso.onData; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static org.hamcrest.Matchers.anything; -import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; - -import android.content.SharedPreferences; - -import androidx.test.ext.junit.rules.ActivityScenarioRule; -import androidx.test.ext.junit.runners.AndroidJUnit4; -import androidx.test.filters.LargeTest; - -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import se.leap.bitmaskclient.R; -import se.leap.bitmaskclient.providersetup.ProviderListActivity; -import tools.fastlane.screengrab.Screengrab; -import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy; -import tools.fastlane.screengrab.locale.LocaleTestRule; - -@LargeTest -@RunWith(AndroidJUnit4.class) -public class ProviderSetupTest { - - @ClassRule - public static final LocaleTestRule localeTestRule = new LocaleTestRule(); - - @Rule - public ActivityScenarioRule mActivityScenarioRule = - new ActivityScenarioRule<>(ProviderListActivity.class); - - @Before - public void setup() { - Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy()); - SharedPreferences preferences = getApplicationContext().getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); - preferences.edit().clear().commit(); - } - - @Test - public void testConfigureRiseupVPNScreenshot() { - Screengrab.screenshot("configureRiseupVPN_before_button_click"); - onData(anything()).inAdapterView(withId(R.id.provider_list)).atPosition(2).perform(click()); - Screengrab.screenshot("configureRiseupVPN_after_button_click"); - } - - @Test - public void testaddManuallyNewProviderScreenshot() { - Screengrab.screenshot("addManuallyNewProvider_before_button_click"); - onData(anything()).inAdapterView(withId(R.id.provider_list)).atPosition(3).perform(click()); - Screengrab.screenshot("addManuallyNewProvider_after_button_click"); - } -} diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/base/ProviderSetupTest.java b/app/src/androidTest/java/se/leap/bitmaskclient/base/ProviderSetupTest.java new file mode 100644 index 00000000..23db8582 --- /dev/null +++ b/app/src/androidTest/java/se/leap/bitmaskclient/base/ProviderSetupTest.java @@ -0,0 +1,68 @@ +package se.leap.bitmaskclient.base; + + +import static android.content.Context.MODE_PRIVATE; +import static androidx.test.core.app.ApplicationProvider.getApplicationContext; +import static androidx.test.espresso.Espresso.onData; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static org.hamcrest.Matchers.anything; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasToString; +import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; +import static utils.CustomInteractions.tryResolve; + +import android.content.SharedPreferences; + +import androidx.test.espresso.DataInteraction; +import androidx.test.espresso.NoMatchingViewException; +import androidx.test.ext.junit.rules.ActivityScenarioRule; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; + +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import se.leap.bitmaskclient.R; +import se.leap.bitmaskclient.providersetup.ProviderListActivity; +import tools.fastlane.screengrab.Screengrab; +import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy; +import tools.fastlane.screengrab.locale.LocaleTestRule; + +@LargeTest +@RunWith(AndroidJUnit4.class) +public class ProviderSetupTest { + + @ClassRule + public static final LocaleTestRule localeTestRule = new LocaleTestRule(); + + @Rule + public ActivityScenarioRule mActivityScenarioRule = + new ActivityScenarioRule<>(ProviderListActivity.class); + + @Before + public void setup() { + Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy()); + SharedPreferences preferences = getApplicationContext().getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); + preferences.edit().clear().commit(); + } + + @Test + public void testConfigureRiseupVPNScreenshot() { + DataInteraction linearLayout = tryResolve(onData(hasToString(containsString("riseup.net"))) + .inAdapterView(withId(R.id.provider_list)), + 2); + Screengrab.screenshot("ProviderListActivity"); + linearLayout.perform(click()); + Screengrab.screenshot("ProviderListActivity_configureRiseup"); + } + + @Test + public void testaddManuallyNewProviderScreenshot() { + onData(anything()).inAdapterView(withId(R.id.provider_list)).atPosition(3).perform(click()); + Screengrab.screenshot("ProviderListActivity_addManuallyNewProvider"); + } +} diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/base/VpnStartTest.java b/app/src/androidTest/java/se/leap/bitmaskclient/base/VpnStartTest.java new file mode 100644 index 00000000..6c99b90e --- /dev/null +++ b/app/src/androidTest/java/se/leap/bitmaskclient/base/VpnStartTest.java @@ -0,0 +1,176 @@ +package se.leap.bitmaskclient.base; + + +import static android.content.Context.MODE_PRIVATE; +import static androidx.test.core.app.ApplicationProvider.getApplicationContext; +import static androidx.test.espresso.Espresso.onData; +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.contrib.DrawerMatchers.isClosed; +import static androidx.test.espresso.matcher.RootMatchers.isDialog; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withTagValue; +import static androidx.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.anything; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasToString; +import static org.hamcrest.Matchers.is; +import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; +import static utils.CustomInteractions.tryResolve; + +import android.content.SharedPreferences; +import android.view.Gravity; + +import androidx.test.espresso.DataInteraction; +import androidx.test.espresso.NoMatchingViewException; +import androidx.test.espresso.ViewInteraction; +import androidx.test.espresso.contrib.DrawerActions; +import androidx.test.ext.junit.rules.ActivityScenarioRule; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; + +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.FixMethodOrder; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; + +import se.leap.bitmaskclient.R; +import tools.fastlane.screengrab.Screengrab; +import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy; +import tools.fastlane.screengrab.locale.LocaleTestRule; + +@LargeTest +@RunWith(AndroidJUnit4.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class VpnStartTest { + + @ClassRule + public static final LocaleTestRule localeTestRule = new LocaleTestRule(); + + @Rule + public ActivityScenarioRule mActivityScenarioRule = + new ActivityScenarioRule<>(StartActivity.class); + + @Before + public void setup() { + Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy()); + SharedPreferences preferences = getApplicationContext().getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); + preferences.edit().clear().commit(); + } + + @Test + public void test01_vpnStartTest() { + boolean configurationNeeded = configureProviderIfNeeded(); + + ViewInteraction mainButtonStop; + if (!configurationNeeded) { + // click on Main on/off button and start VPN + ViewInteraction mainButton = tryResolve( + onView(withId(R.id.main_button)), + matches(isDisplayed()) + ); + + mainButton.perform(click()); + tryResolve( + onView(allOf( + withId(R.id.button), + withTagValue(is("button_circle_cancel")))), + matches(isDisplayed()), + 2); + Screengrab.screenshot("VPN_connecting"); + + mainButtonStop = tryResolve( + onView(allOf( + withId(R.id.button), + withTagValue(is("button_circle_stop")))), + matches(isDisplayed()), + 20); + Screengrab.screenshot("VPN_connected"); + } else { + // on new configurations the VPN is automatically started + Screengrab.screenshot("VPN_connecting"); + mainButtonStop = tryResolve( + onView(allOf( + withId(R.id.button), + withTagValue(is("button_circle_stop")))), + matches(isDisplayed()), + 20); + Screengrab.screenshot("VPN_connected"); + } + + mainButtonStop.perform(click()); + Screengrab.screenshot("VPN_ask_disconnect"); + + onView(withText(android.R.string.yes)) + .inRoot(isDialog()) + .check(matches(isDisplayed())) + .perform(click()); + Screengrab.screenshot("VPN_disconnected"); + } + + @Test + public void test02_SettingsFragmentScreenshots() { + onView(withId(R.id.drawer_layout)) + .check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed. + .perform(DrawerActions.open()); // Open Drawer + + Screengrab.screenshot("navigationDrawer"); + + // Start the screen of your activity. + onView(withId(R.id.advancedSettings)) + .perform(click()); + + Screengrab.screenshot("settingsFragment"); + } + + @Test + public void test03_LocationSelectionFragmentScreenshots() { + onView(withId(R.id.drawer_layout)) + .check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed. + .perform(DrawerActions.open()); // Open Drawer + + onView(withId(R.id.manualGatewaySelection)) + .perform(click()); + + Screengrab.screenshot("GatewaySelectionFragment"); + } + + @Test + public void test04_AppExclusionFragmentScreenshots() { + onView(withId(R.id.drawer_layout)) + .check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed. + .perform(DrawerActions.open()); // Open Drawer + + onView(withId(R.id.advancedSettings)).perform(click()); + + onView(withId(R.id.exclude_apps)).perform(click()); + + tryResolve( + onData(anything()).inAdapterView(withId(android.R.id.list)).atPosition(2), + matches(isDisplayed()), + 5); + + Screengrab.screenshot("App_Exclusion_Fragment"); + } + + public boolean configureProviderIfNeeded() { + try { + DataInteraction linearLayout = tryResolve(onData(hasToString(containsString("riseup.net"))) + .inAdapterView(withId(R.id.provider_list)), + 2); + linearLayout.perform(click()); + return true; + } catch (NoMatchingViewException e) { + // it might be that the provider was already configured, so we print the stack + // trace here and try to continue + e.printStackTrace(); + } + return false; + } +} diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/suite/ScreenshotTest.java b/app/src/androidTest/java/se/leap/bitmaskclient/suite/ScreenshotTest.java new file mode 100644 index 00000000..186a50d1 --- /dev/null +++ b/app/src/androidTest/java/se/leap/bitmaskclient/suite/ScreenshotTest.java @@ -0,0 +1,19 @@ +package se.leap.bitmaskclient.suite; + + +import androidx.test.filters.LargeTest; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +import se.leap.bitmaskclient.base.ProviderSetupTest; +import se.leap.bitmaskclient.base.VpnStartTest; + +@LargeTest +@RunWith(Suite.class) +@Suite.SuiteClasses({ + ProviderSetupTest.class, + VpnStartTest.class, +}) +public class ScreenshotTest { +} diff --git a/app/src/androidTest/java/utils/CustomInteractions.java b/app/src/androidTest/java/utils/CustomInteractions.java new file mode 100644 index 00000000..896e8d9b --- /dev/null +++ b/app/src/androidTest/java/utils/CustomInteractions.java @@ -0,0 +1,81 @@ +package utils; + +import androidx.annotation.Nullable; +import androidx.test.espresso.DataInteraction; +import androidx.test.espresso.NoMatchingViewException; +import androidx.test.espresso.ViewAssertion; +import androidx.test.espresso.ViewInteraction; + +public class CustomInteractions { + + public static @Nullable + ViewInteraction tryResolve(ViewInteraction viewInteraction, int maxTries) { + return tryResolve(viewInteraction, null, maxTries); + } + + public static @Nullable + ViewInteraction tryResolve(ViewInteraction viewInteraction, ViewAssertion assertion) { + return tryResolve(viewInteraction, assertion, 10); + } + + public static @Nullable ViewInteraction tryResolve(ViewInteraction viewInteraction, ViewAssertion assertion, int maxTries) { + ViewInteraction resolvedViewInteraction = null; + int attempt = 0; + boolean hasFound = false; + while (!hasFound && attempt < maxTries) { + try { + resolvedViewInteraction = viewInteraction; + if (assertion != null) { + resolvedViewInteraction.check(assertion); + } + hasFound = true; + } catch (NoMatchingViewException exception) { + System.out.println("NoMatchingViewException attempt: " + attempt); + attempt++; + if (attempt == maxTries) { + throw exception; + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + break; + } + } + } + return resolvedViewInteraction; + } + + public static @Nullable + DataInteraction tryResolve(DataInteraction dataInteraction, ViewAssertion assertion, int maxTries) { + DataInteraction resolvedDataInteraction = null; + int attempt = 0; + boolean hasFound = false; + while (!hasFound && attempt < maxTries) { + try { + resolvedDataInteraction = dataInteraction; + if (assertion != null) { + resolvedDataInteraction.check(assertion); + } + hasFound = true; + } catch (Exception exception) { + // TODO: specify expected exception + attempt++; + if (attempt == maxTries) { + throw exception; + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + break; + } + } + } + return resolvedDataInteraction; + } + public static @Nullable + DataInteraction tryResolve(DataInteraction dataInteraction, int maxTries) { + return tryResolve(dataInteraction, null, maxTries); + } +} diff --git a/app/src/androidTest/java/utils/CustomMatchers.java b/app/src/androidTest/java/utils/CustomMatchers.java new file mode 100644 index 00000000..5fe11cd2 --- /dev/null +++ b/app/src/androidTest/java/utils/CustomMatchers.java @@ -0,0 +1,31 @@ +package utils; + +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewParent; + +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; + +public class CustomMatchers { + + public static Matcher childAtPosition( + final Matcher parentMatcher, final int position) { + + return new TypeSafeMatcher() { + @Override + public void describeTo(Description description) { + description.appendText("Child at position " + position + " in parent "); + parentMatcher.describeTo(description); + } + + @Override + public boolean matchesSafely(View view) { + ViewParent parent = view.getParent(); + return parent instanceof ViewGroup && parentMatcher.matches(parent) + && view.equals(((ViewGroup) parent).getChildAt(position)); + } + }; + } +} diff --git a/app/src/androidTest/java/utils/CustomViewActions.java b/app/src/androidTest/java/utils/CustomViewActions.java new file mode 100644 index 00000000..fb0dcc27 --- /dev/null +++ b/app/src/androidTest/java/utils/CustomViewActions.java @@ -0,0 +1,89 @@ +package utils; + +import static androidx.test.espresso.matcher.ViewMatchers.isRoot; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withText; + +import android.view.View; + +import androidx.annotation.StringRes; +import androidx.test.espresso.UiController; +import androidx.test.espresso.ViewAction; +import androidx.test.espresso.util.TreeIterables; + +import org.hamcrest.Matcher; + +public class CustomViewActions { + + public static ViewAction waitForView(int viewId, long timeout) { + return new ViewAction() { + + @Override + public String getDescription() { + return "Wait for view with specific id \n@param viewId: resource ID \n@param timeout: timeout in milli seconds."; + } + + @Override + public Matcher getConstraints() { + return isRoot(); + } + + @Override + public void perform(UiController uiController, View view) { + uiController.loopMainThreadUntilIdle(); + long startTime = System.currentTimeMillis(); + long endTime = startTime + timeout; + Matcher viewMatcher = withId(viewId); + + while (System.currentTimeMillis() < endTime) { + // Iterate through all views on the screen and see if the view we are looking for is there already + for (View child : TreeIterables.breadthFirstViewTraversal(view)) { + // found view with required ID + if (viewMatcher.matches(child)) { + return; + } + } + // Loops the main thread for a specified period of time. + // Control may not return immediately, instead it'll return after the provided delay has passed and the queue is in an idle state again. + uiController.loopMainThreadForAtLeast(100); + } + } + }; + } + + public static ViewAction waitForText(@StringRes int textId, long timeout) { + return new ViewAction() { + + @Override + public String getDescription() { + return "Wait for view with specific id \n@param viewId: resource ID \n@param timeout: timeout in milli seconds."; + } + + @Override + public Matcher getConstraints() { + return isRoot(); + } + + @Override + public void perform(UiController uiController, View view) { + uiController.loopMainThreadUntilIdle(); + long startTime = System.currentTimeMillis(); + long endTime = startTime + timeout; + Matcher viewMatcher = withText(textId); + + while (System.currentTimeMillis() < endTime) { + // Iterate through all views on the screen and see if the view we are looking for is there already + for (View child : TreeIterables.breadthFirstViewTraversal(view)) { + // found view with required ID + if (viewMatcher.matches(child)) { + return; + } + } + // Loops the main thread for a specified period of time. + // Control may not return immediately, instead it'll return after the provided delay has passed and the queue is in an idle state again. + uiController.loopMainThreadForAtLeast(100); + } + } + }; + } +} \ No newline at end of file diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java b/app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java index fc86fc0b..c7273613 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/MainButton.java @@ -48,10 +48,12 @@ public class MainButton extends RelativeLayout { public void updateState(boolean isOn, boolean isProcessing) { if (isProcessing) { button.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.button_circle_cancel)); + button.setTag("button_circle_cancel"); } else { button.setImageDrawable( ContextCompat.getDrawable(getContext(), isOn ? R.drawable.button_circle_stop : R.drawable.button_circle_start)); + button.setTag(isOn ? "button_circle_stop" : "button_circle_start"); } } } diff --git a/app/src/sharedTest/java/se.leap.bitmaskclient/testutils/TestSetupHelper.java b/app/src/sharedTest/java/se.leap.bitmaskclient/testutils/TestSetupHelper.java deleted file mode 100644 index 72791ba6..00000000 --- a/app/src/sharedTest/java/se.leap.bitmaskclient/testutils/TestSetupHelper.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Copyright (c) 2018 LEAP Encryption Access Project and contributers - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package se.leap.bitmaskclient.testutils; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -import se.leap.bitmaskclient.base.models.Provider; - -/** - * Created by cyberta on 08.10.17. - */ - -public class TestSetupHelper { - - public static String getInputAsString(InputStream fileAsInputStream) throws IOException { - BufferedReader br = new BufferedReader(new InputStreamReader(fileAsInputStream)); - StringBuilder sb = new StringBuilder(); - String line = br.readLine(); - while (line != null) { - sb.append(line); - line = br.readLine(); - if (line != null) { - sb.append("\n"); - } - } - - return sb.toString(); - } - - - public static Provider getConfiguredProvider() throws IOException, JSONException { - return getProvider(null, null, null, null, null, null, null, null); - } - - public static Provider getConfiguredProviderAPIv4() { - return getProvider(null, null, null, null, null, "v4/riseup.net.json", "v4/riseup.service.json", null); - } - - - public static Provider getProvider(String domain, String geoipUrl, String providerIp, String providerApiIp, String caCertFile, String providerJson, String eipServiceJson, String geoIpJson) { - if (domain == null) - domain = "https://riseup.net"; - if (geoipUrl == null) - geoipUrl = "https://api.black.riseup.net:9001/json"; - if (providerIp == null) { - providerIp = ""; - } - if (providerApiIp == null) { - providerApiIp = ""; - } - if (caCertFile == null) - caCertFile = "riseup.net.pem"; - if (providerJson == null) - providerJson = "riseup.net.json"; - if (eipServiceJson == null) { - eipServiceJson = "riseup.service.json"; - } - if (geoIpJson == null) { - geoIpJson = "riseup.geoip.json"; - } - - try { - Provider p = new Provider( - domain, - geoipUrl, - null, - providerIp, - providerApiIp, - getInputAsString(TestSetupHelper.class.getClassLoader().getResourceAsStream(caCertFile)), - getInputAsString(TestSetupHelper.class.getClassLoader().getResourceAsStream(providerJson)) - - ); - JSONObject eipServiceJsonObject = new JSONObject( - getInputAsString(TestSetupHelper.class.getClassLoader().getResourceAsStream(eipServiceJson))); - p.setEipServiceJson(eipServiceJsonObject); - - JSONObject geoIpJsonObject = new JSONObject( - getInputAsString(TestSetupHelper.class.getClassLoader().getResourceAsStream(geoIpJson))); - p.setGeoIpJson(geoIpJsonObject); - return p; - } catch (IOException | JSONException e) { - e.printStackTrace(); - } - return null; - } - -} diff --git a/app/src/test/java/se/leap/bitmaskclient/testutils/TestSetupHelper.java b/app/src/test/java/se/leap/bitmaskclient/testutils/TestSetupHelper.java new file mode 100644 index 00000000..72791ba6 --- /dev/null +++ b/app/src/test/java/se/leap/bitmaskclient/testutils/TestSetupHelper.java @@ -0,0 +1,108 @@ +/** + * Copyright (c) 2018 LEAP Encryption Access Project and contributers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package se.leap.bitmaskclient.testutils; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import se.leap.bitmaskclient.base.models.Provider; + +/** + * Created by cyberta on 08.10.17. + */ + +public class TestSetupHelper { + + public static String getInputAsString(InputStream fileAsInputStream) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(fileAsInputStream)); + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + while (line != null) { + sb.append(line); + line = br.readLine(); + if (line != null) { + sb.append("\n"); + } + } + + return sb.toString(); + } + + + public static Provider getConfiguredProvider() throws IOException, JSONException { + return getProvider(null, null, null, null, null, null, null, null); + } + + public static Provider getConfiguredProviderAPIv4() { + return getProvider(null, null, null, null, null, "v4/riseup.net.json", "v4/riseup.service.json", null); + } + + + public static Provider getProvider(String domain, String geoipUrl, String providerIp, String providerApiIp, String caCertFile, String providerJson, String eipServiceJson, String geoIpJson) { + if (domain == null) + domain = "https://riseup.net"; + if (geoipUrl == null) + geoipUrl = "https://api.black.riseup.net:9001/json"; + if (providerIp == null) { + providerIp = ""; + } + if (providerApiIp == null) { + providerApiIp = ""; + } + if (caCertFile == null) + caCertFile = "riseup.net.pem"; + if (providerJson == null) + providerJson = "riseup.net.json"; + if (eipServiceJson == null) { + eipServiceJson = "riseup.service.json"; + } + if (geoIpJson == null) { + geoIpJson = "riseup.geoip.json"; + } + + try { + Provider p = new Provider( + domain, + geoipUrl, + null, + providerIp, + providerApiIp, + getInputAsString(TestSetupHelper.class.getClassLoader().getResourceAsStream(caCertFile)), + getInputAsString(TestSetupHelper.class.getClassLoader().getResourceAsStream(providerJson)) + + ); + JSONObject eipServiceJsonObject = new JSONObject( + getInputAsString(TestSetupHelper.class.getClassLoader().getResourceAsStream(eipServiceJson))); + p.setEipServiceJson(eipServiceJsonObject); + + JSONObject geoIpJsonObject = new JSONObject( + getInputAsString(TestSetupHelper.class.getClassLoader().getResourceAsStream(geoIpJson))); + p.setGeoIpJson(geoIpJsonObject); + return p; + } catch (IOException | JSONException e) { + e.printStackTrace(); + } + return null; + } + +} -- cgit v1.2.3 From a800ef1e82c25207a842c197190b614e43739051 Mon Sep 17 00:00:00 2001 From: cyberta Date: Fri, 20 Jan 2023 11:59:57 +0100 Subject: fixing tests --- app/src/test/resources/v4/riseup.net.cert | 96 +++++++++++++++---------------- 1 file changed, 48 insertions(+), 48 deletions(-) (limited to 'app/src') diff --git a/app/src/test/resources/v4/riseup.net.cert b/app/src/test/resources/v4/riseup.net.cert index 1beff4bd..2708a8c8 100644 --- a/app/src/test/resources/v4/riseup.net.cert +++ b/app/src/test/resources/v4/riseup.net.cert @@ -1,54 +1,54 @@ -----BEGIN RSA PRIVATE KEY----- -MIIEowIBAAKCAQEAqSkd5UbKh+HbWSH603MJNgSkomeBnPooE0dlxYXIOQa/HnTl -5+7CV47JDWjFWSj1h+zeAmXcgkQxDRF1rbZ+oov26SYyGingBQgn9qvoCZwIdesE -N5Xhdvt23FK8edanCMN/tn1CnyaO5xvHdWRvhpmEf9zAsVwo9qfx1vmRsJfzvcnH -rHoCgH3nxzK1VZm5xNGRdAm9jA2odYYIuSKN1hSYgjcnXVvNHm3bWs+B4RzgtrZG -vy+vsSSd6AaYGQ4sCj3DOuKNOWqXZ8yFpfjbi0rYsOmzxEFiZiequxhrafSM+2uy -NbdPsPXKd0veZh1ApDEHW/6I+qP0bnHE6Dtr+wIDAQABAoIBABnwxjbcrj48Mmju -vwoh/+2atKx69vNdoTujnUW3CEdGc5R2FLOGd6L5sHcv8+OCVnSrrDft6uzHDEaW -wNcMv0qp8Ak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wZrUSQbZsOLNUtSyLJVyhHRLBBzOOJ/ +Cw8awAEeXXwF1+qAO4MAq/ILcA/v8hAR6AlZez6nbZOBfk5JvEPumZPdIQN6PQ6J +jODFuJRFFemea3uYyUEnv5MD3BcsApIrM7eRc82Edc9a73CkuMP4ekG68OFl2qHl +h+XzEchQNVG3t+Ka+8FN1RyeXhPRjzf1JG0elP+CIuyHBOd1SJLv4elGK2ZJWk2L +cPfLt+tFATKy3PEuftXasLG9g/K8PVaNh8gmh4en88vM0XxZ7npygPv84Cl5wV4r +LUuR6Cy8quE8QHx01D2EAspkHqk4d/xClyxfT1KCKEQvOk5gOlSrEFsB8TTqtYfr +G1LiVDcwEq+ExmeDwGIW0EY2mOre7yTHva0p0JZ4AcyK4lNIPXpGBOQcyZ++7/jh +vdNyERG7ZAjCsj7YTy72On5cS6DQDEHnKmrAIejLLw== +-----END CERTIFICATE----- \ No newline at end of file -- cgit v1.2.3 From 7d0a1f8d8057faa74035de0cee262a46c6fbbe00 Mon Sep 17 00:00:00 2001 From: cyberta Date: Mon, 23 Jan 2023 19:47:56 +0100 Subject: setup fastlane to create screenshots for Bitmask and custom branded clients, refactor Tests accordingly and create a script and environment variables to run fastlane screenshotting without thinking --- .../leap/bitmaskclient/base/ProviderBaseTest.java | 157 ++++++++++++++++++ .../leap/bitmaskclient/base/ProviderSetupTest.java | 68 -------- .../se/leap/bitmaskclient/base/VpnStartTest.java | 176 --------------------- .../leap/bitmaskclient/suite/ScreenshotTest.java | 19 --- .../androidTest/java/utils/CustomInteractions.java | 1 + .../bitmaskclient/base/CustomProviderTest.java | 49 ++++++ .../leap/bitmaskclient/suite/ScreenshotTest.java | 17 ++ .../se/leap/bitmaskclient/base/BitmaskTest.java | 42 +++++ .../leap/bitmaskclient/base/ProviderSetupTest.java | 68 ++++++++ .../leap/bitmaskclient/suite/ScreenshotTest.java | 19 +++ 10 files changed, 353 insertions(+), 263 deletions(-) create mode 100644 app/src/androidTest/java/se/leap/bitmaskclient/base/ProviderBaseTest.java delete mode 100644 app/src/androidTest/java/se/leap/bitmaskclient/base/ProviderSetupTest.java delete mode 100644 app/src/androidTest/java/se/leap/bitmaskclient/base/VpnStartTest.java delete mode 100644 app/src/androidTest/java/se/leap/bitmaskclient/suite/ScreenshotTest.java create mode 100644 app/src/androidTestCustom/java/se/leap/bitmaskclient/base/CustomProviderTest.java create mode 100644 app/src/androidTestCustom/java/se/leap/bitmaskclient/suite/ScreenshotTest.java create mode 100644 app/src/androidTestNormal/java/se/leap/bitmaskclient/base/BitmaskTest.java create mode 100644 app/src/androidTestNormal/java/se/leap/bitmaskclient/base/ProviderSetupTest.java create mode 100644 app/src/androidTestNormal/java/se/leap/bitmaskclient/suite/ScreenshotTest.java (limited to 'app/src') diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/base/ProviderBaseTest.java b/app/src/androidTest/java/se/leap/bitmaskclient/base/ProviderBaseTest.java new file mode 100644 index 00000000..bbfcdc8b --- /dev/null +++ b/app/src/androidTest/java/se/leap/bitmaskclient/base/ProviderBaseTest.java @@ -0,0 +1,157 @@ +package se.leap.bitmaskclient.base; + +import static android.content.Context.MODE_PRIVATE; +import static androidx.test.core.app.ApplicationProvider.getApplicationContext; +import static androidx.test.espresso.Espresso.onData; +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.contrib.DrawerMatchers.isClosed; +import static androidx.test.espresso.matcher.RootMatchers.isDialog; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withTagValue; +import static androidx.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.anything; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasToString; +import static org.hamcrest.Matchers.is; +import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; +import static utils.CustomInteractions.tryResolve; + +import android.content.SharedPreferences; +import android.view.Gravity; + +import androidx.test.espresso.DataInteraction; +import androidx.test.espresso.NoMatchingViewException; +import androidx.test.espresso.ViewInteraction; +import androidx.test.espresso.contrib.DrawerActions; +import androidx.test.ext.junit.rules.ActivityScenarioRule; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; + +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.FixMethodOrder; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; + +import se.leap.bitmaskclient.R; +import tools.fastlane.screengrab.Screengrab; +import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy; +import tools.fastlane.screengrab.locale.LocaleTestRule; + +@LargeTest +@RunWith(AndroidJUnit4.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public abstract class ProviderBaseTest { + + @ClassRule + public static final LocaleTestRule localeTestRule = new LocaleTestRule(); + + @Rule + public ActivityScenarioRule mActivityScenarioRule = + new ActivityScenarioRule<>(StartActivity.class); + + @Before + public void setup() { + Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy()); + SharedPreferences preferences = getApplicationContext().getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); + preferences.edit().clear().commit(); + } + + @Test + public void test01_vpnStartTest() throws InterruptedException { + boolean configurationNeeded = configureProviderIfNeeded(); + + ViewInteraction mainButtonStop; + if (!configurationNeeded) { + // click on Main on/off button and start VPN + ViewInteraction mainButton = tryResolve( + onView(withId(R.id.main_button)), + matches(isDisplayed()) + ); + + mainButton.perform(click()); + Thread.sleep(50); + Screengrab.screenshot("VPN_connecting"); + + mainButtonStop = tryResolve( + onView(allOf( + withId(R.id.button), + withTagValue(is("button_circle_stop")))), + matches(isDisplayed()), + 20); + Screengrab.screenshot("VPN_connected"); + } else { + // on new configurations the VPN is automatically started + Screengrab.screenshot("VPN_connecting"); + mainButtonStop = tryResolve( + onView(allOf( + withId(R.id.button), + withTagValue(is("button_circle_stop")))), + matches(isDisplayed()), + 20); + Screengrab.screenshot("VPN_connected"); + } + + mainButtonStop.perform(click()); + Screengrab.screenshot("VPN_ask_disconnect"); + + onView(withText(android.R.string.yes)) + .inRoot(isDialog()) + .check(matches(isDisplayed())) + .perform(click()); + Screengrab.screenshot("VPN_disconnected"); + } + + @Test + public void test02_SettingsFragmentScreenshots() { + onView(withId(R.id.drawer_layout)) + .check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed. + .perform(DrawerActions.open()); // Open Drawer + + Screengrab.screenshot("navigationDrawer"); + + // Start the screen of your activity. + onView(withId(R.id.advancedSettings)) + .perform(click()); + + Screengrab.screenshot("settingsFragment"); + } + + @Test + public void test03_LocationSelectionFragmentScreenshots() { + onView(withId(R.id.drawer_layout)) + .check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed. + .perform(DrawerActions.open()); // Open Drawer + + onView(withId(R.id.manualGatewaySelection)) + .perform(click()); + + Screengrab.screenshot("GatewaySelectionFragment"); + } + + @Test + public void test04_AppExclusionFragmentScreenshots() { + onView(withId(R.id.drawer_layout)) + .check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed. + .perform(DrawerActions.open()); // Open Drawer + + onView(withId(R.id.advancedSettings)).perform(click()); + + onView(withId(R.id.exclude_apps)).perform(click()); + + tryResolve( + onData(anything()).inAdapterView(withId(android.R.id.list)).atPosition(2), + matches(isDisplayed()), + 5); + + Screengrab.screenshot("App_Exclusion_Fragment"); + } + + public abstract boolean configureProviderIfNeeded(); +} diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/base/ProviderSetupTest.java b/app/src/androidTest/java/se/leap/bitmaskclient/base/ProviderSetupTest.java deleted file mode 100644 index 23db8582..00000000 --- a/app/src/androidTest/java/se/leap/bitmaskclient/base/ProviderSetupTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package se.leap.bitmaskclient.base; - - -import static android.content.Context.MODE_PRIVATE; -import static androidx.test.core.app.ApplicationProvider.getApplicationContext; -import static androidx.test.espresso.Espresso.onData; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static org.hamcrest.Matchers.anything; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.hasToString; -import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; -import static utils.CustomInteractions.tryResolve; - -import android.content.SharedPreferences; - -import androidx.test.espresso.DataInteraction; -import androidx.test.espresso.NoMatchingViewException; -import androidx.test.ext.junit.rules.ActivityScenarioRule; -import androidx.test.ext.junit.runners.AndroidJUnit4; -import androidx.test.filters.LargeTest; - -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import se.leap.bitmaskclient.R; -import se.leap.bitmaskclient.providersetup.ProviderListActivity; -import tools.fastlane.screengrab.Screengrab; -import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy; -import tools.fastlane.screengrab.locale.LocaleTestRule; - -@LargeTest -@RunWith(AndroidJUnit4.class) -public class ProviderSetupTest { - - @ClassRule - public static final LocaleTestRule localeTestRule = new LocaleTestRule(); - - @Rule - public ActivityScenarioRule mActivityScenarioRule = - new ActivityScenarioRule<>(ProviderListActivity.class); - - @Before - public void setup() { - Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy()); - SharedPreferences preferences = getApplicationContext().getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); - preferences.edit().clear().commit(); - } - - @Test - public void testConfigureRiseupVPNScreenshot() { - DataInteraction linearLayout = tryResolve(onData(hasToString(containsString("riseup.net"))) - .inAdapterView(withId(R.id.provider_list)), - 2); - Screengrab.screenshot("ProviderListActivity"); - linearLayout.perform(click()); - Screengrab.screenshot("ProviderListActivity_configureRiseup"); - } - - @Test - public void testaddManuallyNewProviderScreenshot() { - onData(anything()).inAdapterView(withId(R.id.provider_list)).atPosition(3).perform(click()); - Screengrab.screenshot("ProviderListActivity_addManuallyNewProvider"); - } -} diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/base/VpnStartTest.java b/app/src/androidTest/java/se/leap/bitmaskclient/base/VpnStartTest.java deleted file mode 100644 index 6c99b90e..00000000 --- a/app/src/androidTest/java/se/leap/bitmaskclient/base/VpnStartTest.java +++ /dev/null @@ -1,176 +0,0 @@ -package se.leap.bitmaskclient.base; - - -import static android.content.Context.MODE_PRIVATE; -import static androidx.test.core.app.ApplicationProvider.getApplicationContext; -import static androidx.test.espresso.Espresso.onData; -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.contrib.DrawerMatchers.isClosed; -import static androidx.test.espresso.matcher.RootMatchers.isDialog; -import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withTagValue; -import static androidx.test.espresso.matcher.ViewMatchers.withText; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.anything; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.hasToString; -import static org.hamcrest.Matchers.is; -import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; -import static utils.CustomInteractions.tryResolve; - -import android.content.SharedPreferences; -import android.view.Gravity; - -import androidx.test.espresso.DataInteraction; -import androidx.test.espresso.NoMatchingViewException; -import androidx.test.espresso.ViewInteraction; -import androidx.test.espresso.contrib.DrawerActions; -import androidx.test.ext.junit.rules.ActivityScenarioRule; -import androidx.test.ext.junit.runners.AndroidJUnit4; -import androidx.test.filters.LargeTest; - -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.FixMethodOrder; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; - -import se.leap.bitmaskclient.R; -import tools.fastlane.screengrab.Screengrab; -import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy; -import tools.fastlane.screengrab.locale.LocaleTestRule; - -@LargeTest -@RunWith(AndroidJUnit4.class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class VpnStartTest { - - @ClassRule - public static final LocaleTestRule localeTestRule = new LocaleTestRule(); - - @Rule - public ActivityScenarioRule mActivityScenarioRule = - new ActivityScenarioRule<>(StartActivity.class); - - @Before - public void setup() { - Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy()); - SharedPreferences preferences = getApplicationContext().getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); - preferences.edit().clear().commit(); - } - - @Test - public void test01_vpnStartTest() { - boolean configurationNeeded = configureProviderIfNeeded(); - - ViewInteraction mainButtonStop; - if (!configurationNeeded) { - // click on Main on/off button and start VPN - ViewInteraction mainButton = tryResolve( - onView(withId(R.id.main_button)), - matches(isDisplayed()) - ); - - mainButton.perform(click()); - tryResolve( - onView(allOf( - withId(R.id.button), - withTagValue(is("button_circle_cancel")))), - matches(isDisplayed()), - 2); - Screengrab.screenshot("VPN_connecting"); - - mainButtonStop = tryResolve( - onView(allOf( - withId(R.id.button), - withTagValue(is("button_circle_stop")))), - matches(isDisplayed()), - 20); - Screengrab.screenshot("VPN_connected"); - } else { - // on new configurations the VPN is automatically started - Screengrab.screenshot("VPN_connecting"); - mainButtonStop = tryResolve( - onView(allOf( - withId(R.id.button), - withTagValue(is("button_circle_stop")))), - matches(isDisplayed()), - 20); - Screengrab.screenshot("VPN_connected"); - } - - mainButtonStop.perform(click()); - Screengrab.screenshot("VPN_ask_disconnect"); - - onView(withText(android.R.string.yes)) - .inRoot(isDialog()) - .check(matches(isDisplayed())) - .perform(click()); - Screengrab.screenshot("VPN_disconnected"); - } - - @Test - public void test02_SettingsFragmentScreenshots() { - onView(withId(R.id.drawer_layout)) - .check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed. - .perform(DrawerActions.open()); // Open Drawer - - Screengrab.screenshot("navigationDrawer"); - - // Start the screen of your activity. - onView(withId(R.id.advancedSettings)) - .perform(click()); - - Screengrab.screenshot("settingsFragment"); - } - - @Test - public void test03_LocationSelectionFragmentScreenshots() { - onView(withId(R.id.drawer_layout)) - .check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed. - .perform(DrawerActions.open()); // Open Drawer - - onView(withId(R.id.manualGatewaySelection)) - .perform(click()); - - Screengrab.screenshot("GatewaySelectionFragment"); - } - - @Test - public void test04_AppExclusionFragmentScreenshots() { - onView(withId(R.id.drawer_layout)) - .check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed. - .perform(DrawerActions.open()); // Open Drawer - - onView(withId(R.id.advancedSettings)).perform(click()); - - onView(withId(R.id.exclude_apps)).perform(click()); - - tryResolve( - onData(anything()).inAdapterView(withId(android.R.id.list)).atPosition(2), - matches(isDisplayed()), - 5); - - Screengrab.screenshot("App_Exclusion_Fragment"); - } - - public boolean configureProviderIfNeeded() { - try { - DataInteraction linearLayout = tryResolve(onData(hasToString(containsString("riseup.net"))) - .inAdapterView(withId(R.id.provider_list)), - 2); - linearLayout.perform(click()); - return true; - } catch (NoMatchingViewException e) { - // it might be that the provider was already configured, so we print the stack - // trace here and try to continue - e.printStackTrace(); - } - return false; - } -} diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/suite/ScreenshotTest.java b/app/src/androidTest/java/se/leap/bitmaskclient/suite/ScreenshotTest.java deleted file mode 100644 index 186a50d1..00000000 --- a/app/src/androidTest/java/se/leap/bitmaskclient/suite/ScreenshotTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package se.leap.bitmaskclient.suite; - - -import androidx.test.filters.LargeTest; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -import se.leap.bitmaskclient.base.ProviderSetupTest; -import se.leap.bitmaskclient.base.VpnStartTest; - -@LargeTest -@RunWith(Suite.class) -@Suite.SuiteClasses({ - ProviderSetupTest.class, - VpnStartTest.class, -}) -public class ScreenshotTest { -} diff --git a/app/src/androidTest/java/utils/CustomInteractions.java b/app/src/androidTest/java/utils/CustomInteractions.java index 896e8d9b..9e3a8f9d 100644 --- a/app/src/androidTest/java/utils/CustomInteractions.java +++ b/app/src/androidTest/java/utils/CustomInteractions.java @@ -31,6 +31,7 @@ public class CustomInteractions { hasFound = true; } catch (NoMatchingViewException exception) { System.out.println("NoMatchingViewException attempt: " + attempt); + exception.printStackTrace(); attempt++; if (attempt == maxTries) { throw exception; diff --git a/app/src/androidTestCustom/java/se/leap/bitmaskclient/base/CustomProviderTest.java b/app/src/androidTestCustom/java/se/leap/bitmaskclient/base/CustomProviderTest.java new file mode 100644 index 00000000..1a0814b6 --- /dev/null +++ b/app/src/androidTestCustom/java/se/leap/bitmaskclient/base/CustomProviderTest.java @@ -0,0 +1,49 @@ +package se.leap.bitmaskclient.base; + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.RootMatchers.isDialog; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withText; +import static utils.CustomInteractions.tryResolve; + +import androidx.test.espresso.ViewInteraction; + +import org.junit.Test; + +import se.leap.bitmaskclient.R; +import tools.fastlane.screengrab.Screengrab; + +public class CustomProviderTest extends ProviderBaseTest { + + @Test + @Override + public void test01_vpnStartTest() throws InterruptedException { + ViewInteraction mainButtonStop; + mainButtonStop = tryResolve( + onView(withId(R.id.main_button)), + matches(isDisplayed()), + 30); + Screengrab.screenshot("VPN_connected"); + + mainButtonStop.perform(click()); + Screengrab.screenshot("VPN_ask_disconnect"); + + ViewInteraction alertDialogOKbutton = tryResolve(onView(withText(android.R.string.yes)) + .inRoot(isDialog()), + matches(isDisplayed())); + alertDialogOKbutton.perform(click()); + Screengrab.screenshot("VPN_disconnected"); + + mainButtonStop.perform(click()); + Thread.sleep(50); + Screengrab.screenshot("VPN_connecting"); + } + + @Override + public boolean configureProviderIfNeeded() { + return false; + } +} \ No newline at end of file diff --git a/app/src/androidTestCustom/java/se/leap/bitmaskclient/suite/ScreenshotTest.java b/app/src/androidTestCustom/java/se/leap/bitmaskclient/suite/ScreenshotTest.java new file mode 100644 index 00000000..a19b0ffd --- /dev/null +++ b/app/src/androidTestCustom/java/se/leap/bitmaskclient/suite/ScreenshotTest.java @@ -0,0 +1,17 @@ +package se.leap.bitmaskclient.suite; + + +import androidx.test.filters.LargeTest; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +import se.leap.bitmaskclient.base.CustomProviderTest; + +@LargeTest +@RunWith(Suite.class) +@Suite.SuiteClasses({ + CustomProviderTest.class +}) +public class ScreenshotTest { +} diff --git a/app/src/androidTestNormal/java/se/leap/bitmaskclient/base/BitmaskTest.java b/app/src/androidTestNormal/java/se/leap/bitmaskclient/base/BitmaskTest.java new file mode 100644 index 00000000..aa437c74 --- /dev/null +++ b/app/src/androidTestNormal/java/se/leap/bitmaskclient/base/BitmaskTest.java @@ -0,0 +1,42 @@ +package se.leap.bitmaskclient.base; + + +import static androidx.test.espresso.Espresso.onData; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasToString; +import static utils.CustomInteractions.tryResolve; + +import androidx.test.espresso.DataInteraction; +import androidx.test.espresso.NoMatchingViewException; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; + +import org.junit.FixMethodOrder; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; + +import se.leap.bitmaskclient.R; + +@LargeTest +@RunWith(AndroidJUnit4.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class BitmaskTest extends ProviderBaseTest { + + @Override + public boolean configureProviderIfNeeded() { + try { + DataInteraction linearLayout = tryResolve(onData(hasToString(containsString("riseup.net"))) + .inAdapterView(withId(R.id.provider_list)), + 2); + linearLayout.perform(click()); + return true; + } catch (NoMatchingViewException e) { + // it might be that the provider was already configured, so we print the stack + // trace here and try to continue + e.printStackTrace(); + } + return false; + } +} diff --git a/app/src/androidTestNormal/java/se/leap/bitmaskclient/base/ProviderSetupTest.java b/app/src/androidTestNormal/java/se/leap/bitmaskclient/base/ProviderSetupTest.java new file mode 100644 index 00000000..23db8582 --- /dev/null +++ b/app/src/androidTestNormal/java/se/leap/bitmaskclient/base/ProviderSetupTest.java @@ -0,0 +1,68 @@ +package se.leap.bitmaskclient.base; + + +import static android.content.Context.MODE_PRIVATE; +import static androidx.test.core.app.ApplicationProvider.getApplicationContext; +import static androidx.test.espresso.Espresso.onData; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static org.hamcrest.Matchers.anything; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasToString; +import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; +import static utils.CustomInteractions.tryResolve; + +import android.content.SharedPreferences; + +import androidx.test.espresso.DataInteraction; +import androidx.test.espresso.NoMatchingViewException; +import androidx.test.ext.junit.rules.ActivityScenarioRule; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; + +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import se.leap.bitmaskclient.R; +import se.leap.bitmaskclient.providersetup.ProviderListActivity; +import tools.fastlane.screengrab.Screengrab; +import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy; +import tools.fastlane.screengrab.locale.LocaleTestRule; + +@LargeTest +@RunWith(AndroidJUnit4.class) +public class ProviderSetupTest { + + @ClassRule + public static final LocaleTestRule localeTestRule = new LocaleTestRule(); + + @Rule + public ActivityScenarioRule mActivityScenarioRule = + new ActivityScenarioRule<>(ProviderListActivity.class); + + @Before + public void setup() { + Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy()); + SharedPreferences preferences = getApplicationContext().getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); + preferences.edit().clear().commit(); + } + + @Test + public void testConfigureRiseupVPNScreenshot() { + DataInteraction linearLayout = tryResolve(onData(hasToString(containsString("riseup.net"))) + .inAdapterView(withId(R.id.provider_list)), + 2); + Screengrab.screenshot("ProviderListActivity"); + linearLayout.perform(click()); + Screengrab.screenshot("ProviderListActivity_configureRiseup"); + } + + @Test + public void testaddManuallyNewProviderScreenshot() { + onData(anything()).inAdapterView(withId(R.id.provider_list)).atPosition(3).perform(click()); + Screengrab.screenshot("ProviderListActivity_addManuallyNewProvider"); + } +} diff --git a/app/src/androidTestNormal/java/se/leap/bitmaskclient/suite/ScreenshotTest.java b/app/src/androidTestNormal/java/se/leap/bitmaskclient/suite/ScreenshotTest.java new file mode 100644 index 00000000..5fa45a95 --- /dev/null +++ b/app/src/androidTestNormal/java/se/leap/bitmaskclient/suite/ScreenshotTest.java @@ -0,0 +1,19 @@ +package se.leap.bitmaskclient.suite; + + +import androidx.test.filters.LargeTest; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +import se.leap.bitmaskclient.base.ProviderSetupTest; +import se.leap.bitmaskclient.base.BitmaskTest; + +@LargeTest +@RunWith(Suite.class) +@Suite.SuiteClasses({ + ProviderSetupTest.class, + BitmaskTest.class, +}) +public class ScreenshotTest { +} -- cgit v1.2.3 From 93bb86626e68c9820b7f40eebfc71c959ed0f047 Mon Sep 17 00:00:00 2001 From: kwadronaut Date: Thu, 23 Feb 2023 11:34:34 +0100 Subject: fix city choose test --- .../leap/bitmaskclient/base/fragments/NavigationDrawerFragment.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/NavigationDrawerFragment.java index 68435fec..aa894cca 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/NavigationDrawerFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/NavigationDrawerFragment.java @@ -424,11 +424,11 @@ public class NavigationDrawerFragment extends Fragment implements SharedPreferen Provider currentProvider = ProviderObservable.getInstance().getCurrentProvider(); account.setText(currentProvider.getName()); initManualGatewayEntry(); - } + } @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if (key.equals(PREFERRED_CITY)) { + if (key != null && key.equals(PREFERRED_CITY)) { initManualGatewayEntry(); } } -- cgit v1.2.3