diff options
author | cyBerta <cyberta@riseup.net> | 2023-11-22 10:41:39 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2023-11-23 09:51:28 +0100 |
commit | e2eccdcf5c49daf9236f782dcdf8ba9924cf7147 (patch) | |
tree | 16c7c6f34655867d29e26d6a285d8f729b4809dd | |
parent | 85e5ed816451b6e78574a40980f6b30876836e4d (diff) |
improve screenhsot tests, fix them for custom flavored builds
-rw-r--r-- | app/src/androidTest/java/se/leap/bitmaskclient/BitmaskTest.java (renamed from app/src/androidTestNormal/java/se/leap/bitmaskclient/base/BitmaskTest.java) | 56 | ||||
-rw-r--r-- | app/src/androidTest/java/se/leap/bitmaskclient/ProviderSetupTest.java | 20 | ||||
-rw-r--r-- | app/src/androidTest/java/se/leap/bitmaskclient/suite/ScreenshotTest.java (renamed from app/src/androidTestNormal/java/se/leap/bitmaskclient/suite/ScreenshotTest.java) | 2 | ||||
-rw-r--r-- | app/src/androidTestCustom/java/se/leap/bitmaskclient/base/CustomProviderTest.java | 62 | ||||
-rw-r--r-- | app/src/androidTestCustom/java/se/leap/bitmaskclient/suite/ScreenshotTest.java | 18 |
5 files changed, 30 insertions, 128 deletions
diff --git a/app/src/androidTestNormal/java/se/leap/bitmaskclient/base/BitmaskTest.java b/app/src/androidTest/java/se/leap/bitmaskclient/BitmaskTest.java index 1d340f61..1ca0980a 100644 --- a/app/src/androidTestNormal/java/se/leap/bitmaskclient/base/BitmaskTest.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/BitmaskTest.java @@ -1,24 +1,16 @@ -package se.leap.bitmaskclient.base; +package se.leap.bitmaskclient; -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withText; import static org.junit.Assert.assertNotNull; -import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT; -import static utils.ProviderSetupUtils.runProviderSetup; import android.Manifest; import android.app.Activity; import android.app.Instrumentation; -import android.content.Context; import android.content.Intent; import android.os.Build; import android.view.Gravity; import androidx.test.espresso.Espresso; -import androidx.test.espresso.PerformException; import androidx.test.espresso.ViewInteraction; import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.assertion.ViewAssertions; @@ -42,12 +34,14 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; -import se.leap.bitmaskclient.R; -import se.leap.bitmaskclient.base.models.ProviderObservable; +import se.leap.bitmaskclient.base.MainActivity; +import se.leap.bitmaskclient.base.StartActivity; +import se.leap.bitmaskclient.providersetup.activities.SetupActivity; import tools.fastlane.screengrab.Screengrab; import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy; import tools.fastlane.screengrab.locale.LocaleTestRule; import utils.CustomInteractions; +import utils.ProviderSetupUtils; @LargeTest @RunWith(AndroidJUnit4.class) @@ -69,7 +63,7 @@ public class BitmaskTest { } @Test - public void test03_vpnStartTest() throws InterruptedException, UiObjectNotFoundException { + public void test01_vpnStartTest() throws InterruptedException, UiObjectNotFoundException { startMainActivity(); Screengrab.screenshot("VPN_connecting"); @@ -92,7 +86,7 @@ public class BitmaskTest { } @Test - public void test04_SettingsFragmentScreenshots() { + public void test02_SettingsFragmentScreenshots() { startMainActivity(); Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)) .check(ViewAssertions.matches(DrawerMatchers.isClosed(Gravity.LEFT))) // Left Drawer should be closed. @@ -108,7 +102,7 @@ public class BitmaskTest { } @Test - public void test05_LocationSelectionFragmentScreenshots() { + public void test03_LocationSelectionFragmentScreenshots() { startMainActivity(); Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)) .check(ViewAssertions.matches(DrawerMatchers.isClosed(Gravity.LEFT))) // Left Drawer should be closed. @@ -121,7 +115,7 @@ public class BitmaskTest { } @Test - public void test06_AppExclusionFragmentScreenshots() { + public void test04_AppExclusionFragmentScreenshots() { startMainActivity(); Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)) .check(ViewAssertions.matches(DrawerMatchers.isClosed(Gravity.LEFT))) // Left Drawer should be closed. @@ -141,30 +135,18 @@ public class BitmaskTest { private void startMainActivity() { Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); - Instrumentation.ActivityMonitor monitor = new Instrumentation.ActivityMonitor(MainActivity.class.getName(), null, false); - instrumentation.addMonitor(monitor); - Intent intent = new Intent(instrumentation.getTargetContext(), MainActivity.class); + Instrumentation.ActivityMonitor setupActivityMonitor = new Instrumentation.ActivityMonitor(SetupActivity.class.getName(), null, false); + Instrumentation.ActivityMonitor mainActivityMonitor = new Instrumentation.ActivityMonitor(MainActivity.class.getName(), null, false); + instrumentation.addMonitor(setupActivityMonitor); + instrumentation.addMonitor(mainActivityMonitor); + Intent intent = new Intent(instrumentation.getTargetContext(), StartActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.setAction(ACTION_SHOW_VPN_FRAGMENT); instrumentation.startActivitySync(intent); - Activity activity = instrumentation.waitForMonitor(monitor); - assertNotNull(activity); - configureIfNeeded(); - } - - private void configureIfNeeded() { - if (ProviderObservable.getInstance().getCurrentProvider().isConfigured()) { - return; + Activity setupActivity = instrumentation.waitForMonitorWithTimeout(setupActivityMonitor, 1000L); + if (setupActivity != null) { + ProviderSetupUtils.runProviderSetup(device, false, false, InstrumentationRegistry.getInstrumentation().getTargetContext()); } - final Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - try { - onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); - } catch (PerformException performException) { - System.out.println("navigation drawer already opened"); - } - onView(withText(R.string.switch_provider_menu_option)).perform(click()); - System.out.println("configure Provider... starting SetupActivity"); - - runProviderSetup(device, false, false, targetContext); + Activity mainActivity = instrumentation.waitForMonitorWithTimeout(mainActivityMonitor, 1000); + assertNotNull(mainActivity); } } diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/ProviderSetupTest.java b/app/src/androidTest/java/se/leap/bitmaskclient/ProviderSetupTest.java index a878951a..b9da0dff 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/ProviderSetupTest.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/ProviderSetupTest.java @@ -7,7 +7,6 @@ import static androidx.test.espresso.action.ViewActions.replaceText; import static androidx.test.espresso.assertion.ViewAssertions.matches; 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 utils.CustomInteractions.tryResolve; @@ -20,18 +19,15 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.LargeTest; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.uiautomator.UiDevice; -import androidx.test.uiautomator.UiObjectNotFoundException; -import org.hamcrest.Matchers; 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.runner.manipulation.Ordering; +import org.junit.runners.MethodSorters; -import se.leap.bitmaskclient.base.fragments.MainActivityErrorDialog; -import se.leap.bitmaskclient.base.utils.PreferenceHelper; import se.leap.bitmaskclient.providersetup.activities.SetupActivity; import tools.fastlane.screengrab.Screengrab; import tools.fastlane.screengrab.UiAutomatorScreenshotStrategy; @@ -40,6 +36,7 @@ import utils.ProviderSetupUtils; @LargeTest @RunWith(AndroidJUnit4.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ProviderSetupTest { @ClassRule @@ -65,24 +62,27 @@ public class ProviderSetupTest { } @Test - public void test01_setupProviderCircumvention() { + public void test02_setupProviderCircumvention() { ProviderSetupUtils.runProviderSetup(device, true, true, InstrumentationRegistry.getInstrumentation().getTargetContext()); } @Test - public void testaddManuallyNewProviderScreenshot() { + public void test03_addManuallyNewProviderScreenshot() { if (!"normal".equals(BuildConfig.FLAVOR_branding)) { System.out.println("skipping custom provider url test"); return; } + Context context = InstrumentationRegistry.getInstrumentation().getTargetContext(); + ViewInteraction radioButtonSelection = tryResolve(onView(withText(R.string.add_provider)), matches(isDisplayed())); radioButtonSelection.perform(click()); - onView(withId(R.id.edit_customProvider)).perform(replaceText("https://leapvpn.myserver.org")); Screengrab.screenshot("setup_custom_provider"); onView(withId(R.id.setup_next_button)).perform(click()); + + onView(withText(context.getString(R.string.use_standard_vpn, context.getString(R.string.app_name)))).perform(click()); onView(withId(R.id.setup_next_button)).perform(click()); - Context context = InstrumentationRegistry.getInstrumentation().getTargetContext(); + tryResolve( onView(withText(context.getString(R.string.malformed_url, context.getString(R.string.app_name)))), matches(isDisplayed()), diff --git a/app/src/androidTestNormal/java/se/leap/bitmaskclient/suite/ScreenshotTest.java b/app/src/androidTest/java/se/leap/bitmaskclient/suite/ScreenshotTest.java index ec2e7b5c..f3a8d73c 100644 --- a/app/src/androidTestNormal/java/se/leap/bitmaskclient/suite/ScreenshotTest.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/suite/ScreenshotTest.java @@ -6,8 +6,8 @@ import androidx.test.filters.LargeTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; +import se.leap.bitmaskclient.BitmaskTest; import se.leap.bitmaskclient.ProviderSetupTest; -import se.leap.bitmaskclient.base.BitmaskTest; @LargeTest @RunWith(Suite.class) diff --git a/app/src/androidTestCustom/java/se/leap/bitmaskclient/base/CustomProviderTest.java b/app/src/androidTestCustom/java/se/leap/bitmaskclient/base/CustomProviderTest.java deleted file mode 100644 index 15e6f799..00000000 --- a/app/src/androidTestCustom/java/se/leap/bitmaskclient/base/CustomProviderTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package se.leap.bitmaskclient.base; - -import static androidx.test.core.app.ApplicationProvider.getApplicationContext; -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 android.net.VpnService; - -import androidx.test.espresso.ViewInteraction; -import androidx.test.uiautomator.UiObject; -import androidx.test.uiautomator.UiObjectNotFoundException; -import androidx.test.uiautomator.UiSelector; - -import org.junit.Test; - -import se.leap.bitmaskclient.R; -import tools.fastlane.screengrab.Screengrab; - -public class CustomProviderTest { - - /*@Test - @Override - public void test01_vpnStartTest() throws InterruptedException, UiObjectNotFoundException { - // handle VPN permission dialog - if (VpnService.prepare(getApplicationContext()) != null) { - UiObject okButton = device.findObject(new UiSelector().packageName("com.android.vpndialogs").resourceId("android:id/button1")); - okButton.waitForExists(30000); - okButton.click(); - } - - 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 deleted file mode 100644 index 15a21173..00000000 --- a/app/src/androidTestCustom/java/se/leap/bitmaskclient/suite/ScreenshotTest.java +++ /dev/null @@ -1,18 +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.ProviderSetupTest; -import se.leap.bitmaskclient.base.CustomProviderTest; - -@LargeTest -@RunWith(Suite.class) -@Suite.SuiteClasses({ - ProviderSetupTest.class -}) -public class ScreenshotTest { -} |