diff --git a/app/build.gradle b/app/build.gradle index a28f9ea..8cd85c1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -76,4 +76,7 @@ dependencies { // 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/app/src/androidTest/assets/user.properties b/app/src/androidTest/assets/user.properties index f87b97d..e1e78e8 100644 --- a/app/src/androidTest/assets/user.properties +++ b/app/src/androidTest/assets/user.properties @@ -1,3 +1,8 @@ -name=Boris -email=borisqa@bayqa.com -password=bayqa12345 \ No newline at end of file + +name=Oxana +email=oxanaga@bayqa.com +password=bayqa2017 +bankName=Bank of America +accountNumber=123456789 +passwordForAccount=bankqapassword + diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/BaseTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/BaseTest.java index e8be5fb..d622ea2 100644 --- a/app/src/androidTest/java/io/mattcarroll/androidtesting/BaseTest.java +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/BaseTest.java @@ -9,7 +9,7 @@ import java.util.Properties; /** - * Created by borisgurtovyy on 9/7/17. + */ public class BaseTest { @@ -26,8 +26,9 @@ public void setProperties(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"); + + 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/login/EspressoSignInTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/login/EspressoSignInTest.java new file mode 100644 index 0000000..fcb217e --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/login/EspressoSignInTest.java @@ -0,0 +1,112 @@ +package io.mattcarroll.androidtesting.login; + +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; + +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; +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 extends BaseTest{ + + @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(scrollTo()) + .perform(click()); + 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); + + } + + +} 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 b56bf1e..391fc29 100644 --- a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/EspressoSignUpTest.java @@ -6,20 +6,30 @@ import android.support.test.espresso.NoActivityResumedException; import android.support.test.espresso.action.EspressoKey; import android.support.test.rule.ActivityTestRule; + import android.support.test.runner.AndroidJUnit4; + import android.util.Log; import org.junit.Before; import org.junit.Rule; import org.junit.Test; + import org.junit.runner.RunWith; + 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; @@ -29,14 +39,36 @@ 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.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; + + 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.hasToString; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; + +/** + * Created by oxana on 8/31/2017. + */ + +public class EspressoSignUpTest extends BaseTest { + @Rule + public final ActivityTestRuleactivityRule = + import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.hasEntry; @@ -47,34 +79,41 @@ public class EspressoSignUpTest extends BaseTest { @Rule public final ActivityTestRule activityRule = + new ActivityTestRule<>(SignUpActivity.class, false, true); private Resources resources; @Before - public void setup() { - // getTargetContext() operates on the application under test - // getContext() operates on the test APK context + + public void setup() { resources = InstrumentationRegistry.getTargetContext().getResources(); } + private static void scrollToAndTapNext(){ + private static void scrollToAndTapNext() { + onView(withId(R.id.button_next)).perform( scrollTo(), click() ); } + private static void tapNext() { + onView(withId(R.id.button_next)).perform( click() ); } + private static void pressBackOnActivity() { // hide keyboard closeSoftKeyboard(); // press back button + pressBack(); } @@ -93,25 +132,29 @@ private static void scrollToAndFill(int fieldId, String textToType){ } @Test - public void userSignUpVerifyBackWorksOnEachPage() { - // Fill in personal info - scrollToAndFill(R.id.edittext_first_name, "Boris"); - scrollToAndFill(R.id.edittext_last_name, "Gurtovoy"); - scrollToAndFill(R.id.edittext_address_line_1, "my adress 666"); - scrollToAndFill(R.id.edittext_address_city, "Los Angeles"); + + 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"); + scrollToAndFill(R.id.edittext_address_city, "Mountain view"); scrollToAndFill(R.id.edittext_address_state, "CA"); - scrollToAndFill(R.id.edittext_address_zip, "90007"); + scrollToAndFill(R.id.edittext_address_zip, "94043"); + //tap next button scrollToAndTapNext(); - // Select interest + //select interest onView(withText("Chess")) .perform(click()); - // tap next button + //tap next button tapNext(); - // first press of back button + //first press of back button + pressBackOnActivity(); onView(withText("Basketball")) .check(matches(isDisplayed())); @@ -122,6 +165,7 @@ public void userSignUpVerifyBackWorksOnEachPage() { .check(matches(isDisplayed())); boolean activityFinished = false; + try { pressBackOnActivity(); } catch (NoActivityResumedException e){ @@ -133,6 +177,7 @@ public void userSignUpVerifyBackWorksOnEachPage() { @Test public void userSignUpPersonalInfoVerifyRequiredFieldsAreRequired() { // Verify required fields show errors and non-required fields do not. + scrollToAndTapNext(); checkFieldHasError(R.id.edittext_first_name, R.string.input_error_required); @@ -141,58 +186,75 @@ public void userSignUpPersonalInfoVerifyRequiredFieldsAreRequired() { 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 - /*HOMEWORK*/ + private static void verifyViewIsChecked (String viewName){ + } - private void verifyViewIsChecked(String viewName) { + onView(withText(viewName)) .check(matches(isChecked())); } + private void verifyViewIsNotChecked(String viewName) { + onView(withText(viewName)) .check(matches(isNotChecked())); } + + 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 userChecksAstronomy() { + public void userChecksAstronomy(){ - // filling - scrollToAndFill(R.id.edittext_first_name, "Boris"); - scrollToAndFill(R.id.edittext_last_name, "Gurtovoy"); - scrollToAndFill(R.id.edittext_address_line_1, "Some adress"); - scrollToAndFill(R.id.edittext_address_city, "Los Angeles"); + + + //filling + 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, "90007"); + scrollToAndFill(R.id.edittext_address_zip, "94043"); + + //scroll and press next + - // scroll and press next + scrollToAndTapNext(); //click Astronomy clickViewOnTheListView("Astronomy"); + // check it is checked verifyViewIsChecked("Astronomy"); @@ -205,27 +267,34 @@ public void userChecksAstronomy() { scrollToViewOnTheListView("Astronomy"); // check it is NOT checked + verifyViewIsNotChecked("Astronomy"); //click Astronomy clickViewOnTheListView("Astronomy"); + // click next button without scrolling + tapNext(); //fill email scrollToAndFill(R.id.autocompletetextview_email, getProperties().getProperty("email")); + //fill pass + String password = generateRandomPassword(10); Log.d("info", password); scrollToAndFill(R.id.edittext_password, getProperties().getProperty("password")); + //click sign up button tapNext(); } + String generateRandomPassword(int length){ String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; StringBuilder res = new StringBuilder(); @@ -238,4 +307,6 @@ String generateRandomPassword(int length){ return res.toString(); } -} \ No newline at end of file + +} + 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" /> diff --git a/build.gradle b/build.gradle index 5e07d85..71be5d9 100644 --- a/build.gradle +++ b/build.gradle @@ -24,4 +24,4 @@ allprojects { task clean(type: Delete) { delete rootProject.buildDir -} +} \ No newline at end of file