Skip to content

Commit a8ecd82

Browse files
authored
HW-53053: Fixing ui tests (#33)
1 parent 3899d12 commit a8ecd82

File tree

5 files changed

+216
-120
lines changed

5 files changed

+216
-120
lines changed

ui/src/androidTest/java/com/hyperwallet/android/transfermethod/ui/AddTransferMethodTest.java

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import static androidx.test.espresso.Espresso.onView;
44
import static androidx.test.espresso.action.ViewActions.click;
5-
import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard;
6-
import static androidx.test.espresso.action.ViewActions.typeText;
5+
import static androidx.test.espresso.action.ViewActions.replaceText;
76
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
87
import static androidx.test.espresso.assertion.ViewAssertions.matches;
98
import static androidx.test.espresso.matcher.RootMatchers.isDialog;
@@ -130,12 +129,9 @@ public void testAddTransferMethod_displaysErrorDialogOnDuplicateAccountFailure()
130129

131130
mActivityTestRule.launchActivity(null);
132131

133-
onView(withId(R.id.branchId))
134-
.perform(typeText(ROUTING_NUMBER)).perform(closeSoftKeyboard());
135-
onView(withId(R.id.bankAccountId))
136-
.perform(typeText(String.valueOf(ACCOUNT_NUMBER)))
137-
.perform(closeSoftKeyboard());
138-
onView(withId(R.id.bankAccountPurpose)).perform(click());
132+
onView(withId(R.id.branchId)).perform(nestedScrollTo(), replaceText(ROUTING_NUMBER));
133+
onView(withId(R.id.bankAccountId)).perform(nestedScrollTo(), replaceText(ACCOUNT_NUMBER));
134+
onView(withId(R.id.bankAccountPurpose)).perform(nestedScrollTo(), click());
139135
onView(allOf(withId(R.id.select_name), withText("Savings"))).perform(click());
140136
onView(withId(R.id.add_transfer_method_button)).perform(nestedScrollTo(), click());
141137

@@ -165,12 +161,9 @@ public void testAddTransferMethod_displaysUnexpectedErrorDialogOnException() {
165161

166162
mActivityTestRule.launchActivity(null);
167163

168-
onView(withId(R.id.branchId)).perform(typeText(ROUTING_NUMBER)).perform(
169-
closeSoftKeyboard());
170-
onView(withId(R.id.bankAccountId))
171-
.perform(typeText(ACCOUNT_NUMBER))
172-
.perform(closeSoftKeyboard());
173-
onView(withId(R.id.bankAccountPurpose)).perform(click());
164+
onView(withId(R.id.branchId)).perform(nestedScrollTo(), replaceText(ROUTING_NUMBER));
165+
onView(withId(R.id.bankAccountId)).perform(nestedScrollTo(), replaceText(ACCOUNT_NUMBER));
166+
onView(withId(R.id.bankAccountPurpose)).perform(nestedScrollTo(), click());
174167
onView(allOf(withId(R.id.select_name), withText("Savings"))).perform(click());
175168

176169
onView(withId(R.id.add_transfer_method_button)).perform(nestedScrollTo(), click());
@@ -193,14 +186,9 @@ public void testAddTransferMethod_displaysNetworkErrorDialogOnConnectionTimeout(
193186

194187
mActivityTestRule.launchActivity(null);
195188

196-
onView(withId(R.id.branchId))
197-
.perform(typeText(ROUTING_NUMBER))
198-
.perform(closeSoftKeyboard());
199-
onView(withId(R.id.bankAccountId))
200-
.perform(typeText(ACCOUNT_NUMBER))
201-
.perform(closeSoftKeyboard());
202-
203-
onView(withId(R.id.bankAccountPurpose)).perform(click());
189+
onView(withId(R.id.branchId)).perform(nestedScrollTo(), replaceText(ROUTING_NUMBER));
190+
onView(withId(R.id.bankAccountId)).perform(nestedScrollTo(), replaceText(ACCOUNT_NUMBER));
191+
onView(withId(R.id.bankAccountPurpose)).perform(nestedScrollTo(), click());
204192
onView(allOf(withId(R.id.select_name), withText("Savings"))).perform(click());
205193

206194
// initiate test

ui/src/androidTest/java/com/hyperwallet/android/transfermethod/ui/BankAccountTest.java

Lines changed: 82 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
import static androidx.test.espresso.Espresso.onView;
44
import static androidx.test.espresso.action.ViewActions.click;
5-
import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard;
6-
import static androidx.test.espresso.action.ViewActions.typeText;
5+
import static androidx.test.espresso.action.ViewActions.replaceText;
76
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
87
import static androidx.test.espresso.assertion.ViewAssertions.matches;
98
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
109
import static androidx.test.espresso.matcher.ViewMatchers.isEnabled;
11-
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
1210
import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
1311
import static androidx.test.espresso.matcher.ViewMatchers.withId;
1412
import static androidx.test.espresso.matcher.ViewMatchers.withParent;
@@ -28,6 +26,7 @@
2826
import static com.hyperwallet.android.model.transfermethod.HyperwalletBankAccount.Purpose.SAVINGS;
2927
import static com.hyperwallet.android.util.EspressoUtils.hasEmptyText;
3028
import static com.hyperwallet.android.util.EspressoUtils.hasErrorText;
29+
import static com.hyperwallet.android.util.EspressoUtils.hasNoErrorText;
3130
import static com.hyperwallet.android.util.EspressoUtils.nestedScrollTo;
3231
import static com.hyperwallet.android.util.EspressoUtils.withHint;
3332

@@ -123,8 +122,9 @@ public void testAddTransferMethod_displaysElementsOnTmcResponse() {
123122
onView(allOf(instanceOf(TextView.class), withParent(withId(R.id.toolbar))))
124123
.check(matches(withText(R.string.title_add_bank_account)));
125124

126-
onView(allOf(withId(R.id.section_header_title), withText("Account Information - United States (USD)"))).check(
127-
matches(isDisplayed()));
125+
onView(allOf(withId(R.id.section_header_title), withText("Account Information - United States (USD)")))
126+
.perform(nestedScrollTo())
127+
.check(matches(isDisplayed()));
128128
onView(withId(R.id.branchId)).perform(nestedScrollTo()).check(matches(isDisplayed()));
129129
onView(withId(R.id.branchIdLabel)).check(matches(isDisplayed()));
130130
onView(withId(R.id.branchIdLabel)).check(matches(withHint("Routing Number")));
@@ -133,11 +133,11 @@ public void testAddTransferMethod_displaysElementsOnTmcResponse() {
133133
onView(withId(R.id.bankAccountIdLabel)).check(matches(withHint("Account Number")));
134134
onView(withId(R.id.bankAccountPurpose)).perform(nestedScrollTo()).check(matches(isDisplayed()));
135135
onView(withId(R.id.bankAccountPurposeLabel)).check(matches(isDisplayed()));
136-
onView(withId(R.id.bankAccountPurposeLabel)).check(
137-
matches(withHint("Account Type")));
136+
onView(withId(R.id.bankAccountPurposeLabel)).check(matches(withHint("Account Type")));
138137

139-
onView(allOf(withId(R.id.section_header_title), withText("Account Holder"))).perform(nestedScrollTo()).check(
140-
matches(isDisplayed()));
138+
onView(allOf(withId(R.id.section_header_title), withText("Account Holder")))
139+
.perform(nestedScrollTo())
140+
.check(matches(isDisplayed()));
141141
onView(withId(R.id.firstName)).perform(nestedScrollTo()).check(matches(isDisplayed()));
142142
onView(withId(R.id.firstNameLabel)).check(matches(isDisplayed()));
143143
onView(withId(R.id.firstNameLabel)).check(matches(withHint("First Name")));
@@ -151,17 +151,19 @@ public void testAddTransferMethod_displaysElementsOnTmcResponse() {
151151
onView(withId(R.id.dateOfBirthLabel)).check(matches(isDisplayed()));
152152
onView(withId(R.id.dateOfBirthLabel)).check(matches(withHint("Date of Birth")));
153153

154-
onView(allOf(withId(R.id.section_header_title), withText("Contact Information"))).perform(
155-
nestedScrollTo()).check(matches(isDisplayed()));
154+
onView(allOf(withId(R.id.section_header_title), withText("Contact Information")))
155+
.perform(nestedScrollTo())
156+
.check(matches(isDisplayed()));
156157
onView(withId(R.id.phoneNumber)).perform(nestedScrollTo()).check(matches(isDisplayed()));
157158
onView(withId(R.id.phoneNumberLabel)).check(matches(isDisplayed()));
158159
onView(withId(R.id.phoneNumberLabel)).check(matches(withHint("Phone Number")));
159160
onView(withId(R.id.mobileNumber)).perform(nestedScrollTo()).check(matches(isDisplayed()));
160161
onView(withId(R.id.mobileNumberLabel)).check(matches(isDisplayed()));
161162
onView(withId(R.id.mobileNumberLabel)).check(matches(withHint("Mobile Number")));
162163

163-
onView(allOf(withId(R.id.section_header_title), withText("Address"))).perform(nestedScrollTo()).check(
164-
matches(isDisplayed()));
164+
onView(allOf(withId(R.id.section_header_title), withText("Address")))
165+
.perform(nestedScrollTo())
166+
.check(matches(isDisplayed()));
165167
onView(withId(R.id.country)).perform(nestedScrollTo()).check(matches(isDisplayed()));
166168
onView(withId(R.id.countryLabel)).check(matches(isDisplayed()));
167169
onView(withId(R.id.countryLabel)).check(matches(withHint("Country")));
@@ -214,7 +216,7 @@ public void testAddTransferMethod_verifyDefaultValues() {
214216
onView(withId(R.id.firstName)).check(matches(withText("Brody")));
215217
onView(withId(R.id.middleName)).check(matches(hasEmptyText()));
216218
onView(withId(R.id.lastName)).check(matches(withText("Nehru")));
217-
onView(withId(R.id.dateOfBirth)).check(matches(withText("2000-01-01")));
219+
onView(withId(R.id.dateOfBirth)).check(matches(withText("January 01, 2000")));
218220

219221
onView(withId(R.id.phoneNumber)).check(matches(withText("+1 604 6666666")));
220222
onView(withId(R.id.mobileNumber)).check(matches(withText("604 666 6666")));
@@ -298,11 +300,9 @@ public void onReceive(Context context, Intent intent) {
298300
LocalBroadcastManager.getInstance(mActivityTestRule.getActivity().getApplicationContext())
299301
.registerReceiver(br, new IntentFilter("ACTION_HYPERWALLET_TRANSFER_METHOD_ADDED"));
300302

301-
onView(withId(R.id.branchId))
302-
.perform(typeText(ROUTING_NUMBER)).perform(closeSoftKeyboard());
303-
onView(withId(R.id.bankAccountId))
304-
.perform(typeText(ACCOUNT_NUMBER)).perform(closeSoftKeyboard());
305-
onView(withId(R.id.bankAccountPurpose)).perform(click());
303+
onView(withId(R.id.branchId)).perform(nestedScrollTo(), replaceText(ROUTING_NUMBER));
304+
onView(withId(R.id.bankAccountId)).perform(nestedScrollTo(), replaceText(ACCOUNT_NUMBER));
305+
onView(withId(R.id.bankAccountPurpose)).perform(nestedScrollTo(), click());
306306
onView(withId(R.id.search_button)).check(doesNotExist());
307307
onView(withId(R.id.input_selection_list)).check(new RecyclerViewCountAssertion(2));
308308
onView(allOf(withId(R.id.select_name), withText("Savings"))).perform(click());
@@ -321,21 +321,53 @@ public void onReceive(Context context, Intent intent) {
321321
@Test
322322
public void testAddTransferMethod_returnsErrorOnInvalidPattern() {
323323
mActivityTestRule.launchActivity(null);
324-
// Number input should not allow non numeric values
325-
onView(withId(R.id.branchId)).perform(typeText("a12-345"));
326-
onView(withId(R.id.branchId)).check(matches(withText("12345")));
324+
325+
onView(withId(R.id.bankAccountId)).perform(nestedScrollTo(), replaceText("ewrd{123"));
326+
onView(withId(R.id.branchId)).perform(nestedScrollTo(), replaceText("{dfghfgh}"));
327+
onView(withId(R.id.firstName)).perform(nestedScrollTo(), replaceText("ewrd{1{2"));
328+
onView(withId(R.id.lastName)).perform(nestedScrollTo(), replaceText("ewrd{1{2345"));
329+
onView(withId(R.id.addressLine1)).perform(nestedScrollTo(), replaceText("950 {G}ranville Street"));
330+
onView(withId(R.id.city)).perform(nestedScrollTo(), replaceText("Vancouve{r}"));
331+
onView(withId(R.id.stateProvince)).perform(nestedScrollTo(), replaceText("df{r}"));
332+
onView(withId(R.id.postalCode)).perform(nestedScrollTo(), replaceText("df{r}"));
333+
334+
onView(withId(R.id.add_transfer_method_button)).perform(nestedScrollTo(), click());
335+
336+
onView(withId(R.id.branchIdLabel))
337+
.check(matches(hasErrorText("is invalid length or format.")));
338+
onView(withId(R.id.bankAccountIdLabel))
339+
.check(matches(hasErrorText("is invalid length or format.")));
340+
onView(withId(R.id.firstNameLabel))
341+
.check(matches(hasErrorText("is invalid length or format.")));
342+
onView(withId(R.id.lastNameLabel))
343+
.check(matches(hasErrorText("is invalid length or format.")));
344+
onView(withId(R.id.addressLine1Label))
345+
.check(matches(hasErrorText("is invalid length or format.")));
346+
onView(withId(R.id.cityLabel))
347+
.check(matches(hasErrorText("is invalid length or format.")));
348+
onView(withId(R.id.stateProvinceLabel))
349+
.check(matches(hasErrorText("is invalid length or format.")));
350+
onView(withId(R.id.postalCodeLabel))
351+
.check(matches(hasErrorText("is invalid length or format.")));
327352
}
328353

329354
@Test
330355
public void testAddTransferMethod_returnsErrorOnInvalidPresence() {
331356
mActivityTestRule.launchActivity(null);
332357

333-
onView(withId(R.id.branchId)).perform(click()).perform(closeSoftKeyboard());
334-
onView(withId(R.id.bankAccountId)).perform(click()).perform(closeSoftKeyboard());
335-
onView(withId(R.id.bankAccountPurpose)).perform(click());
336-
337-
onView(allOf(withContentDescription(R.string.abc_action_bar_up_description),
338-
withParent(withId(R.id.input_selection_toolbar)))).perform(click());
358+
onView(withId(R.id.branchId)).perform(nestedScrollTo(), replaceText(""));
359+
onView(withId(R.id.bankAccountId)).perform(nestedScrollTo(), replaceText(""));
360+
onView(withId(R.id.bankAccountPurpose)).perform(nestedScrollTo(), replaceText(""));
361+
onView(withId(R.id.firstName)).perform(nestedScrollTo(), replaceText(""));
362+
onView(withId(R.id.middleName)).perform(nestedScrollTo(), replaceText(""));
363+
onView(withId(R.id.lastName)).perform(nestedScrollTo(), replaceText(""));
364+
onView(withId(R.id.dateOfBirth)).perform(nestedScrollTo(), replaceText(""));
365+
onView(withId(R.id.phoneNumber)).perform(nestedScrollTo(), replaceText(""));
366+
onView(withId(R.id.mobileNumber)).perform(nestedScrollTo(), replaceText(""));
367+
onView(withId(R.id.addressLine1)).perform(nestedScrollTo(), replaceText(""));
368+
onView(withId(R.id.city)).perform(nestedScrollTo(), replaceText(""));
369+
onView(withId(R.id.stateProvince)).perform(nestedScrollTo(), replaceText(""));
370+
onView(withId(R.id.postalCode)).perform(nestedScrollTo(), replaceText(""));
339371

340372
onView(withId(R.id.add_transfer_method_button)).perform(nestedScrollTo(), click());
341373

@@ -345,16 +377,31 @@ public void testAddTransferMethod_returnsErrorOnInvalidPresence() {
345377
.check(matches(hasErrorText("You must provide a value for this field")));
346378
onView(withId(R.id.bankAccountPurposeLabel))
347379
.check(matches(hasErrorText("You must provide a value for this field")));
380+
onView(withId(R.id.firstNameLabel))
381+
.check(matches(hasErrorText("You must provide a value for this field")));
382+
onView(withId(R.id.lastNameLabel))
383+
.check(matches(hasErrorText("You must provide a value for this field")));
384+
onView(withId(R.id.addressLine1Label))
385+
.check(matches(hasErrorText("You must provide a value for this field")));
386+
onView(withId(R.id.cityLabel))
387+
.check(matches(hasErrorText("You must provide a value for this field")));
388+
onView(withId(R.id.stateProvinceLabel))
389+
.check(matches(hasErrorText("You must provide a value for this field")));
390+
onView(withId(R.id.postalCodeLabel))
391+
.check(matches(hasErrorText("You must provide a value for this field")));
392+
393+
onView(withId(R.id.middleNameLabel)).check(matches(hasNoErrorText()));
394+
onView(withId(R.id.dateOfBirthLabel)).check(matches(hasNoErrorText()));
395+
onView(withId(R.id.phoneNumberLabel)).check(matches(hasNoErrorText()));
396+
onView(withId(R.id.mobileNumberLabel)).check(matches(hasNoErrorText()));
348397
}
349398

350399
@Test
351400
public void testAddTransferMethod_returnsErrorOnInvalidLength() {
352401
mActivityTestRule.launchActivity(null);
353402

354-
onView(withId(R.id.branchId))
355-
.perform(typeText("2111795311")).perform(closeSoftKeyboard());
356-
onView(withId(R.id.bankAccountId))
357-
.perform(typeText("1")).perform(closeSoftKeyboard());
403+
onView(withId(R.id.branchId)).perform(nestedScrollTo(), replaceText("2111795311"));
404+
onView(withId(R.id.bankAccountId)).perform(nestedScrollTo(), replaceText("1"));
358405

359406
onView(withId(R.id.add_transfer_method_button)).perform(nestedScrollTo(), click());
360407

@@ -371,12 +418,9 @@ public void testAddTransferMethod_displaysErrorOnInvalidRoutingNumber() {
371418

372419
mActivityTestRule.launchActivity(null);
373420

374-
onView(withId(R.id.branchId))
375-
.perform(typeText(INVALID_ROUTING_NUMBER)).perform(closeSoftKeyboard());
376-
onView(withId(R.id.bankAccountId))
377-
.perform(typeText(ACCOUNT_NUMBER))
378-
.perform(closeSoftKeyboard());
379-
onView(withId(R.id.bankAccountPurpose)).perform(click());
421+
onView(withId(R.id.branchId)).perform(nestedScrollTo(), replaceText(INVALID_ROUTING_NUMBER));
422+
onView(withId(R.id.bankAccountId)).perform(nestedScrollTo(), replaceText(ACCOUNT_NUMBER));
423+
onView(withId(R.id.bankAccountPurpose)).perform(nestedScrollTo(), click());
380424
onView(allOf(withId(R.id.select_name), withText("Checking"))).perform(click());
381425

382426
onView(withId(R.id.add_transfer_method_button)).perform(nestedScrollTo(), click());

0 commit comments

Comments
 (0)