From 15a093d0f4df45bf8e80e09d14f5a1f57f0fa1ff Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 14 Sep 2017 17:36:09 +0200 Subject: avoid dependencies between different test classes extending ActivityInstrumentationTestCase2 --- .../test/BaseTestDashboardFragment.java | 47 ++++++++++++++++++---- .../test/TestConfigurationWizard.java | 41 +++++-------------- 2 files changed, 49 insertions(+), 39 deletions(-) (limited to 'app/src') diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboardFragment.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboardFragment.java index aef968b8..3e572c31 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboardFragment.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboardFragment.java @@ -1,13 +1,15 @@ package se.leap.bitmaskclient.test; -import android.content.*; -import android.graphics.*; -import android.test.*; -import android.view.*; +import android.content.Context; +import android.graphics.Rect; +import android.test.ActivityInstrumentationTestCase2; +import android.view.View; -import com.robotium.solo.*; +import com.robotium.solo.Solo; -import se.leap.bitmaskclient.*; +import se.leap.bitmaskclient.ConfigurationWizard; +import se.leap.bitmaskclient.Dashboard; +import se.leap.bitmaskclient.R; public abstract class BaseTestDashboardFragment extends ActivityInstrumentationTestCase2 { @@ -28,8 +30,9 @@ public abstract class BaseTestDashboardFragment extends ActivityInstrumentationT vpn_controller = new VpnTestController(solo); ConnectionManager.setMobileDataEnabled(true, context); solo.unlockScreen(); - if (solo.searchText(solo.getString(R.string.configuration_wizard_title))) - new testConfigurationWizard(solo).toDashboardAnonymously("demo.bitmask.net"); + if (solo.searchText(solo.getString(R.string.configuration_wizard_title))) { + toDashboardAnonymously("demo.bitmask.net"); + } } void changeProviderAndLogIn(String provider) { @@ -60,4 +63,32 @@ public abstract class BaseTestDashboardFragment extends ActivityInstrumentationT view.getHitRect(scrollBounds); return view.getLocalVisibleRect(scrollBounds); } + + + private void toDashboardAnonymously(String provider) { + selectProvider(provider); + useAnonymously(); + } + + private void useAnonymously() { + String text = solo.getString(R.string.use_anonymously_button); + clickAndWaitForDashboard(text); + } + + + private void selectProvider(String provider) { + solo.clickOnText(provider); + Screenshot.setTimeToSleep(1); + Screenshot.take("Configuring provider"); + waitForProviderDetails(); + } + + private void waitForProviderDetails() { + String text = solo.getString(R.string.provider_details_fragment_title); + assertTrue("Provider details dialog did not appear", solo.waitForText(text, 1, 60*1000)); + Screenshot.take("Provider details"); + } + + + } diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java index 1e1dbe4b..90b8b839 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java @@ -1,43 +1,36 @@ package se.leap.bitmaskclient.test; -import android.os.Build; -import android.test.*; -import android.widget.*; +import android.test.ActivityInstrumentationTestCase2; +import android.widget.ListView; -import com.robotium.solo.*; +import com.robotium.solo.Solo; -import java.io.*; +import java.io.IOException; -import se.leap.bitmaskclient.*; +import se.leap.bitmaskclient.AboutActivity; +import se.leap.bitmaskclient.ConfigurationWizard; +import se.leap.bitmaskclient.R; -public class testConfigurationWizard extends ActivityInstrumentationTestCase2 { +public class TestConfigurationWizard extends ActivityInstrumentationTestCase2 { private Solo solo; private static int added_providers; - private boolean executing_from_dashboard = false; - public testConfigurationWizard() { + public TestConfigurationWizard() { super(ConfigurationWizard.class); } - public testConfigurationWizard(Solo solo) { - super(ConfigurationWizard.class); - this.solo = solo; - executing_from_dashboard = true; - } @Override protected void setUp() throws Exception { super.setUp(); solo = new Solo(getInstrumentation(), getActivity()); Screenshot.initialize(solo); - //ConnectionManager.setMobileDataEnabled(true, solo.getCurrentActivity().getApplicationContext()); } @Override protected void tearDown() throws Exception { - if(!executing_from_dashboard) - solo.finishOpenedActivities(); + solo.finishOpenedActivities(); super.tearDown(); } @@ -111,18 +104,4 @@ public class testConfigurationWizard extends ActivityInstrumentationTestCase2