From 9d89cf38e73726377b599bd276d5fd00b588286a Mon Sep 17 00:00:00 2001 From: okyska Date: Thu, 31 Aug 2017 17:48:25 -0700 Subject: [PATCH 01/10] configured gradle files --- app/build.gradle | 42 +++++++++++++++++++++++++++++++++++++++++- build.gradle | 5 ++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b94ac9e..ac5edd6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,12 +9,36 @@ 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 +60,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' +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 0a26ece..71be5d9 100644 --- a/build.gradle +++ b/build.gradle @@ -16,9 +16,12 @@ allprojects { repositories { jcenter() maven { url "https://jitpack.io" } + maven { + url "https://maven.google.com" + } } } task clean(type: Delete) { delete rootProject.buildDir -} +} \ No newline at end of file From 98a506a471971a64b985b10ceaf7d3f3589dee38 Mon Sep 17 00:00:00 2001 From: okyska Date: Mon, 4 Sep 2017 19:20:56 -0700 Subject: [PATCH 02/10] added user sign up test(reqired fields) --- .../signup/EspressoSignUpTest.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java new file mode 100644 index 0000000..d8c3915 --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java @@ -0,0 +1,56 @@ +package io.mattcarroll.androidtesting.signup; + +import android.support.test.rule.ActivityTestRule; + +import org.junit.Rule; +import org.junit.Test; + +import io.mattcarroll.androidtesting.R; + +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; + +/** + * Created by oxana on 8/31/2017. + */ + +public class EspressoSignUpTest { + @Rule + public final ActivityTestRuleactivityRule = + 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 59e7ecb387e1f612be5f12708e46a5ed00947736 Mon Sep 17 00:00:00 2001 From: okyska Date: Mon, 4 Sep 2017 19:38:17 -0700 Subject: [PATCH 03/10] minor changes in requred fields --- .../signup/EspressoSignUpTest.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java index d8c3915..fed7a42 100644 --- a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java @@ -1,7 +1,10 @@ package io.mattcarroll.androidtesting.signup; +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; @@ -23,6 +26,12 @@ public class EspressoSignUpTest { public final ActivityTestRuleactivityRule = new ActivityTestRule<>(SignUpActivity.class, false, true); + private Resources resources; + + @Before + public void setup() { + resources = InstrumentationRegistry.getTargetContext().getResources(); + } @Test public void userSignUpPersonalInfoVerifyRequiredFieldsAreRequired(){ @@ -31,17 +40,17 @@ 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 e9ea7494d10b4a85c83d62414de97820a6de0fb7 Mon Sep 17 00:00:00 2001 From: okyska Date: Mon, 4 Sep 2017 20:20:14 -0700 Subject: [PATCH 04/10] added user sign in test --- .../signin/EspressoSignInTest.java | 40 +++++++++++++++++++ .../signup/EspressoSignUpTest.java | 1 + app/src/main/AndroidManifest.xml | 2 +- .../CollectInterestsFragment.java | 2 +- .../CollectPersonalInfoFragment.java | 2 +- .../Credentials.java | 2 +- .../DoSignUpFragment.java | 3 +- .../InterestsListsAdapter.java | 2 +- .../PersonalInfo.java | 2 +- .../SelectCredentialsFragment.java | 2 +- .../SignUpActivity.java | 4 +- .../SignUpForm.java | 3 +- .../androidtesting/login/LoginActivity.java | 2 +- app/src/main/res/layout/activity_sign_up.xml | 2 +- 14 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 app/src/androidTest/java/io/mattcarroll/androidtesting/signin/EspressoSignInTest.java rename app/src/main/java/io/mattcarroll/androidtesting/{signup => androidtesting}/CollectInterestsFragment.java (98%) rename app/src/main/java/io/mattcarroll/androidtesting/{signup => androidtesting}/CollectPersonalInfoFragment.java (99%) rename app/src/main/java/io/mattcarroll/androidtesting/{signup => androidtesting}/Credentials.java (89%) rename app/src/main/java/io/mattcarroll/androidtesting/{signup => androidtesting}/DoSignUpFragment.java (97%) rename app/src/main/java/io/mattcarroll/androidtesting/{signup => androidtesting}/InterestsListsAdapter.java (97%) rename app/src/main/java/io/mattcarroll/androidtesting/{signup => androidtesting}/PersonalInfo.java (96%) rename app/src/main/java/io/mattcarroll/androidtesting/{signup => androidtesting}/SelectCredentialsFragment.java (98%) rename app/src/main/java/io/mattcarroll/androidtesting/{signup => androidtesting}/SignUpActivity.java (98%) rename app/src/main/java/io/mattcarroll/androidtesting/{signup => androidtesting}/SignUpForm.java (98%) diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signin/EspressoSignInTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signin/EspressoSignInTest.java new file mode 100644 index 0000000..508b368 --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signin/EspressoSignInTest.java @@ -0,0 +1,40 @@ +package io.mattcarroll.androidtesting.signin; + +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; +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; + +/** + * Created by max on 9/4/2017. + */ + +public class EspressoSignInTest { + + @Rule + public final ActivityTestRule activityRule = + new ActivityTestRule<>(SplashActivity.class, false,true); + + @Test + public void userSignInPersonalInfoRequiredFieldsAreRequired(){ + + onView(withId(R.id.edittext_email)) + .perform(typeText("BayQA@yahoo.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())); + } +} diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java index fed7a42..c136a09 100644 --- a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java @@ -9,6 +9,7 @@ import org.junit.Test; import io.mattcarroll.androidtesting.R; +import io.mattcarroll.androidtesting.androidtesting.SignUpActivity; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5853e14..232eb71 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -32,7 +32,7 @@ android:windowSoftInputMode="adjustResize" /> From f89cc01259d90951a858b091d1a4a79174a42470 Mon Sep 17 00:00:00 2001 From: okyska Date: Mon, 4 Sep 2017 21:02:07 -0700 Subject: [PATCH 05/10] added scroll in sign in test --- .../mattcarroll/androidtesting/signin/EspressoSignInTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signin/EspressoSignInTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signin/EspressoSignInTest.java index 508b368..40d859c 100644 --- a/app/src/androidTest/java/io/mattcarroll/androidtesting/signin/EspressoSignInTest.java +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signin/EspressoSignInTest.java @@ -10,6 +10,7 @@ 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.action.ViewActions.typeText; import static android.support.test.espresso.assertion.ViewAssertions.matches; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; @@ -33,6 +34,7 @@ public void userSignInPersonalInfoRequiredFieldsAreRequired(){ onView(withId(R.id.edittext_password)) .perform(typeText("password")); onView(withId(R.id.button_sign_in)) + .perform(scrollTo()) .perform(click()); onView(withId(R.id.textview_no_accounts)) .check(matches(isDisplayed())); From 61e95cbf1c3042151ee17d35dd81a78d97749354 Mon Sep 17 00:00:00 2001 From: okyska Date: Tue, 5 Sep 2017 11:28:39 -0700 Subject: [PATCH 06/10] refactoring required test, back button works test,espressokey test --- .../signup/EspressoSignUpTest.java | 108 +++++++++++++++--- 1 file changed, 91 insertions(+), 17 deletions(-) diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java index c136a09..15972f0 100644 --- a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java @@ -2,6 +2,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.R; import io.mattcarroll.androidtesting.androidtesting.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; /** * Created by oxana on 8/31/2017. @@ -33,34 +43,98 @@ public class EspressoSignUpTest { 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)))); - onView(withId(R.id.edittext_last_name)) - .check(matches(hasErrorText(resources.getString(R.string.input_error_required)))); - onView(withId(R.id.edittext_address_line_1)) - .check(matches(hasErrorText(resources.getString(R.string.input_error_required)))); - onView(withId(R.id.edittext_address_city)) - .check(matches(hasErrorText(resources.getString(R.string.input_error_required)))); - onView(withId(R.id.edittext_address_state)) - .check(matches(hasErrorText(resources.getString(R.string.input_error_required)))); - onView(withId(R.id.edittext_address_zip)) - .check(matches(hasErrorText(resources.getString(R.string.input_error_required)))); + private static void pressBackOnActivity(){ + //hide keyboard + closeSoftKeyboard(); + //press back button + pressBack(); + } + + private static void scrollToAndFill(int fieldId, String textToType){ + + EspressoKey underscore = new EspressoKey.Builder() + .withShiftPressed(true) + .withKeyCode(KEYCODE_MINUS) + .build(); + + onView(withId(fieldId)).perform( + scrollTo(), + pressKey(underscore), + typeText(textToType) + ); + } + + private static void tapNext(){ + onView(withId(R.id.button_next)).perform( + click() + ); } + @Test + public void userSignUpVerifyBackWorksOnEachPage(){ + scrollToAndFill(R.id.edittext_first_name, "Oxana"); + scrollToAndFill(R.id.edittext_last_name, "Ermolenko"); + scrollToAndFill(R.id.edittext_address_line_1, "address"); + scrollToAndFill(R.id.edittext_address_city, "Mountain view"); + scrollToAndFill(R.id.edittext_address_state, "CA"); + scrollToAndFill(R.id.edittext_address_zip, "94043"); + + //tap next button + scrollToAndTapNext(); + + //select interest + onView(withText("Chess")) + .perform(click()); + //tap next button + tapNext(); + //first press of 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 activityFinished = false; + try{ + pressBackOnActivity(); + }catch (NoActivityResumedException e){ + activityFinished = true; + } + assertTrue(activityFinished); + } + @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); + + } + + private void checkFieldHasError(int fieldId, int errorId){ + onView(withId(fieldId)) + .check(matches(hasErrorText(resources.getString(errorId)))); + + } } From 3364679295ea551209a28ace31ed348513edc9c8 Mon Sep 17 00:00:00 2001 From: okyska Date: Wed, 6 Sep 2017 10:22:02 -0700 Subject: [PATCH 07/10] added test user sign up personal info verify popup about verification email --- .../signup/EspressoSignUpTest.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java index 15972f0..bc3e4ce 100644 --- a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java @@ -14,6 +14,7 @@ import io.mattcarroll.androidtesting.androidtesting.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; @@ -21,12 +22,19 @@ 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.RootMatchers.isDialog; +import static android.support.test.espresso.matcher.RootMatchers.isPlatformPopup; 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.isRoot; 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.Matchers.allOf; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; /** * Created by oxana on 8/31/2017. @@ -116,6 +124,55 @@ public void userSignUpVerifyBackWorksOnEachPage(){ assertTrue(activityFinished); + } + + @Test + public void userSignUpPersonalInfoVerifyPopupAboutVerificationEmail(){ + + scrollToAndFill(R.id.edittext_first_name, "Oxana"); + scrollToAndFill(R.id.edittext_last_name, "Ermolenko"); + scrollToAndFill(R.id.edittext_address_line_1, "address"); + scrollToAndFill(R.id.edittext_address_city, "Mountain view"); + scrollToAndFill(R.id.edittext_address_state, "CA"); + scrollToAndFill(R.id.edittext_address_zip, "94043"); + + //tap next button + scrollToAndTapNext(); + + //select interest + onData(allOf(is(instanceOf(String.class)),is("Astronomy"))) + .perform(scrollTo()); + onView(withText("Astronomy")) + .perform(scrollTo()) + .perform(click()); + + //tap next button + tapNext(); + + //press back button + pressBackOnActivity(); + + //verify that Astronomy is not checked and check again + onData(allOf(is(instanceOf(String.class)),is("Astronomy"))) + .perform(scrollTo()); + onView(withText("Astronomy")) + .check(matches(isNotChecked())); + onView(withText("Astronomy")) + .perform(click()); + + //tap next button + tapNext(); + + //provide email password + scrollToAndFill(R.id.autocompletetextview_email, "bayqa@yahoo.com"); + scrollToAndFill(R.id.edittext_password, "password"); + + //tap next button + tapNext(); + + + + } @Test From 0af9d5c896c60d809a97dcd9e184caeceec12efa Mon Sep 17 00:00:00 2001 From: okyska Date: Wed, 6 Sep 2017 10:58:46 -0700 Subject: [PATCH 08/10] refactoring scroll list, check for selected and select interest --- .../signup/EspressoSignUpTest.java | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java index bc3e4ce..ba4dfa3 100644 --- a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java @@ -80,12 +80,33 @@ private static void scrollToAndFill(int fieldId, String textToType){ ); } + //scroll list + private static void scrollToForInterest(String itemName) { + onData(allOf(is(instanceOf(String.class)), is(itemName))) + .perform(scrollTo()); + } + + //check checkbox + private static void interestIsNotSelected(String itemName) { + onView(withText(itemName)) + .check(matches(isNotChecked())); + + } + //put checkbox + private static void selectInterest(String itemName){ + onView(withText(itemName)) + .perform(click()); + } + + private static void tapNext(){ onView(withId(R.id.button_next)).perform( click() ); } + + // lesson3_class @Test public void userSignUpVerifyBackWorksOnEachPage(){ scrollToAndFill(R.id.edittext_first_name, "Oxana"); @@ -125,7 +146,7 @@ public void userSignUpVerifyBackWorksOnEachPage(){ } - + //homework lesson3 @Test public void userSignUpPersonalInfoVerifyPopupAboutVerificationEmail(){ @@ -140,11 +161,8 @@ public void userSignUpPersonalInfoVerifyPopupAboutVerificationEmail(){ scrollToAndTapNext(); //select interest - onData(allOf(is(instanceOf(String.class)),is("Astronomy"))) - .perform(scrollTo()); - onView(withText("Astronomy")) - .perform(scrollTo()) - .perform(click()); + scrollToForInterest("Astronomy"); + selectInterest("Astronomy"); //tap next button tapNext(); @@ -152,13 +170,11 @@ public void userSignUpPersonalInfoVerifyPopupAboutVerificationEmail(){ //press back button pressBackOnActivity(); - //verify that Astronomy is not checked and check again - onData(allOf(is(instanceOf(String.class)),is("Astronomy"))) - .perform(scrollTo()); - onView(withText("Astronomy")) - .check(matches(isNotChecked())); - onView(withText("Astronomy")) - .perform(click()); + //verify that Astronomy is not selected and select again + scrollToForInterest("Astronomy"); + interestIsNotSelected("Astronomy"); + selectInterest("Astronomy"); + //tap next button tapNext(); From 4ebd6129c6c5c6396957f921877d25b0e4ebc76c Mon Sep 17 00:00:00 2001 From: okyska Date: Mon, 11 Sep 2017 13:44:41 -0700 Subject: [PATCH 09/10] added assets --- app/src/androidTest/assets/user.properties | 3 + .../mattcarroll/androidtesting/BaseTest.java | 33 ++++ .../{signin => login}/EspressoSignInTest.java | 2 +- .../signup/EspressoSignUpTest.java | 154 +++++++++++------- 4 files changed, 130 insertions(+), 62 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/{signin => login}/EspressoSignInTest.java (96%) diff --git a/app/src/androidTest/assets/user.properties b/app/src/androidTest/assets/user.properties new file mode 100644 index 0000000..41f54c3 --- /dev/null +++ b/app/src/androidTest/assets/user.properties @@ -0,0 +1,3 @@ +name=Oxana +email=oxanaga@bayqa.com +password=bayqa2017 \ 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..26425ed --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/BaseTest.java @@ -0,0 +1,33 @@ +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; + +/** + * Created by max on 9/11/2017. + */ + +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 testAssetManger = InstrumentationRegistry.getContext().getAssets(); + AssetManager.AssetInputStream assetStream = (AssetManager.AssetInputStream) testAssetManger.open("user.properties"); + properties.load(assetStream); + } +} diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signin/EspressoSignInTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/login/EspressoSignInTest.java similarity index 96% rename from app/src/androidTest/java/io/mattcarroll/androidtesting/signin/EspressoSignInTest.java rename to app/src/androidTest/java/io/mattcarroll/androidtesting/login/EspressoSignInTest.java index 40d859c..fd194c8 100644 --- a/app/src/androidTest/java/io/mattcarroll/androidtesting/signin/EspressoSignInTest.java +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/login/EspressoSignInTest.java @@ -1,4 +1,4 @@ -package io.mattcarroll.androidtesting.signin; +package io.mattcarroll.androidtesting.login; import android.support.test.rule.ActivityTestRule; diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java index ba4dfa3..3959a5d 100644 --- a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java @@ -5,14 +5,20 @@ import android.support.test.espresso.NoActivityResumedException; import android.support.test.espresso.action.EspressoKey; 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.Properties; +import java.util.Random; + +import io.mattcarroll.androidtesting.BaseTest; import io.mattcarroll.androidtesting.R; import io.mattcarroll.androidtesting.androidtesting.SignUpActivity; +import static android.R.attr.name; import static android.support.test.espresso.Espresso.closeSoftKeyboard; import static android.support.test.espresso.Espresso.onData; import static android.support.test.espresso.Espresso.onView; @@ -25,6 +31,7 @@ import static android.support.test.espresso.matcher.RootMatchers.isDialog; import static android.support.test.espresso.matcher.RootMatchers.isPlatformPopup; import static android.support.test.espresso.matcher.ViewMatchers.hasErrorText; +import static android.support.test.espresso.matcher.ViewMatchers.isChecked; 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.isRoot; @@ -33,6 +40,7 @@ import static android.view.KeyEvent.KEYCODE_MINUS; import static junit.framework.Assert.assertTrue; import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; @@ -40,7 +48,7 @@ * Created by oxana on 8/31/2017. */ -public class EspressoSignUpTest { +public class EspressoSignUpTest extends BaseTest { @Rule public final ActivityTestRuleactivityRule = new ActivityTestRule<>(SignUpActivity.class, false, true); @@ -59,6 +67,12 @@ private static void scrollToAndTapNext(){ ); } + private static void tapNext(){ + onView(withId(R.id.button_next)).perform( + click() + ); + } + private static void pressBackOnActivity(){ //hide keyboard closeSoftKeyboard(); @@ -80,35 +94,10 @@ private static void scrollToAndFill(int fieldId, String textToType){ ); } - //scroll list - private static void scrollToForInterest(String itemName) { - onData(allOf(is(instanceOf(String.class)), is(itemName))) - .perform(scrollTo()); - } - - //check checkbox - private static void interestIsNotSelected(String itemName) { - onView(withText(itemName)) - .check(matches(isNotChecked())); - - } - //put checkbox - private static void selectInterest(String itemName){ - onView(withText(itemName)) - .perform(click()); - } - - - private static void tapNext(){ - onView(withId(R.id.button_next)).perform( - click() - ); - } - - - // lesson3_class @Test public void userSignUpVerifyBackWorksOnEachPage(){ + + //fill in personal info scrollToAndFill(R.id.edittext_first_name, "Oxana"); scrollToAndFill(R.id.edittext_last_name, "Ermolenko"); scrollToAndFill(R.id.edittext_address_line_1, "address"); @@ -144,12 +133,57 @@ public void userSignUpVerifyBackWorksOnEachPage(){ } assertTrue(activityFinished); + } + + @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); + + } + + private void checkFieldHasError(int fieldId, int errorId){ + onView(withId(fieldId)) + .check(matches(hasErrorText(resources.getString(errorId)))); } + //homework lesson3 + + private static void verifyViewIsChecked (String viewName){ + onView(withText(viewName)) + .check(matches(isChecked())); + } + + private static void verifyViewIsNotChecked (String viewName){ + onView(withText(viewName)) + .check(matches(isNotChecked())); + } + + //scroll list + private static void clickViewOnTheListView(String viewName) { + onData(hasToString(viewName)) + .perform(click()); + } + + private static void scrollToViewOnTheListView(String viewName){ + onData(hasToString(viewName)) + .perform(scrollTo()); + } + @Test - public void userSignUpPersonalInfoVerifyPopupAboutVerificationEmail(){ + public void userChecksAstronomy(){ + + + //filling scrollToAndFill(R.id.edittext_first_name, "Oxana"); scrollToAndFill(R.id.edittext_last_name, "Ermolenko"); scrollToAndFill(R.id.edittext_address_line_1, "address"); @@ -157,12 +191,14 @@ public void userSignUpPersonalInfoVerifyPopupAboutVerificationEmail(){ scrollToAndFill(R.id.edittext_address_state, "CA"); scrollToAndFill(R.id.edittext_address_zip, "94043"); - //tap next button + //scroll and press next scrollToAndTapNext(); - //select interest - scrollToForInterest("Astronomy"); - selectInterest("Astronomy"); + //click Astronomy + clickViewOnTheListView("Astronomy"); + + //check it is checked + verifyViewIsChecked("Astronomy"); //tap next button tapNext(); @@ -170,44 +206,40 @@ public void userSignUpPersonalInfoVerifyPopupAboutVerificationEmail(){ //press back button pressBackOnActivity(); - //verify that Astronomy is not selected and select again - scrollToForInterest("Astronomy"); - interestIsNotSelected("Astronomy"); - selectInterest("Astronomy"); + //scroll list view + scrollToViewOnTheListView("Astronomy"); + //check it is not checked + verifyViewIsNotChecked("Astronomy"); - //tap next button - tapNext(); - - //provide email password - scrollToAndFill(R.id.autocompletetextview_email, "bayqa@yahoo.com"); - scrollToAndFill(R.id.edittext_password, "password"); + //click Astronomy + clickViewOnTheListView("Astronomy"); //tap next button tapNext(); + //fill email + scrollToAndFill(R.id.autocompletetextview_email, getProperties().getProperty("email")); + //fill password + String password = generateRandomPassword(10); + Log.d("info", password); + scrollToAndFill(R.id.edittext_password, getProperties().getProperty("password")); + //click sign in button + tapNext(); } - - @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); - + String generateRandomPassword(int length){ + String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; + 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(); } - private void checkFieldHasError(int fieldId, int errorId){ - onView(withId(fieldId)) - .check(matches(hasErrorText(resources.getString(errorId)))); - - } } From e8cef6c2276a9ac4e983490d9fc34fffe6b0a17f Mon Sep 17 00:00:00 2001 From: okyska Date: Mon, 11 Sep 2017 19:39:47 -0700 Subject: [PATCH 10/10] added test add bank account --- app/src/androidTest/assets/user.properties | 5 +- .../login/EspressoSignInTest.java | 72 ++++++++++++++++++- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/app/src/androidTest/assets/user.properties b/app/src/androidTest/assets/user.properties index 41f54c3..9af67ab 100644 --- a/app/src/androidTest/assets/user.properties +++ b/app/src/androidTest/assets/user.properties @@ -1,3 +1,6 @@ name=Oxana email=oxanaga@bayqa.com -password=bayqa2017 \ No newline at end of file +password=bayqa2017 +bankName=Bank of America +accountNumber=123456789 +passwordForAccount=bankqapassword \ 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 fd194c8..fcb217e 100644 --- a/app/src/androidTest/java/io/mattcarroll/androidtesting/login/EspressoSignInTest.java +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/login/EspressoSignInTest.java @@ -2,9 +2,11 @@ import android.support.test.rule.ActivityTestRule; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import io.mattcarroll.androidtesting.BaseTest; import io.mattcarroll.androidtesting.R; import io.mattcarroll.androidtesting.SplashActivity; @@ -15,12 +17,13 @@ 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; +import static android.support.test.espresso.matcher.ViewMatchers.withText; /** * Created by max on 9/4/2017. */ -public class EspressoSignInTest { +public class EspressoSignInTest extends BaseTest{ @Rule public final ActivityTestRule activityRule = @@ -39,4 +42,71 @@ public void userSignInPersonalInfoRequiredFieldsAreRequired(){ onView(withId(R.id.textview_no_accounts)) .check(matches(isDisplayed())); } + + //homework lesson 4 + + private static void fillFields(int fieldId, String textToType){ + onView(withId(fieldId)).perform( + typeText(textToType) + ); + } + + private static void scrollToButton(int fieldId){ + onView(withId(fieldId)).perform( + scrollTo() + ); + } + + private static void clickButton(int fieldId){ + onView(withId(fieldId)).perform( + click() + ); + } + + private static void checkTextIsDisplayed(String textToCheck) { + onView(withText(textToCheck)).check(matches(isDisplayed()) + ); + } + + @Before + public void SignIn(){ + //fill email + fillFields(R.id.edittext_email, getProperties().getProperty("email")); + + //fill password + fillFields(R.id.edittext_password, getProperties().getProperty("password")); + + //scroll to sign in button + scrollToButton(R.id.button_sign_in); + + //click on sign in button + clickButton(R.id.button_sign_in); + } + + + @Test + public void logInAndAddBankAccount(){ + + + //click on + button + clickButton(R.id.fab_manage_accounts); + + //click on link button + clickButton(R.id.button_link_account); + + //fill bank name + fillFields(R.id.edittext_bank_name, getProperties().getProperty("bankName")); + + //fill bank account number + fillFields(R.id.edittext_account_number, getProperties().getProperty("accountNumber")); + + //fill password for account + fillFields(R.id.edittext_password, getProperties().getProperty("passwordForAccount")); + + // click link button + clickButton(R.id.button_link_account); + + } + + }