Commit 3f462d9a authored by Alfonso Garza's avatar Alfonso Garza Committed by Commit Bot

Fix flaky card nickname tests.

Two main changes to address flakiness:
  1. Scroll to nickname before changing it.
  2. Use grey_replaceText as recommended by EG.

Evolved from previous CL
https://chromium-review.googlesource.com/c/chromium/src/+/2380145

Fixed: 1106766, 1108809
Change-Id: I0acfc0980b95bc657d545c43d1a7e15410485747
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2493423
Commit-Queue: Alfonso Garza <alfonsogarza@google.com>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Cr-Commit-Position: refs/heads/master@{#828014}
parent f4c6e138
......@@ -167,7 +167,7 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) {
// not enabled.
- (void)testAddButtonDisabledOnInvalidNumber {
[[EarlGrey selectElementWithMatcher:CardNumberTextField()]
performAction:grey_typeText(@"1234")];
performAction:grey_replaceText(@"1234")];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardButton()]
assertWithMatcher:grey_allOf(grey_sufficientlyVisible(),
......@@ -178,11 +178,11 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) {
// not enabled.
- (void)testAddButtonDisabledOnInvalidExpiryDate {
[[EarlGrey selectElementWithMatcher:CardNumberTextField()]
performAction:grey_typeText(@"4111111111111111")];
performAction:grey_replaceText(@"4111111111111111")];
[[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()]
performAction:grey_typeText(@"00")];
performAction:grey_replaceText(@"00")];
[[EarlGrey selectElementWithMatcher:YearOfExpiryTextField()]
performAction:grey_typeText(@"0000")];
performAction:grey_replaceText(@"0000")];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardButton()]
assertWithMatcher:grey_allOf(grey_sufficientlyVisible(),
......@@ -191,16 +191,15 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) {
// Tests when a user tries to add an invalid card nickname, the "Add" button is
// not enabled.
// TODO(crbug.com/1108809): Re-enable the test
- (void)DISABLED_testAddButtonDisabledOnInvalidNickname {
- (void)testAddButtonDisabledOnInvalidNickname {
[[EarlGrey selectElementWithMatcher:CardNumberTextField()]
performAction:grey_typeText(@"4111111111111111")];
performAction:grey_replaceText(@"4111111111111111")];
[[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()]
performAction:grey_typeText(@"12")];
performAction:grey_replaceText(@"12")];
[[EarlGrey selectElementWithMatcher:YearOfExpiryTextField()]
performAction:grey_typeText(@"2030")];
performAction:grey_replaceText(@"2030")];
[[EarlGrey selectElementWithMatcher:NicknameTextField()]
performAction:grey_typeText(@"1234")];
performAction:grey_replaceText(@"1234")];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardButton()]
assertWithMatcher:grey_allOf(grey_sufficientlyVisible(),
......@@ -211,11 +210,11 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) {
// enabled.
- (void)testAddButtonEnabledOnEmptyNickname {
[[EarlGrey selectElementWithMatcher:CardNumberTextField()]
performAction:grey_typeText(@"4111111111111111")];
performAction:grey_replaceText(@"4111111111111111")];
[[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()]
performAction:grey_typeText(@"12")];
performAction:grey_replaceText(@"12")];
[[EarlGrey selectElementWithMatcher:YearOfExpiryTextField()]
performAction:grey_typeText(@"2030")];
performAction:grey_replaceText(@"2030")];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardButton()]
assertWithMatcher:grey_allOf(grey_sufficientlyVisible(), grey_enabled(),
......@@ -232,11 +231,11 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) {
}
[AutofillAppInterface clearCreditCardStore];
[[EarlGrey selectElementWithMatcher:CardNumberTextField()]
performAction:grey_typeText(@"4111111111111111")];
performAction:grey_replaceText(@"4111111111111111")];
[[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()]
performAction:grey_typeText(@"12")];
performAction:grey_replaceText(@"12")];
[[EarlGrey selectElementWithMatcher:YearOfExpiryTextField()]
performAction:grey_typeText(@"2999")];
performAction:grey_replaceText(@"2999")];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardButton()]
performAction:grey_tap()];
......@@ -256,18 +255,16 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) {
// Tests when a user add a card with a nickname, the screen is dismissed
// and the new card number appears on the Autofill Credit Card 'Payment Methods'
// screen with the nickname.
// TODO(crbug.com/1109663): Enable the test on iPhone once the bug is fixed.
// TODO(crbug.com/1149306): test flaky on iPads.
- (void)DISABLED_testAddButtonOnValidNickname {
- (void)testAddButtonOnValidNickname {
[AutofillAppInterface clearCreditCardStore];
[[EarlGrey selectElementWithMatcher:CardNumberTextField()]
performAction:grey_typeText(@"4111111111111111")];
performAction:grey_replaceText(@"4111111111111111")];
[[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()]
performAction:grey_typeText(@"12")];
performAction:grey_replaceText(@"12")];
[[EarlGrey selectElementWithMatcher:YearOfExpiryTextField()]
performAction:grey_typeText(@"2999")];
performAction:grey_replaceText(@"2999")];
[[EarlGrey selectElementWithMatcher:NicknameTextField()]
performAction:grey_typeText(@"Fav Card")];
performAction:grey_replaceText(@"Fav Card")];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardButton()]
performAction:grey_tap()];
......@@ -289,7 +286,7 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) {
// Error icon displayed when field is invalid.
[[EarlGrey selectElementWithMatcher:CardNumberTextField()]
performAction:grey_typeText(@"1234")];
performAction:grey_replaceText(@"1234")];
[[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:CardNumberIconView(kErrorIconIdentifier)]
......
......@@ -18,4 +18,7 @@ extern NSString* const kAutofillCreditCardSwitchViewId;
extern NSString* const kAutofillCreditCardManagedViewId;
extern NSString* const kSettingsAddPaymentMethodButtonId;
// Accessibility identifier for the edit card table view.
extern NSString* const kAutofillCreditCardEditTableViewId;
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_AUTOFILL_AUTOFILL_CONSTANTS_H_
......@@ -25,3 +25,6 @@ NSString* const kAutofillPaymentMethodsToolbarId =
@"kAutofillPaymentMethodsToolbarId";
NSString* const kSettingsAddPaymentMethodButtonId =
@"kSettingsAddPaymentMethodButtonId";
NSString* const kAutofillCreditCardEditTableViewId =
@"kAutofillCreditCardEditTableViewId";
......@@ -22,6 +22,7 @@
#import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h"
#import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_constants.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_edit_table_view_controller+protected.h"
#import "ios/chrome/browser/ui/settings/cells/copied_to_chrome_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_edit_item_delegate.h"
......@@ -39,9 +40,6 @@
namespace {
using ::AutofillTypeFromAutofillUIType;
NSString* const kAutofillCreditCardEditTableViewId =
@"kAutofillCreditCardEditTableViewId";
typedef NS_ENUM(NSInteger, SectionIdentifier) {
SectionIdentifierFields = kSectionIdentifierEnumZero,
SectionIdentifierCopiedToChrome,
......
......@@ -45,6 +45,11 @@ id<GREYMatcher> NavigationBarEditButton() {
grey_ancestor(grey_kindOfClass([UINavigationBar class])), nil);
}
// Returns an action to scroll down (swipe up).
id<GREYAction> ScrollDown() {
return grey_scrollInDirection(kGREYDirectionDown, 150);
}
} // namespace
@implementation AutofillEditCreditCardTestCase
......@@ -80,17 +85,7 @@ id<GREYMatcher> NavigationBarEditButton() {
// Tests that editing the credit card nickname is possible.
- (void)testValidNickname {
#if !TARGET_OS_SIMULATOR
// TODO(crbug.com/1108809): These seem to fail on device only downstream,
// iOS 12.4 only.
if (@available(iOS 13, *)) {
} else {
EARL_GREY_TEST_DISABLED(@"Test disabled on iOS12 device.");
}
#endif
[[EarlGrey selectElementWithMatcher:NicknameTextField()]
performAction:grey_replaceText(@"Nickname")];
[self typeNickname:@"Nickname"];
[[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()]
assertWithMatcher:grey_allOf(grey_sufficientlyVisible(), grey_enabled(),
......@@ -102,17 +97,7 @@ id<GREYMatcher> NavigationBarEditButton() {
// Tests that invalid nicknames are not allowed when editing a card.
- (void)testInvalidNickname {
#if !TARGET_OS_SIMULATOR
// TODO(crbug.com/1108809): These seem to fail on device only downstream,
// iOS 12.4 only.
if (@available(iOS 13, *)) {
} else {
EARL_GREY_TEST_DISABLED(@"Test disabled on iOS12 device.");
}
#endif
[[EarlGrey selectElementWithMatcher:NicknameTextField()]
performAction:grey_typeText(@"1233")];
[self typeNickname:@"1233"];
[[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()]
assertWithMatcher:grey_allOf(grey_sufficientlyVisible(),
......@@ -120,10 +105,8 @@ id<GREYMatcher> NavigationBarEditButton() {
}
// Tests that clearing a nickname is allowed.
// TODO(crbug.com/1108809): Re-enable the test.
- (void)DISABLED_testEmptyNickname {
[[EarlGrey selectElementWithMatcher:NicknameTextField()]
performAction:grey_typeText(@"To be removed")];
- (void)testEmptyNickname {
[self typeNickname:@"To be removed"];
[[EarlGrey selectElementWithMatcher:NicknameTextField()]
performAction:grey_clearText()];
......@@ -133,4 +116,14 @@ id<GREYMatcher> NavigationBarEditButton() {
nil)];
}
#pragma mark - Helper methods
// Scrolls to nickname text field and types the string.
- (void)typeNickname:(NSString*)nickname {
[[[EarlGrey selectElementWithMatcher:NicknameTextField()]
usingSearchAction:ScrollDown()
onElementWithMatcher:chrome_test_util::AutofillCreditCardEditTableView()]
performAction:grey_replaceText(nickname)];
}
@end
......@@ -191,6 +191,9 @@ id<GREYMatcher> SettingsDoneButton();
// settings' navigation bar.
id<GREYMatcher> SyncSettingsConfirmButton();
// Returns matcher for the Autofill Credit Card "Payment Methods" edit view.
id<GREYMatcher> AutofillCreditCardEditTableView();
// Returns matcher for the Autofill Credit Card "Payment Methods" view in the
// settings menu.
id<GREYMatcher> AutofillCreditCardTableView();
......
......@@ -249,6 +249,10 @@ id<GREYMatcher> SyncSettingsConfirmButton() {
return [ChromeMatchersAppInterface syncSettingsConfirmButton];
}
id<GREYMatcher> AutofillCreditCardEditTableView() {
return [ChromeMatchersAppInterface autofillCreditCardEditTableView];
}
id<GREYMatcher> AutofillCreditCardTableView() {
return [ChromeMatchersAppInterface autofillCreditCardTableView];
}
......
......@@ -190,6 +190,9 @@
// settings' navigation bar.
+ (id<GREYMatcher>)syncSettingsConfirmButton;
// Returns matcher for the Autofill Credit Card "Payment Methods" edit view.
+ (id<GREYMatcher>)autofillCreditCardEditTableView;
// Returns matcher for the Autofill Credit Card "Payment Methods" view in the
// settings menu.
+ (id<GREYMatcher>)autofillCreditCardTableView;
......
......@@ -471,6 +471,10 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
return grey_accessibilityID(kSyncSettingsConfirmButtonId);
}
+ (id<GREYMatcher>)autofillCreditCardEditTableView {
return grey_accessibilityID(kAutofillCreditCardEditTableViewId);
}
+ (id<GREYMatcher>)addressesAndMoreButton {
return [ChromeMatchersAppInterface
buttonWithAccessibilityLabelID:(IDS_AUTOFILL_ADDRESSES_SETTINGS_TITLE)];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment