From 2519960e6735c37ec3ccd104c70a1733d8e02771 Mon Sep 17 00:00:00 2001 From: VitalyW Date: Wed, 30 Aug 2017 23:06:09 -0500 Subject: [PATCH 1/9] Configured gradle files --- app/build.gradle | 38 ++++++++++++++++++++++++++++++++++++++ build.gradle | 3 +++ 2 files changed, 41 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index b94ac9e..8f4e0c6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,12 +9,34 @@ android { targetSdkVersion 25 versionCode 1 versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } + + testBuildType 'espresso' + buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } + // We use a special build type for Espresso tests so that we can replace animated resources + // with non-animated variations during the tests. + espresso { + initWith(buildTypes.debug) + } + } +} + +// Force same version as in the app +configurations.all { + resolutionStrategy { + force 'com.android.support:support-annotations:25.3.0' + force 'com.android.support:support-v4:25.3.0' + force 'com.android.support:appcompat-v7:25.3.0' + force 'com.android.support:design:25.3.0' + force 'com.android.support:support-compat:25.3.0' + force 'com.android.support:support-core-ui:25.3.0' + force 'com.android.support:recyclerview-v7:25.3.0' } } @@ -36,4 +58,20 @@ dependencies { testCompile 'junit:junit:4.12' testCompile "org.mockito:mockito-core:2.7.22" + + // AndroidJUnitRunner and JUnit Rules + androidTestCompile 'com.android.support.test:runner:1.0.0' + androidTestCompile 'com.android.support.test:rules:1.0.0' + + // Espresso dependencies + androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0' + androidTestCompile 'com.android.support.test.espresso:espresso-contrib:3.0.0' + androidTestCompile 'com.android.support.test.espresso:espresso-intents:3.0.0' + androidTestCompile 'com.android.support.test.espresso:espresso-web:3.0.0' + androidTestCompile 'com.android.support.test.espresso.idling:idling-concurrent:3.0.0' + + // The following Espresso dependency can be either "compile" + // or "androidTestCompile", depending on the app's implementation + // androidTestCompile for now, might change later + androidTestCompile 'com.android.support.test.espresso:espresso-idling-resource:3.0.0' } diff --git a/build.gradle b/build.gradle index 0a26ece..5e07d85 100644 --- a/build.gradle +++ b/build.gradle @@ -16,6 +16,9 @@ allprojects { repositories { jcenter() maven { url "https://jitpack.io" } + maven { + url "https://maven.google.com" + } } } From 65e125f8b395569f006a827b4bce091e0f33eac7 Mon Sep 17 00:00:00 2001 From: VitalyW Date: Sun, 3 Sep 2017 15:33:21 -0500 Subject: [PATCH 2/9] added first test - user sign up --- app/build.gradle | 7 ++- .../androidtesting/EspressoSignUpTest.java | 47 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java diff --git a/app/build.gradle b/app/build.gradle index 8f4e0c6..29f2b02 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,7 +9,12 @@ android { targetSdkVersion 25 versionCode 1 versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" +// lintOptions { +// abortOnError false +// } + } testBuildType 'espresso' @@ -19,6 +24,7 @@ android { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } + // We use a special build type for Espresso tests so that we can replace animated resources // with non-animated variations during the tests. espresso { @@ -62,7 +68,6 @@ dependencies { // AndroidJUnitRunner and JUnit Rules androidTestCompile 'com.android.support.test:runner:1.0.0' androidTestCompile 'com.android.support.test:rules:1.0.0' - // Espresso dependencies androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0' androidTestCompile 'com.android.support.test.espresso:espresso-contrib:3.0.0' diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java new file mode 100644 index 0000000..af42d21 --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java @@ -0,0 +1,47 @@ +package io.mattcarroll.androidtesting; + + +import android.support.test.rule.ActivityTestRule; + +import org.junit.Rule; +import org.junit.Test; + +import io.mattcarroll.androidtesting.signup.SignUpActivity; +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.action.ViewActions.click; +import static android.support.test.espresso.action.ViewActions.scrollTo; +import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.ViewMatchers.hasErrorText; +import static android.support.test.espresso.matcher.ViewMatchers.withId; + +public class EspressoSignUpTest { + + @Rule + public final ActivityTestRule activityRule = + new ActivityTestRule<>(SignUpActivity.class, false, true); + + @Test + public void userSignUpPersonalInfoVerifyRequiredFieldsAreRequired() { + onView(withId(R.id.button_next)) + .perform(scrollTo()) + .perform(click()); + + onView(withId(R.id.edittext_first_name)) + .check(matches(hasErrorText("Required."))); + + onView(withId(R.id.edittext_last_name)) + .check(matches(hasErrorText("Required."))); + + onView(withId(R.id.edittext_address_line_1)) + .check(matches(hasErrorText("Required."))); + + onView(withId(R.id.edittext_address_city)) + .check(matches(hasErrorText("Required."))); + + onView(withId(R.id.edittext_address_state)) + .check(matches(hasErrorText("Required."))); + + onView(withId(R.id.edittext_address_zip)) + .check(matches(hasErrorText("Required."))); + } +} From 2d672b67ea4918993dad36ee446c9b2b0631339e Mon Sep 17 00:00:00 2001 From: VitalyW Date: Sun, 3 Sep 2017 15:42:08 -0500 Subject: [PATCH 3/9] Refactoring of the required fields --- .../androidtesting/EspressoSignUpTest.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java index af42d21..a597b25 100644 --- a/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java @@ -1,8 +1,11 @@ package io.mattcarroll.androidtesting; +import android.content.res.Resources; +import android.support.test.InstrumentationRegistry; import android.support.test.rule.ActivityTestRule; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -20,6 +23,13 @@ public class EspressoSignUpTest { public final ActivityTestRule activityRule = new ActivityTestRule<>(SignUpActivity.class, false, true); + private Resources resources; + + @Before + public void setUp() { + resources = InstrumentationRegistry.getTargetContext().getResources(); + } + @Test public void userSignUpPersonalInfoVerifyRequiredFieldsAreRequired() { onView(withId(R.id.button_next)) @@ -27,21 +37,21 @@ public void userSignUpPersonalInfoVerifyRequiredFieldsAreRequired() { .perform(click()); onView(withId(R.id.edittext_first_name)) - .check(matches(hasErrorText("Required."))); + .check(matches(hasErrorText(resources.getString(R.string.input_error_required)))); onView(withId(R.id.edittext_last_name)) - .check(matches(hasErrorText("Required."))); + .check(matches(hasErrorText(resources.getString(R.string.input_error_required)))); onView(withId(R.id.edittext_address_line_1)) - .check(matches(hasErrorText("Required."))); + .check(matches(hasErrorText(resources.getString(R.string.input_error_required)))); onView(withId(R.id.edittext_address_city)) - .check(matches(hasErrorText("Required."))); + .check(matches(hasErrorText(resources.getString(R.string.input_error_required)))); onView(withId(R.id.edittext_address_state)) - .check(matches(hasErrorText("Required."))); + .check(matches(hasErrorText(resources.getString(R.string.input_error_required)))); onView(withId(R.id.edittext_address_zip)) - .check(matches(hasErrorText("Required."))); + .check(matches(hasErrorText(resources.getString(R.string.input_error_required)))); } } From e5975ecfadb7d8ddae8b5d438cd2ad59b1f0ef0c Mon Sep 17 00:00:00 2001 From: VitalyW Date: Sun, 3 Sep 2017 16:40:34 -0500 Subject: [PATCH 4/9] small code refactoring --- .../java/io/mattcarroll/androidtesting/EspressoSignUpTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java index a597b25..1f937cf 100644 --- a/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java @@ -10,6 +10,7 @@ import org.junit.Test; import io.mattcarroll.androidtesting.signup.SignUpActivity; + import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.action.ViewActions.scrollTo; From a28ce83abb0f05dacad638602c1b900ecf73e7de Mon Sep 17 00:00:00 2001 From: VitalyW Date: Sun, 3 Sep 2017 16:48:04 -0500 Subject: [PATCH 5/9] homewrok 2. added sign in test --- .../androidtesting/EspressoSignInTest.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignInTest.java diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignInTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignInTest.java new file mode 100644 index 0000000..a4d3df9 --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignInTest.java @@ -0,0 +1,36 @@ +package io.mattcarroll.androidtesting; + + +import android.support.test.rule.ActivityTestRule; + +import org.junit.Rule; +import org.junit.Test; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.action.ViewActions.click; +import static android.support.test.espresso.action.ViewActions.typeText; +import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; + +public class EspressoSignInTest { + + @Rule + public final ActivityTestRule activityRule = + new ActivityTestRule<>(SplashActivity.class, false, true); + + @Test + public void userSignInVerifyNoLinkedAccounts() { + onView(withId(R.id.edittext_email)) + .perform(typeText("a@a.com")); + + onView(withId(R.id.edittext_password)) + .perform(typeText("password")); + + onView(withId(R.id.button_sign_in)) + .perform(click()); + + onView(withId(R.id.textview_no_accounts)) + .check(matches(isDisplayed())); + } +} \ No newline at end of file From 2feff5e5c9718dc5ce4312861eb857c043c97095 Mon Sep 17 00:00:00 2001 From: VitalyW Date: Sun, 3 Sep 2017 22:33:22 -0500 Subject: [PATCH 6/9] Refactoring required test, backButtonWork test --- .../androidtesting/EspressoSignUpTest.java | 96 +++++++++++++++---- 1 file changed, 79 insertions(+), 17 deletions(-) diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java index 1f937cf..af6bc65 100644 --- a/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java @@ -3,6 +3,8 @@ import android.content.res.Resources; import android.support.test.InstrumentationRegistry; +import android.support.test.espresso.NoActivityResumedException; +import android.support.test.espresso.action.EspressoKey; import android.support.test.rule.ActivityTestRule; import org.junit.Before; @@ -11,12 +13,20 @@ import io.mattcarroll.androidtesting.signup.SignUpActivity; +import static android.support.test.espresso.Espresso.closeSoftKeyboard; import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.Espresso.pressBack; import static android.support.test.espresso.action.ViewActions.click; +import static android.support.test.espresso.action.ViewActions.pressKey; import static android.support.test.espresso.action.ViewActions.scrollTo; +import static android.support.test.espresso.action.ViewActions.typeText; import static android.support.test.espresso.assertion.ViewAssertions.matches; import static android.support.test.espresso.matcher.ViewMatchers.hasErrorText; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static android.view.KeyEvent.KEYCODE_MINUS; +import static junit.framework.Assert.assertTrue; public class EspressoSignUpTest { @@ -31,28 +41,80 @@ public void setUp() { resources = InstrumentationRegistry.getTargetContext().getResources(); } - @Test - public void userSignUpPersonalInfoVerifyRequiredFieldsAreRequired() { - onView(withId(R.id.button_next)) - .perform(scrollTo()) - .perform(click()); + private static void scrollToAndTapNext() { + onView(withId(R.id.button_next)).perform(scrollTo(), click()); + } - onView(withId(R.id.edittext_first_name)) - .check(matches(hasErrorText(resources.getString(R.string.input_error_required)))); + private static void tapNext() { + onView(withId(R.id.button_next)).perform(click()); + } - onView(withId(R.id.edittext_last_name)) - .check(matches(hasErrorText(resources.getString(R.string.input_error_required)))); + private void checkFieldHasError(int fieldId, int errorId) { + onView(withId(fieldId)) + .check(matches(hasErrorText(resources.getString(errorId)))); + } - onView(withId(R.id.edittext_address_line_1)) - .check(matches(hasErrorText(resources.getString(R.string.input_error_required)))); + public static void pressBackOnActivity() { + // hide key board + closeSoftKeyboard(); + // press back button + pressBack(); + } - onView(withId(R.id.edittext_address_city)) - .check(matches(hasErrorText(resources.getString(R.string.input_error_required)))); + private static void scrollToAndFill(int fieldId, String textToType) { - onView(withId(R.id.edittext_address_state)) - .check(matches(hasErrorText(resources.getString(R.string.input_error_required)))); + EspressoKey underscore = new EspressoKey.Builder() + .withShiftPressed(true) + .withKeyCode(KEYCODE_MINUS) + .build(); - onView(withId(R.id.edittext_address_zip)) - .check(matches(hasErrorText(resources.getString(R.string.input_error_required)))); + onView(withId(fieldId)) + .perform(scrollTo(), + pressKey(underscore), + typeText(textToType)); + } + + @Test + public void userSignUpVerifyBackButtonWorksOnEachPage() { + // fill in personal info + scrollToAndFill(R.id.edittext_first_name, "TestName"); + scrollToAndFill(R.id.edittext_last_name, "TestLastName"); + scrollToAndFill(R.id.edittext_address_line_1, "TestAddress"); + scrollToAndFill(R.id.edittext_address_city, "TestCity"); + scrollToAndFill(R.id.edittext_address_state, "TestState"); + scrollToAndFill(R.id.edittext_address_zip, "12345"); + scrollToAndTapNext(); + // select interest + onView(withText("Chess")).perform(click()); + + // tap next button + tapNext(); + + // first press back button + pressBackOnActivity(); + onView(withText("Basketball")).check(matches(isDisplayed())); + + //second press of back button + pressBackOnActivity(); + onView(withId(R.id.edittext_first_name)).check(matches(isDisplayed())); + + boolean activityFinish = false; + try { + pressBackOnActivity(); + } catch (NoActivityResumedException e) { + activityFinish = true; + } + assertTrue(activityFinish); + } + + @Test + public void userSignUpPersonalInfoVerifyRequiredFieldsAreRequired() { + scrollToAndTapNext(); + checkFieldHasError(R.id.edittext_first_name, R.string.input_error_required); + checkFieldHasError(R.id.edittext_last_name, R.string.input_error_required); + checkFieldHasError(R.id.edittext_address_line_1, R.string.input_error_required); + checkFieldHasError(R.id.edittext_address_city, R.string.input_error_required); + checkFieldHasError(R.id.edittext_address_state, R.string.input_error_required); + checkFieldHasError(R.id.edittext_address_zip, R.string.input_error_required); } } From 8205e53b5083140e86c673c96417b9f5efa2c2e7 Mon Sep 17 00:00:00 2001 From: VitalyW Date: Wed, 6 Sep 2017 22:00:18 -0500 Subject: [PATCH 7/9] Home work 3 --- .../androidtesting/EspressoSignUpTest.java | 77 +++++++++++++++++-- 1 file changed, 69 insertions(+), 8 deletions(-) diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java index af6bc65..7a55b22 100644 --- a/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java @@ -5,6 +5,7 @@ import android.support.test.InstrumentationRegistry; import android.support.test.espresso.NoActivityResumedException; import android.support.test.espresso.action.EspressoKey; +import android.support.test.espresso.action.ViewActions; import android.support.test.rule.ActivityTestRule; import org.junit.Before; @@ -14,6 +15,7 @@ import io.mattcarroll.androidtesting.signup.SignUpActivity; import static android.support.test.espresso.Espresso.closeSoftKeyboard; +import static android.support.test.espresso.Espresso.onData; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.Espresso.pressBack; import static android.support.test.espresso.action.ViewActions.click; @@ -23,10 +25,14 @@ import static android.support.test.espresso.assertion.ViewAssertions.matches; import static android.support.test.espresso.matcher.ViewMatchers.hasErrorText; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.isNotChecked; import static android.support.test.espresso.matcher.ViewMatchers.withId; import static android.support.test.espresso.matcher.ViewMatchers.withText; import static android.view.KeyEvent.KEYCODE_MINUS; import static junit.framework.Assert.assertTrue; +import static org.hamcrest.CoreMatchers.allOf; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; public class EspressoSignUpTest { @@ -61,8 +67,43 @@ public static void pressBackOnActivity() { pressBack(); } - private static void scrollToAndFill(int fieldId, String textToType) { + private void selectItemByText(String item) { + onView(withText(item)).perform(click()); + } + + private static void scrollToItem(String item) { + onData(allOf(is(instanceOf(String.class)), is(item))).perform(scrollTo()); + } + + private void fillInPersonalInfo( + String name, String lastName, String address, String city, String state, String zipCode + ) { + scrollToAndFill(R.id.edittext_first_name, name); + scrollToAndFill(R.id.edittext_last_name, lastName); + scrollToAndFill(R.id.edittext_address_line_1, address); + scrollToAndFill(R.id.edittext_address_city, city); + scrollToAndFill(R.id.edittext_address_state, state); + scrollToAndFill(R.id.edittext_address_zip, zipCode); + } + + public void checkIfItemSelected(String item) { + onView(withText(item)).check(matches(isNotChecked())); + } + + public void fillInCredentials(String email, String password) { + scrollToAndFill(R.id.autocompletetextview_email, email); + scrollToAndFill(R.id.edittext_password, password); + } + + public static void clickSignUp() { + onView(withId(R.id.button_next)).perform(click()); + } + + public void checkSuccessfulPopUp() { + onView(withId(R.id.alertTitle)).check(matches(allOf(withText("Signup successful!"), isDisplayed()))); + } + private static void scrollToAndFill(int fieldId, String textToType) { EspressoKey underscore = new EspressoKey.Builder() .withShiftPressed(true) .withKeyCode(KEYCODE_MINUS) @@ -70,19 +111,17 @@ private static void scrollToAndFill(int fieldId, String textToType) { onView(withId(fieldId)) .perform(scrollTo(), - pressKey(underscore), +// pressKey(underscore), typeText(textToType)); } @Test public void userSignUpVerifyBackButtonWorksOnEachPage() { // fill in personal info - scrollToAndFill(R.id.edittext_first_name, "TestName"); - scrollToAndFill(R.id.edittext_last_name, "TestLastName"); - scrollToAndFill(R.id.edittext_address_line_1, "TestAddress"); - scrollToAndFill(R.id.edittext_address_city, "TestCity"); - scrollToAndFill(R.id.edittext_address_state, "TestState"); - scrollToAndFill(R.id.edittext_address_zip, "12345"); + fillInPersonalInfo( + "TestName", "TestLastName", "TestAddress", "TestCity", "TestState", "12345" + ); + scrollToAndTapNext(); // select interest onView(withText("Chess")).perform(click()); @@ -117,4 +156,26 @@ public void userSignUpPersonalInfoVerifyRequiredFieldsAreRequired() { checkFieldHasError(R.id.edittext_address_state, R.string.input_error_required); checkFieldHasError(R.id.edittext_address_zip, R.string.input_error_required); } + + @Test + public void userSignUpPositiveTest() { + fillInPersonalInfo( + "Vitaly", "W", "460E 5th Avenue", "New York", "NY", "10012" + ); + scrollToAndTapNext(); + scrollToItem("Astronomy"); + selectItemByText("Astronomy"); + tapNext(); + pressBackOnActivity(); + scrollToItem("Astronomy"); + checkIfItemSelected("Astronomy"); + selectItemByText("Astronomy"); + tapNext(); + //fill in credentials + fillInCredentials("a@a.com", "password"); + //click sign up + clickSignUp(); + // verify the pop up +// checkSuccessfulPopUp(); + } } From 453c4ecc9c0ddd8312e548806d6d7ce51d6a611e Mon Sep 17 00:00:00 2001 From: VitalyW Date: Tue, 12 Sep 2017 21:44:12 -0500 Subject: [PATCH 8/9] user properties, BaseTest, File system, inheritance, random string --- app/src/androidTest/assets/user.properties | 3 ++ .../mattcarroll/androidtesting/BaseTest.java | 31 +++++++++++++++++++ .../{ => login}/EspressoSignInTest.java | 8 +++-- .../{ => signup}/EspressoSignUpTest.java | 28 ++++++++++++++--- 4 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 app/src/androidTest/assets/user.properties create mode 100644 app/src/androidTest/java/io/mattcarroll/androidtesting/BaseTest.java rename app/src/androidTest/java/io/mattcarroll/androidtesting/{ => login}/EspressoSignInTest.java (81%) rename app/src/androidTest/java/io/mattcarroll/androidtesting/{ => signup}/EspressoSignUpTest.java (87%) diff --git a/app/src/androidTest/assets/user.properties b/app/src/androidTest/assets/user.properties new file mode 100644 index 0000000..c3ac65c --- /dev/null +++ b/app/src/androidTest/assets/user.properties @@ -0,0 +1,3 @@ +name=Vitaly +email=a@test.com +password=qwerty1 \ No newline at end of file diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/BaseTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/BaseTest.java new file mode 100644 index 0000000..63751bd --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/BaseTest.java @@ -0,0 +1,31 @@ +package io.mattcarroll.androidtesting; + + +import android.content.res.AssetManager; +import android.support.test.InstrumentationRegistry; + +import org.junit.Before; + +import java.io.IOException; +import java.util.Properties; + +public class BaseTest { + + private Properties properties; + + public Properties getProperties() { + return properties; + } + + public void setProperties(Properties properties) { + this.properties = properties; + } + + @Before + public void baseSetUp() throws IOException { + properties = new Properties(); + AssetManager testAssetManager = InstrumentationRegistry.getContext().getAssets(); + AssetManager.AssetInputStream assetStream = (AssetManager.AssetInputStream) testAssetManager.open("user.properties"); + properties.load(assetStream); + } +} diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignInTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/login/EspressoSignInTest.java similarity index 81% rename from app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignInTest.java rename to app/src/androidTest/java/io/mattcarroll/androidtesting/login/EspressoSignInTest.java index a4d3df9..4ed30df 100644 --- a/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignInTest.java +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/login/EspressoSignInTest.java @@ -1,11 +1,15 @@ -package io.mattcarroll.androidtesting; +package io.mattcarroll.androidtesting.login; +import android.support.test.espresso.matcher.ViewMatchers; import android.support.test.rule.ActivityTestRule; import org.junit.Rule; import org.junit.Test; +import io.mattcarroll.androidtesting.R; +import io.mattcarroll.androidtesting.SplashActivity; + import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.action.ViewActions.typeText; @@ -21,7 +25,7 @@ public class EspressoSignInTest { @Test public void userSignInVerifyNoLinkedAccounts() { - onView(withId(R.id.edittext_email)) + onView(ViewMatchers.withId(R.id.edittext_email)) .perform(typeText("a@a.com")); onView(withId(R.id.edittext_password)) diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java similarity index 87% rename from app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java rename to app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java index 7a55b22..5fe8f3b 100644 --- a/app/src/androidTest/java/io/mattcarroll/androidtesting/EspressoSignUpTest.java +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java @@ -1,4 +1,4 @@ -package io.mattcarroll.androidtesting; +package io.mattcarroll.androidtesting.signup; import android.content.res.Resources; @@ -6,12 +6,18 @@ import android.support.test.espresso.NoActivityResumedException; import android.support.test.espresso.action.EspressoKey; import android.support.test.espresso.action.ViewActions; +import android.support.test.espresso.matcher.ViewMatchers; import android.support.test.rule.ActivityTestRule; +import android.util.Log; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import java.util.Random; + +import io.mattcarroll.androidtesting.BaseTest; +import io.mattcarroll.androidtesting.R; import io.mattcarroll.androidtesting.signup.SignUpActivity; import static android.support.test.espresso.Espresso.closeSoftKeyboard; @@ -34,7 +40,7 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; -public class EspressoSignUpTest { +public class EspressoSignUpTest extends BaseTest { @Rule public final ActivityTestRule activityRule = @@ -48,7 +54,7 @@ public void setUp() { } private static void scrollToAndTapNext() { - onView(withId(R.id.button_next)).perform(scrollTo(), click()); + onView(ViewMatchers.withId(R.id.button_next)).perform(scrollTo(), click()); } private static void tapNext() { @@ -172,10 +178,24 @@ public void userSignUpPositiveTest() { selectItemByText("Astronomy"); tapNext(); //fill in credentials - fillInCredentials("a@a.com", "password"); + String password = generateRandomPassword(10); + Log.d("Info", password); + fillInCredentials(getProperties().getProperty("email"), getProperties().getProperty("password")); //click sign up clickSignUp(); // verify the pop up // checkSuccessfulPopUp(); } + + String generateRandomPassword(int length) { + String base = "ABCDEFG1234567890"; + StringBuilder res = new StringBuilder(); + Random rand = new Random(); + while (length>0) { + int index = rand.nextInt(base.length()); + res.append(base.charAt(index)); + length--; + } + return res.toString(); + } } From 3f0e7645b5d5805970132ecc757437726afeede9 Mon Sep 17 00:00:00 2001 From: VitalyW Date: Tue, 12 Sep 2017 22:41:14 -0500 Subject: [PATCH 9/9] HW 4: linkBankAccount test, split in functions, all data is in user prop file --- app/src/androidTest/assets/user.properties | 4 +- .../login/EspressoSignInTest.java | 48 ++++++++++++++++--- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/app/src/androidTest/assets/user.properties b/app/src/androidTest/assets/user.properties index c3ac65c..998aea3 100644 --- a/app/src/androidTest/assets/user.properties +++ b/app/src/androidTest/assets/user.properties @@ -1,3 +1,5 @@ name=Vitaly email=a@test.com -password=qwerty1 \ No newline at end of file +password=qwerty1 +accountNumber=1234567890 +bankName=Chase \ No newline at end of file diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/login/EspressoSignInTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/login/EspressoSignInTest.java index 4ed30df..4315b87 100644 --- a/app/src/androidTest/java/io/mattcarroll/androidtesting/login/EspressoSignInTest.java +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/login/EspressoSignInTest.java @@ -7,6 +7,7 @@ import org.junit.Rule; import org.junit.Test; +import io.mattcarroll.androidtesting.BaseTest; import io.mattcarroll.androidtesting.R; import io.mattcarroll.androidtesting.SplashActivity; @@ -17,7 +18,7 @@ import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.withId; -public class EspressoSignInTest { +public class EspressoSignInTest extends BaseTest { @Rule public final ActivityTestRule activityRule = @@ -25,16 +26,49 @@ public class EspressoSignInTest { @Test public void userSignInVerifyNoLinkedAccounts() { - onView(ViewMatchers.withId(R.id.edittext_email)) - .perform(typeText("a@a.com")); + signIn(); + onView(withId(R.id.textview_no_accounts)) + .check(matches(isDisplayed())); + } + + @Test + public void linkBankAccount() { + signIn(); + //user click + sign + clickAddButton(); + //user click Link Account + linkButtonClik(); + //user types in Bank name, Account Number, and Password + linkNewBankAccount(); + //user clicks Link + linkButtonClik(); + } + + private void clickAddButton() { + onView(withId(R.id.fab_manage_accounts)) + .perform(click()); + } + private void linkButtonClik() { + onView(withId(R.id.button_link_account)) + .perform(click()); + } + + private void linkNewBankAccount() { + onView(withId(R.id.edittext_bank_name)) + .perform(typeText(getProperties().getProperty("bankName"))); + onView(withId(R.id.edittext_account_number)) + .perform(typeText(getProperties().getProperty("accountNumber"))); onView(withId(R.id.edittext_password)) - .perform(typeText("password")); + .perform(typeText(getProperties().getProperty("password"))); + } + private void signIn() { + onView(ViewMatchers.withId(R.id.edittext_email)) + .perform(typeText(getProperties().getProperty("email"))); + onView(withId(R.id.edittext_password)) + .perform(typeText(getProperties().getProperty("password"))); onView(withId(R.id.button_sign_in)) .perform(click()); - - onView(withId(R.id.textview_no_accounts)) - .check(matches(isDisplayed())); } } \ No newline at end of file