From 925a76a9d20e8cdf87c852c7ccd20f4bd4c754c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Fri, 1 May 2015 10:32:28 +0200 Subject: Separated tests for UserStatusFragment. This way, I can add more easily the tests for errors. --- .../leap/bitmaskclient/test/BaseTestDashboard.java | 59 +++++++++ .../test/UserStatusTestController.java | 54 +++++++++ .../test/testDashboardIntegration.java | 135 +++++---------------- .../bitmaskclient/test/testUserStatusFragment.java | 13 ++ 4 files changed, 153 insertions(+), 108 deletions(-) create mode 100644 app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboard.java create mode 100644 app/src/androidTest/java/se/leap/bitmaskclient/test/UserStatusTestController.java create mode 100644 app/src/androidTest/java/se/leap/bitmaskclient/test/testUserStatusFragment.java (limited to 'app/src') diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboard.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboard.java new file mode 100644 index 00000000..263d83d5 --- /dev/null +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboard.java @@ -0,0 +1,59 @@ +package se.leap.bitmaskclient.test; + +import android.content.*; +import android.graphics.*; +import android.test.*; +import android.view.*; + +import com.robotium.solo.*; + +import se.leap.bitmaskclient.*; + +public abstract class BaseTestDashboard extends ActivityInstrumentationTestCase2 { + + Solo solo; + Context context; + UserStatusTestController user_status_controller; + + public BaseTestDashboard() { super(Dashboard.class); } + + @Override + protected void setUp() throws Exception { + super.setUp(); + context = getInstrumentation().getContext(); + solo = new Solo(getInstrumentation(), getActivity()); + user_status_controller = new UserStatusTestController(solo); + ConnectionManager.setMobileDataEnabled(true, context); + solo.unlockScreen(); + if (solo.searchText(solo.getString(R.string.configuration_wizard_title))) + new testConfigurationWizard(solo).toDashboardAnonymously("demo.bitmask.net"); + } + + void changeProvider(String provider) { + tapSwitchProvider(); + solo.clickOnText(provider); + useRegistered(); + } + + void tapSwitchProvider() { + solo.clickOnMenuItem(solo.getString(R.string.switch_provider_menu_option)); + solo.waitForActivity(ConfigurationWizard.class); + } + + private void useRegistered() { + String text = solo.getString(R.string.signup_or_login_button); + clickAndWaitForDashboard(text); + user_status_controller.logIn("parmegvtest10", "holahola2"); + } + + private void clickAndWaitForDashboard(String click_text) { + solo.clickOnText(click_text); + assertTrue(solo.waitForActivity(Dashboard.class, 5000)); + } + + boolean isShownWithinConfinesOfVisibleScreen(View view) { + Rect scrollBounds = new Rect(); + view.getHitRect(scrollBounds); + return view.getLocalVisibleRect(scrollBounds); + } +} diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/UserStatusTestController.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/UserStatusTestController.java new file mode 100644 index 00000000..a8b6bfe8 --- /dev/null +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/UserStatusTestController.java @@ -0,0 +1,54 @@ +package se.leap.bitmaskclient.test; + +import android.view.View; + +import com.robotium.solo.Solo; + +import se.leap.bitmaskclient.R; + +public class UserStatusTestController { + private final Solo solo; + + public UserStatusTestController(Solo solo) { + this.solo = solo; + } + + void clickUserSessionButton() { + solo.clickOnView(getUserSessionButton()); + } + + View getUserSessionButton() throws IllegalStateException { + View view = solo.getView(R.id.user_status_button); + if(view == null) + throw new IllegalStateException(); + + return view; + } + + void logIn(String username, String password) { + solo.enterText(0, username); + solo.enterText(1, password); + solo.clickOnText(solo.getString(R.string.login_button)); + solo.waitForDialogToClose(); + assertLoggedIn(); + } + + private void assertLoggedIn() { + String log_out = solo.getString(R.string.logout_button); + solo.waitForText(log_out); + } + + void assertLoggedOut() { + String log_in = solo.getString(R.string.login_button); + solo.waitForText(log_in); + } + + void logOut() { + assertLoggedIn(); + clickUserSessionButton(); + + solo.clickOnActionBarItem(R.string.logout_button); + solo.waitForDialogToClose(); + assertLoggedOut(); + } +} diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java index a41a1acf..085e3c6b 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java @@ -1,9 +1,7 @@ package se.leap.bitmaskclient.test; -import android.content.*; import android.graphics.*; -import android.test.*; -import android.view.*; +import android.graphics.drawable.Drawable; import android.widget.Button; import com.robotium.solo.*; @@ -16,25 +14,12 @@ import mbanje.kurt.fabbutton.FabButton; import mbanje.kurt.fabbutton.ProgressRingView; import se.leap.bitmaskclient.*; -public class testDashboardIntegration extends ActivityInstrumentationTestCase2 { - - private Solo solo; - private Context context; - - public testDashboardIntegration() { - super(Dashboard.class); - } +public class testDashboardIntegration extends BaseTestDashboard { @Override protected void setUp() throws Exception { super.setUp(); - context = getInstrumentation().getContext(); - solo = new Solo(getInstrumentation(), getActivity()); Screenshot.initialize(solo); - ConnectionManager.setMobileDataEnabled(true, context); - solo.unlockScreen(); - if (solo.searchText(solo.getString(R.string.configuration_wizard_title))) - new testConfigurationWizard(solo).toDashboardAnonymously("demo.bitmask.net"); } @Override @@ -82,7 +67,7 @@ public class testDashboardIntegration extends ActivityInstrumentationTestCase2