diff --git a/app/build.gradle b/app/build.gradle index a28f9ea..234b074 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,6 +29,7 @@ android { } } + // Force same version as in the app configurations.all { resolutionStrategy { @@ -76,4 +77,6 @@ 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 44ed520..37d0d2c 100644 --- a/app/src/androidTest/assets/user.properties +++ b/app/src/androidTest/assets/user.properties @@ -1,11 +1,11 @@ -name=Boris -last_name=Gurtovoy -address1=my street 666 -city=Los Angeles -state=CA -zip=90007 -email_login=borisqa@bayqa.com -password_login=bayqa12345 -bank_name=Chase -account_number=21367823612765372 -password_bank=password12345 +name = Joy +email = bayQaTraining@email.com +passwordForLogin = password2017 +bankName = Wells Fargo +accountNumber = 00002345234 +passwordForBankAccount = passwordBank +lastName= Taylor +city=San Francisco +street1 = my street +state = CA +zip = 94134 diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/BaseTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/BaseTest.java new file mode 100644 index 0000000..2859d5a --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/BaseTest.java @@ -0,0 +1,37 @@ +package io.mattcarroll.androidtesting.signup; + +import android.content.res.AssetManager; +import android.content.res.Resources; +import android.support.test.InstrumentationRegistry; + +import org.junit.Before; + +import java.io.IOException; +import java.util.Properties; + +/** + * Created by abzalbek on 9/10/17. + */ + +public class BaseTest { + + private Properties properties; + + public Properties getProperties() { + return properties; + } + + public void setProperties(Properties properties) { + this.properties = properties; + } + + // triggering method before tests + @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/signup/PageObjects/BankAccountPage.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/BankAccountPage.java new file mode 100644 index 0000000..885e36f --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/BankAccountPage.java @@ -0,0 +1,53 @@ +package io.mattcarroll.androidtesting.signup.PageObjects; + +import android.support.annotation.NonNull; + +import io.mattcarroll.androidtesting.R; + +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.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 abzalbek on 9/18/17. + */ + +public class BankAccountPage { + public BankAccountPage() { + onView(withId(R.id.edittext_bank_name)) + .check(matches(isDisplayed())); + } + + public BankAccountPage fillBankName(@NonNull String bankName){ + onView(withId(R.id.edittext_bank_name)) + .perform(typeText(bankName)); + return this; + } + + public BankAccountPage fillAccountNumber(@NonNull String accountNumber){ + onView(withId(R.id.edittext_account_number)) + .perform(typeText(accountNumber)); + return this; + } + public BankAccountPage fillPassword(@NonNull String password){ + onView(withId(R.id.edittext_password)) + .perform(typeText(password)); + return this; + } + + public void goBack(){ + closeSoftKeyboard(); + pressBack(); + } + public void pressLinkAccountButton(){ + onView(withId(R.id.button_link_account)) + .perform(click()); + } + + // decided to skip assertation of error!!!! +} diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/CredentialsPage.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/CredentialsPage.java new file mode 100644 index 0000000..94c0403 --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/CredentialsPage.java @@ -0,0 +1,64 @@ +package io.mattcarroll.androidtesting.signup.PageObjects; + +import android.support.annotation.NonNull; + +import io.mattcarroll.androidtesting.R; + +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.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; + +/** + * Created by abzalbek on 9/18/17. + */ + +public class CredentialsPage { + + public CredentialsPage() { + onView(withId(R.id.autocompletetextview_email)).check(matches(isDisplayed())); + } + + public CredentialsPage typeTextToEmailField(String email){ + onView(withId(R.id.autocompletetextview_email)).perform(typeText(email)); + return this; + } + + public CredentialsPage typeTextToPasswordField(String passwrod){ + onView(withId(R.id.edittext_password)).perform(typeText(passwrod)); + return this; + } + + public CredentialsPage assertHasEmailError(@NonNull String error){ + onView(withId(R.id.autocompletetextview_email)) + .check(matches(hasErrorText(error))); + return this; + } + + public CredentialsPage assertHasPasswordError(@NonNull String error){ + onView(withId(R.id.edittext_password)) + .check(matches(hasErrorText(error))); + return this; + } + + public void goBack(){ + closeSoftKeyboard(); + pressBack(); + } + //button_next + public void clickOnSignUPButton(){ + onView(withId(R.id.button_next)) + .perform(click()); + } + + public SignUPSuccesFullPage submitAndSuccess(){ + clickOnSignUPButton(); + return new SignUPSuccesFullPage(); + } + +} diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/HomeActivityPage.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/HomeActivityPage.java new file mode 100644 index 0000000..9e29973 --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/HomeActivityPage.java @@ -0,0 +1,20 @@ +package io.mattcarroll.androidtesting.signup.PageObjects; + +import io.mattcarroll.androidtesting.R; + +import static android.support.test.espresso.Espresso.onView; +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 abzalbek on 9/14/17. + */ + +public class HomeActivityPage { + + public HomeActivityPage() { + + onView(withId(R.id.textview_no_accounts)).check(matches(isDisplayed())); + } +} diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/InterestsPage.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/InterestsPage.java new file mode 100644 index 0000000..5c6c019 --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/InterestsPage.java @@ -0,0 +1,64 @@ +package io.mattcarroll.androidtesting.signup.PageObjects; + + +import android.support.annotation.NonNull; + +import io.mattcarroll.androidtesting.R; + +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; +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.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.hasToString; +import static org.hamcrest.Matchers.is; + +/** + * Created by abzalbek on 9/14/17. + */ + +public class InterestsPage { + public InterestsPage() { + + onView(withId(R.id.listview_interests)).check(matches(isDisplayed())); + } + // very important!!! + public InterestsPage clickOnView(@NonNull String ...interests) { + for (String interest:interests){ + onData(is(interest)).perform(click()); + } + return this; + } + // that one for checking + public static void scrollingListView(String itemName) { + onData(allOf(is(instanceOf(String.class)), is(itemName))).perform( + scrollTo() + ); + } + + public void back() { + pressBack(); + } + + public void pressNext(){ + onView(withId(R.id.button_next)).perform( + click()); + } + + public CredentialsPage submitAndExpectCredendialPage(){ + pressNext(); + return new CredentialsPage(); + } + + public void checkingPopUP(){ + onView(withId(R.id.title_template)).check(matches(isDisplayed())); + } + + +} diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/LinkAccountPage.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/LinkAccountPage.java new file mode 100644 index 0000000..e204d46 --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/LinkAccountPage.java @@ -0,0 +1,39 @@ +package io.mattcarroll.androidtesting.signup.PageObjects; + +import io.mattcarroll.androidtesting.R; + +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.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; + +/** + * Created by abzalbek on 9/18/17. + */ + +public class LinkAccountPage { + public LinkAccountPage() { + onView(withId(R.id.fab_manage_accounts)) + .check(matches(isDisplayed())); + } + + public void goBack() { + closeSoftKeyboard(); + pressBack(); + } + + public ListLinkAccountPage addButton(){ + onView(withId(R.id.fab_manage_accounts)) + .perform(click()); + return new ListLinkAccountPage(); + } + +} + + + + + diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/ListLinkAccountPage.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/ListLinkAccountPage.java new file mode 100644 index 0000000..215d96b --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/ListLinkAccountPage.java @@ -0,0 +1,26 @@ +package io.mattcarroll.androidtesting.signup.PageObjects; + +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.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; + +/** + * Created by abzalbek on 9/18/17. + */ + +public class ListLinkAccountPage { + public ListLinkAccountPage() { + onView(withId(R.id.button_link_account)).check(matches(isDisplayed())); + } + + public BankAccountPage linkAccountButton(){ + onView(withId(R.id.button_link_account)) + .perform(click()); + return new BankAccountPage(); + } + +} diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/LoginPage.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/LoginPage.java new file mode 100644 index 0000000..74cd672 --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/LoginPage.java @@ -0,0 +1,76 @@ +package io.mattcarroll.androidtesting.signup.PageObjects; + +import android.support.annotation.NonNull; + +import io.mattcarroll.androidtesting.R; + +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.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; + +/** + * Created by abzalbek on 9/14/17. + */ + +public class LoginPage { + public LoginPage() { + + onView(withId(R.id.button_sign_in)).check(matches(isDisplayed())); + } + + public LoginPage fillEmail(String email) { + onView(withId(R.id.edittext_email)) + .perform( + scrollTo(), + typeText(email) + ); + return this; + } + + public LoginPage fillPassword(String password) { + onView(withId(R.id.edittext_password)) + .perform( + scrollTo(), + typeText(password) + ); + return this; + } + + public LoginPage assertHasEmailError(@NonNull String error){ + onView(withId(R.id.edittext_email)) + .check(matches(hasErrorText(error))); + return this; + } + + public LoginPage assertHasPasswordError(@NonNull String error){ + onView(withId(R.id.edittext_password)) + .check(matches(hasErrorText(error))); + return this; + } + + public void goBack(){ + closeSoftKeyboard(); + pressBack(); + } + + public void clickSignIN(){ + onView(withId(R.id.button_sign_in)) + .perform( + click() + ); + } + public HomeActivityPage submit(){ + clickSignIN(); + return new HomeActivityPage(); + } + + +} diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/PersonalInfoPage.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/PersonalInfoPage.java new file mode 100644 index 0000000..49e6b8c --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/PersonalInfoPage.java @@ -0,0 +1,146 @@ +package io.mattcarroll.androidtesting.signup.PageObjects; + +import android.support.annotation.NonNull; + +import io.mattcarroll.androidtesting.R; +import io.mattcarroll.androidtesting.signup.BaseTest; + +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.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; + +/** + * Created by abzalbek on 9/14/17. + */ + +public class PersonalInfoPage extends BaseTest { + + public PersonalInfoPage() { + + onView(withId(R.id.edittext_first_name)) + .check(matches(isDisplayed())); + } + + public PersonalInfoPage firstName(@NonNull String firstName) { + + onView(withId(R.id.edittext_first_name)) + .perform( + scrollTo(), + typeText(firstName) + ); + return this; + } + + public PersonalInfoPage lastName(@NonNull String lastName) { + + onView(withId(R.id.edittext_last_name)) + .perform( + scrollTo(), + typeText(lastName) + ); + return this; + } + + public PersonalInfoPage address1(@NonNull String address) { + + onView(withId(R.id.edittext_address_line_1)) + .perform( + scrollTo(), + typeText(address) + ); + return this; + } + + public PersonalInfoPage city(@NonNull String city) { + + onView(withId(R.id.edittext_address_city)) + .perform( + scrollTo(), + typeText(city) + ); + return this; + } + + public PersonalInfoPage state(@NonNull String state) { + + onView(withId(R.id.edittext_address_state)) + .perform( + scrollTo(), + typeText(state) + ); + return this; + } + + public PersonalInfoPage zipcode(@NonNull String zipcode) { + + onView(withId(R.id.edittext_address_zip)) + .perform( + scrollTo(), + typeText(zipcode) + ); + return this; + } + + public void submit() { + onView(withId(R.id.button_next)) + .perform( + scrollTo(), + click() + ); + } + + public InterestsPage submitAndExpectInterestPage() { + submit(); + return new InterestsPage(); + } + + + public void back() { + closeSoftKeyboard(); + pressBack(); + } + + public PersonalInfoPage assertHasFirstNameError(@NonNull String error) { + onView(withId(R.id.edittext_first_name)) + .check(matches(hasErrorText(error))); + return this; + } + + public PersonalInfoPage assertHasLastNameError(@NonNull String error) { + onView(withId(R.id.edittext_last_name)) + .check(matches(hasErrorText(error))); + return this; + } + + public PersonalInfoPage assertHasAddressError(@NonNull String error) { + onView(withId(R.id.edittext_address_line_1)) + .check(matches(hasErrorText(error))); + return this; + } + + public PersonalInfoPage assertHasCityError(@NonNull String error) { + onView(withId(R.id.edittext_address_city)) + .check(matches(hasErrorText(error))); + return this; + } + + public PersonalInfoPage assertHasStateError(@NonNull String error) { + onView(withId(R.id.edittext_address_state)) + .check(matches(hasErrorText(error))); + return this; + } + + public PersonalInfoPage assertHasZipCodeError(@NonNull String error) { + onView(withId(R.id.edittext_address_zip)) + .check(matches(hasErrorText(error))); + return this; + } + +} diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/SignUPSuccesFullPage.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/SignUPSuccesFullPage.java new file mode 100644 index 0000000..25d15e6 --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/PageObjects/SignUPSuccesFullPage.java @@ -0,0 +1,18 @@ +package io.mattcarroll.androidtesting.signup.PageObjects; + +import io.mattcarroll.androidtesting.R; + +import static android.support.test.espresso.Espresso.onView; +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 abzalbek on 9/18/17. + */ + +public class SignUPSuccesFullPage { + public SignUPSuccesFullPage() { + onView(withId(R.id.progress)).check(matches(isDisplayed())); + } +} diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/accounts/LinkAccountTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/accounts/LinkAccountTest.java new file mode 100644 index 0000000..521c749 --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/accounts/LinkAccountTest.java @@ -0,0 +1,140 @@ +package io.mattcarroll.androidtesting.signup.accounts; + +import android.support.test.espresso.contrib.RecyclerViewActions; +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 io.mattcarroll.androidtesting.signup.BaseTest; +import io.mattcarroll.androidtesting.signup.PageObjects.BankAccountPage; +import io.mattcarroll.androidtesting.signup.PageObjects.LinkAccountPage; +import io.mattcarroll.androidtesting.signup.PageObjects.ListLinkAccountPage; +import io.mattcarroll.androidtesting.signup.PageObjects.LoginPage; + +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.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.hasDescendant; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.Matchers.allOf; + +/** + * Created by abzalbek on 9/12/17. + */ + +public class LinkAccountTest extends BaseTest { + + @Rule + + public final ActivityTestRule activityRule = + new ActivityTestRule(SplashActivity.class, false, true); + + public static void clickOnItem(int fieldID) { + onView(withId(fieldID)).perform( + click() + ); + } + + public static void typeTextIntoTextField(int fieldID, String text) { + onView(withId(fieldID)) + .perform(typeText(text)); + } + + public static void scrollAndClickOnItem(int filedID) { + onView(withId(filedID)).perform( + scrollTo(), + click() + ); + } + + public static void goToOverViewScreen() { + closeSoftKeyboard(); + pressBack(); + } + + // verification on recycler view, very important!!! + public void verifyLastFourDigits() { + String accountNumber = getProperties().getProperty("accountNumber"); + // cutting string + String acountNumberLastFourDigits = accountNumber.substring(accountNumber.length() - 4, accountNumber.length()); + + // finding recycleView !!! neeed to go over!!! + onView(withId(R.id.recyclerview_accounts)) + .perform(RecyclerViewActions.scrollTo( + hasDescendant(withText(acountNumberLastFourDigits)))) + .check(matches(allOf( + hasDescendant(allOf( + withId(R.id.textview_account_last_digits), + withText(acountNumberLastFourDigits)))))); + } + + public void login() { + typeTextIntoTextField(R.id.edittext_email, getProperties().getProperty("email")); + typeTextIntoTextField(R.id.edittext_password, getProperties().getProperty("passwordForLogin")); + scrollAndClickOnItem(R.id.button_sign_in); + } + + @Test + public void linkingBankAccount() { + + login(); + + //click "+" + clickOnItem(R.id.fab_manage_accounts); + + //click "link account" + clickOnItem(R.id.button_link_account); + + //type bank name + typeTextIntoTextField(R.id.edittext_bank_name, getProperties().getProperty("bankName")); + + //type account number + typeTextIntoTextField(R.id.edittext_account_number, getProperties().getProperty("accountNumber")); + + // type password + typeTextIntoTextField(R.id.edittext_password, getProperties().getProperty("passwordForBankAccount")); + + //click "link account" + clickOnItem(R.id.button_link_account); + + //pressBack + goToOverViewScreen(); + //sdghrhh + + // verification last 4 digits of account number + verifyLastFourDigits(); + } + + @Test + public void linkAccountTextPO() { + + new LoginPage() + .fillEmail(getProperties().getProperty("email")) + .fillPassword(getProperties().getProperty("passwordForLogin")) + .submit(); + + new LinkAccountPage() + .addButton(); + + new ListLinkAccountPage() + .linkAccountButton(); + + BankAccountPage bankAccountPage = new BankAccountPage() + .fillBankName(getProperties().getProperty("bankName")) + .fillAccountNumber(getProperties().getProperty("accountNumber")) + .fillPassword(getProperties().getProperty("passwordForBankAccount")); + + bankAccountPage.pressLinkAccountButton(); + + + } + +} diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/login/EspressoSignInTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/login/EspressoSignInTest.java new file mode 100644 index 0000000..80ee305 --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/login/EspressoSignInTest.java @@ -0,0 +1,142 @@ +package io.mattcarroll.androidtesting.signup.login; + +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; + +import io.mattcarroll.androidtesting.R; +import io.mattcarroll.androidtesting.SplashActivity; +import io.mattcarroll.androidtesting.home.HomeActivity; +import io.mattcarroll.androidtesting.signup.BaseTest; +import io.mattcarroll.androidtesting.signup.PageObjects.HomeActivityPage; +import io.mattcarroll.androidtesting.signup.PageObjects.LoginPage; + +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; + +/** + * Created by abzalbek on 8/31/17. + */ + +public class EspressoSignInTest extends BaseTest { + + @Rule + + + public final ActivityTestRule activityRule = + new ActivityTestRule<>(SplashActivity.class, false, true); + private Resources resources; + + @Before + public void setUp() { + resources = InstrumentationRegistry.getTargetContext().getResources(); + } + + @Test + public void usersSignInPersonalInfoRequiredFieldAreFilled() { + onView(withId(R.id.edittext_email)) + .perform(typeText("bayQATraining@email.com")); + onView(withId(R.id.edittext_password)) + .perform(typeText("Password2017")); + onView(withId(R.id.button_sign_in)).perform(click()); + onView(withId(R.id.textview_no_accounts)).check(matches(isDisplayed())); + + } + + /*----------------HOMEWORK----------------*/ + + private static void typeTextOnfield(int fieldID, String text) { + onView(withId(fieldID)).perform( + typeText(text) + ); + } + + private static void scrollAndclickOn(int fieldID) { + onView(withId(fieldID)).perform( + scrollTo(), + click() + ); + } + + private static void clickOn(int fieldID) { + onView(withId(fieldID)).perform( + click() + ); + } + + private static void checkTextOnView(int text) { + onView(withId(text)).check(matches(isDisplayed())); + } +/* + @Before + public void logIn() { + // filling email + typeTextOnfield(R.id.edittext_email, getProperties().getProperty("email")); + + //filliing password + typeTextOnfield(R.id.edittext_password, getProperties().getProperty("passwordForLogin")); + + //clicking + scrollAndclickOn(R.id.button_sign_in); + + } +*/ + @Test + + public void addingBankAccount() { + + // click on + + clickOn(R.id.fab_manage_accounts); + + //click "link" + clickOn(R.id.button_link_account); + + // filling bank name + typeTextOnfield(R.id.edittext_bank_name, getProperties().getProperty("bankName")); + + //filling bank account number + typeTextOnfield(R.id.edittext_account_number, getProperties().getProperty("accountNumber")); + + // filling passwrod for bank account + typeTextOnfield(R.id.edittext_password, getProperties().getProperty("passwordForBankAccount")); + + //click linkAccount + clickOn(R.id.button_link_account); + + } + // with PAGE OBJECS!!!! + @Test + public void loginWithPageObject() { + + LoginPage loginPage = new LoginPage() + .fillEmail(getProperties().getProperty("email")) + .fillPassword(getProperties().getProperty("passwordForLogin")); + + HomeActivityPage homeActivityPage = loginPage.submit(); + } + // negative test + @Test + + public void checkError(){ + final String REQUIRED_FIELD_ERROR = "This field is required"; + + + LoginPage loginPage = new LoginPage(); + loginPage.clickSignIN(); + + loginPage + .assertHasEmailError(REQUIRED_FIELD_ERROR) + .assertHasPasswordError(REQUIRED_FIELD_ERROR); + } + + +} diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/signUp/EspressoSignUpTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/signUp/EspressoSignUpTest.java new file mode 100644 index 0000000..a307c8b --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/signUp/EspressoSignUpTest.java @@ -0,0 +1,300 @@ +package io.mattcarroll.androidtesting.signup.signUp; + + +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 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.Random; + +import io.mattcarroll.androidtesting.R; +import io.mattcarroll.androidtesting.signup.BaseTest; +import io.mattcarroll.androidtesting.signup.PageObjects.InterestsPage; +import io.mattcarroll.androidtesting.signup.PageObjects.PersonalInfoPage; +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; +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.RootMatchers.isDialog; +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.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.instanceOf; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.hasToString; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; + +/** + * Created by abzalbek on 8/29/17. + */ +@RunWith(AndroidJUnit4.class) +public class EspressoSignUpTest extends BaseTest { + + @Rule + public final ActivityTestRule activityRule = + new ActivityTestRule<>(SignUpActivity.class, false, true); + + private Resources resources; + + @Before + public void setup() { + resources = InstrumentationRegistry.getTargetContext().getResources(); + } + + // scroll and tap next button + private void scrollToAndTapNext() { + onView(withId(R.id.button_next)).perform( + scrollTo(), + click() + ); + } + + // click next button + private void tapNext() { + onView(withId(R.id.button_next)).perform( + click() + ); + } + + // checking error + private void checkFieldHasError(int filedId, int errorId) { + onView(withId(filedId)) + .check(matches(hasErrorText(resources.getString(errorId)))); + } + + // press back button + private static void pressBackOnActivity() { + //hide keyboard + closeSoftKeyboard(); + // press back button + pressBack(); + } + + //scroll and fill, typing with code + 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) + ); + } + + // select item with text + private void selectItemWithText(String itemName) { + onView(withText(itemName)).perform( + click() + ); + } + + // checking item with text + private void checkItemWithTextDisplayed(String itemName) { + onView(withText(itemName)) + .check(matches(isDisplayed())); + } + + //checking item with ID + private void checkitemWithIdDisplayed(int itemName) { + onView(withId(itemName)) + .check(matches(isDisplayed())); + } + + //checking item with text(is not checked) + private void checkItemWithTextIsNotChecked(String itemName) { + onView(withText(itemName)) + .check(matches(isNotChecked())); + } + + + //checking item with text(is checked) + private void checkItemWithTextIsChecked(String itemName) { + onView(withText(itemName)) + .check(matches(isChecked())); + } + + + // scrolling list view , finding element with text (need to ask!!!) + private static void scrollingListView(String itemName) { + onData(allOf(is(instanceOf(String.class)), is(itemName))).perform( + scrollTo() + ); + } + + // methods that scroll and click view on listView,(tutor) + private static void clickViewOnTheListView(String viewName) { + onData(hasToString(viewName)) + .perform(click()); + } + + //checking popup with text + private void checkPopupWithText(String itemName) { + onView(withText(itemName)) + .inRoot(isDialog()) + .check(matches(isDisplayed())); + } + + // catching exception(need to go over again) + private static void catchingException() { + // catching exception + boolean activityFinished = false; + try { + pressBackOnActivity(); + } catch (NoActivityResumedException e) { + activityFinished = true; + } + assertTrue(activityFinished); + } + + @Test + public void usersSignUpPersonalInfoVerifyRequiredFieldsAreRequired() { + + /* + 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); + */ + + + } + + @Test + public void userSignUpVerifyBackWorksOnEachPage() { + // filling + scrollToAndFill(R.id.edittext_first_name, "Joe"); + scrollToAndFill(R.id.edittext_last_name, "Taylor"); + scrollToAndFill(R.id.edittext_address_line_1, "Star ave"); + scrollToAndFill(R.id.edittext_address_city, "SanJose"); + scrollToAndFill(R.id.edittext_address_state, "CA"); + scrollToAndFill(R.id.edittext_address_zip, "90003"); + + // scrolling and tap next button + scrollToAndTapNext(); + + // Select chess + selectItemWithText("Chess"); + + // click next button without scrolling + tapNext(); + + // pressing back button + pressBackOnActivity(); + + //checking item + checkItemWithTextDisplayed("Basketball"); + + //second time press back button + pressBackOnActivity(); + + // checking "first name" + checkitemWithIdDisplayed(R.id.edittext_first_name); + + //catching exception + catchingException(); + } + + /*HOMEWORK*/ + @Test + public void usersInfoPressNextBackButtonsCheckAndVerifyPopup() { + + Log.d("info", "My name is " + getProperties().getProperty("name")); + // filling + scrollToAndFill(R.id.edittext_first_name, "Joe"); + scrollToAndFill(R.id.edittext_last_name, "Taylor"); + scrollToAndFill(R.id.edittext_address_line_1, "Star ave"); + scrollToAndFill(R.id.edittext_address_city, "SanJose"); + scrollToAndFill(R.id.edittext_address_state, "CA"); + scrollToAndFill(R.id.edittext_address_zip, "90003"); + + // scrolling and tap next button + scrollToAndTapNext(); + + + /* + //scrolling and clicking checkbox + scrollingListView("Astronomy"); + selectItemWithText("Astronomy"); + //onView(withText("Astronomy")) + */ + + + // clicking onView on listView by tutor !!!!!!!!!!!!! no need to scroll to a view + clickViewOnTheListView("Astronomy"); + + // checking view isChecked + checkItemWithTextIsChecked("Astronomy"); + + // click next button without scrolling + tapNext(); + + // pressing back button + pressBackOnActivity(); + + // checkin checkbox + scrollingListView("Astronomy"); + checkItemWithTextIsNotChecked("Astronomy"); + + //clicking checkbox + selectItemWithText("Astronomy"); + + // click next button without scrolling + tapNext(); + + // providing email and password + scrollToAndFill(R.id.autocompletetextview_email, getProperties().getProperty("email")); + + // generating random password + String password = generateRandomPassword(10); + Log.d("info", "MY PASSWORD IS ===>" + password); + scrollToAndFill(R.id.edittext_password, getProperties().getProperty("password")); + + // click next button without scrolling + tapNext(); + + } + + //generating random string from giving base ! + 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(); + } + + +} diff --git a/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/signUp/PageObjectSignUpTest.java b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/signUp/PageObjectSignUpTest.java new file mode 100644 index 0000000..7369887 --- /dev/null +++ b/app/src/androidTest/java/io/mattcarroll/androidtesting/signup/signUp/PageObjectSignUpTest.java @@ -0,0 +1,120 @@ +package io.mattcarroll.androidtesting.signup.signUp; + +import android.content.res.Resources; +import android.support.test.InstrumentationRegistry; +import android.support.test.rule.ActivityTestRule; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import io.mattcarroll.androidtesting.R; +import io.mattcarroll.androidtesting.signup.BaseTest; +import io.mattcarroll.androidtesting.signup.PageObjects.CredentialsPage; +import io.mattcarroll.androidtesting.signup.PageObjects.InterestsPage; +import io.mattcarroll.androidtesting.signup.PageObjects.PersonalInfoPage; +import io.mattcarroll.androidtesting.signup.SignUpActivity; +import io.mattcarroll.androidtesting.usersession.UserSession; + +/** + * Created by abzalbek on 9/18/17. + */ + +public class PageObjectSignUpTest extends BaseTest { + + @Rule + public final ActivityTestRule activityRule + = new ActivityTestRule<>(SignUpActivity.class, false, true); + + private Resources resources; + + + @Before + public void setUp() { + resources = InstrumentationRegistry.getTargetContext().getResources(); + } + + @After + public void tearDown() { + UserSession.getInstance().logout(); + } + + //positive test + @Test + public void userSignUpHappyPathPO() { + final String REQUIRED_FIELD_ERROR = resources.getString(R.string.input_error_required); + + // filling of field by using pageObjects + new PersonalInfoPage() + .firstName(getProperties().getProperty("name")) + .lastName(getProperties().getProperty("lastName")) + .address1(getProperties().getProperty("street1")) + .city(getProperties().getProperty("city")) + .state(getProperties().getProperty("state")) + .zipcode(getProperties().getProperty("zip")) + .submitAndExpectInterestPage(); + + // next page + new InterestsPage() + .clickOnView("Snowboarding") + .clickOnView("Chess") + .clickOnView("Astronomy") + .submitAndExpectCredendialPage(); + + // next page + CredentialsPage credentialsPage = new CredentialsPage(); + + credentialsPage.clickOnSignUPButton(); + credentialsPage + .assertHasEmailError(REQUIRED_FIELD_ERROR) + .assertHasPasswordError(REQUIRED_FIELD_ERROR); + + } + + //negative test + @Test + public void userSignUpPersonalInfoVerifyRequiredFieldsAreRequiredPO() { + final String REQUIRED_FIELD_ERROR = resources.getString(R.string.input_error_required); + + // creating constructor + PersonalInfoPage personalInfoPage = new PersonalInfoPage(); + // pressing "next" button + personalInfoPage.submit(); + // assertation of requred field(error) + personalInfoPage + .assertHasFirstNameError(REQUIRED_FIELD_ERROR) + .assertHasLastNameError(REQUIRED_FIELD_ERROR) + .assertHasAddressError(REQUIRED_FIELD_ERROR) + .assertHasCityError(REQUIRED_FIELD_ERROR) + .assertHasStateError(REQUIRED_FIELD_ERROR) + .assertHasZipCodeError(REQUIRED_FIELD_ERROR); + + } + + // way to get all steps from beginning (positive test) + @Test + public void userSignUpHappyPath2PO() { + final String REQUIRED_FIELD_ERROR = resources.getString(R.string.input_error_required); + + // filling of field by using pageObjects + new PersonalInfoPage() + .firstName(getProperties().getProperty("name")) + .lastName(getProperties().getProperty("lastName")) + .address1(getProperties().getProperty("street1")) + .city(getProperties().getProperty("city")) + .state(getProperties().getProperty("state")) + .zipcode(getProperties().getProperty("zip")) + .submitAndExpectInterestPage(); + + new InterestsPage() + .clickOnView("Snowboarding", "Astronomy") + .submitAndExpectCredendialPage(); + + new CredentialsPage() + .typeTextToEmailField(getProperties().getProperty("email")) + .typeTextToPasswordField(getProperties().getProperty("passwordForLogin")) + .submitAndSuccess(); + } + +} diff --git a/build.gradle b/build.gradle index 5e07d85..571df81 100644 --- a/build.gradle +++ b/build.gradle @@ -16,9 +16,10 @@ allprojects { repositories { jcenter() maven { url "https://jitpack.io" } - maven { - url "https://maven.google.com" - } + maven { url "https://maven.google.com" } + + + } }