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) { ...@@ -167,7 +167,7 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) {
// not enabled. // not enabled.
- (void)testAddButtonDisabledOnInvalidNumber { - (void)testAddButtonDisabledOnInvalidNumber {
[[EarlGrey selectElementWithMatcher:CardNumberTextField()] [[EarlGrey selectElementWithMatcher:CardNumberTextField()]
performAction:grey_typeText(@"1234")]; performAction:grey_replaceText(@"1234")];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardButton()]
assertWithMatcher:grey_allOf(grey_sufficientlyVisible(), assertWithMatcher:grey_allOf(grey_sufficientlyVisible(),
...@@ -178,11 +178,11 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) { ...@@ -178,11 +178,11 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) {
// not enabled. // not enabled.
- (void)testAddButtonDisabledOnInvalidExpiryDate { - (void)testAddButtonDisabledOnInvalidExpiryDate {
[[EarlGrey selectElementWithMatcher:CardNumberTextField()] [[EarlGrey selectElementWithMatcher:CardNumberTextField()]
performAction:grey_typeText(@"4111111111111111")]; performAction:grey_replaceText(@"4111111111111111")];
[[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()] [[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()]
performAction:grey_typeText(@"00")]; performAction:grey_replaceText(@"00")];
[[EarlGrey selectElementWithMatcher:YearOfExpiryTextField()] [[EarlGrey selectElementWithMatcher:YearOfExpiryTextField()]
performAction:grey_typeText(@"0000")]; performAction:grey_replaceText(@"0000")];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardButton()]
assertWithMatcher:grey_allOf(grey_sufficientlyVisible(), assertWithMatcher:grey_allOf(grey_sufficientlyVisible(),
...@@ -191,16 +191,15 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) { ...@@ -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 // Tests when a user tries to add an invalid card nickname, the "Add" button is
// not enabled. // not enabled.
// TODO(crbug.com/1108809): Re-enable the test - (void)testAddButtonDisabledOnInvalidNickname {
- (void)DISABLED_testAddButtonDisabledOnInvalidNickname {
[[EarlGrey selectElementWithMatcher:CardNumberTextField()] [[EarlGrey selectElementWithMatcher:CardNumberTextField()]
performAction:grey_typeText(@"4111111111111111")]; performAction:grey_replaceText(@"4111111111111111")];
[[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()] [[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()]
performAction:grey_typeText(@"12")]; performAction:grey_replaceText(@"12")];
[[EarlGrey selectElementWithMatcher:YearOfExpiryTextField()] [[EarlGrey selectElementWithMatcher:YearOfExpiryTextField()]
performAction:grey_typeText(@"2030")]; performAction:grey_replaceText(@"2030")];
[[EarlGrey selectElementWithMatcher:NicknameTextField()] [[EarlGrey selectElementWithMatcher:NicknameTextField()]
performAction:grey_typeText(@"1234")]; performAction:grey_replaceText(@"1234")];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardButton()]
assertWithMatcher:grey_allOf(grey_sufficientlyVisible(), assertWithMatcher:grey_allOf(grey_sufficientlyVisible(),
...@@ -211,11 +210,11 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) { ...@@ -211,11 +210,11 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) {
// enabled. // enabled.
- (void)testAddButtonEnabledOnEmptyNickname { - (void)testAddButtonEnabledOnEmptyNickname {
[[EarlGrey selectElementWithMatcher:CardNumberTextField()] [[EarlGrey selectElementWithMatcher:CardNumberTextField()]
performAction:grey_typeText(@"4111111111111111")]; performAction:grey_replaceText(@"4111111111111111")];
[[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()] [[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()]
performAction:grey_typeText(@"12")]; performAction:grey_replaceText(@"12")];
[[EarlGrey selectElementWithMatcher:YearOfExpiryTextField()] [[EarlGrey selectElementWithMatcher:YearOfExpiryTextField()]
performAction:grey_typeText(@"2030")]; performAction:grey_replaceText(@"2030")];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardButton()]
assertWithMatcher:grey_allOf(grey_sufficientlyVisible(), grey_enabled(), assertWithMatcher:grey_allOf(grey_sufficientlyVisible(), grey_enabled(),
...@@ -232,11 +231,11 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) { ...@@ -232,11 +231,11 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) {
} }
[AutofillAppInterface clearCreditCardStore]; [AutofillAppInterface clearCreditCardStore];
[[EarlGrey selectElementWithMatcher:CardNumberTextField()] [[EarlGrey selectElementWithMatcher:CardNumberTextField()]
performAction:grey_typeText(@"4111111111111111")]; performAction:grey_replaceText(@"4111111111111111")];
[[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()] [[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()]
performAction:grey_typeText(@"12")]; performAction:grey_replaceText(@"12")];
[[EarlGrey selectElementWithMatcher:YearOfExpiryTextField()] [[EarlGrey selectElementWithMatcher:YearOfExpiryTextField()]
performAction:grey_typeText(@"2999")]; performAction:grey_replaceText(@"2999")];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardButton()]
performAction:grey_tap()]; performAction:grey_tap()];
...@@ -256,18 +255,16 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) { ...@@ -256,18 +255,16 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) {
// Tests when a user add a card with a nickname, the screen is dismissed // 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' // and the new card number appears on the Autofill Credit Card 'Payment Methods'
// screen with the nickname. // screen with the nickname.
// TODO(crbug.com/1109663): Enable the test on iPhone once the bug is fixed. - (void)testAddButtonOnValidNickname {
// TODO(crbug.com/1149306): test flaky on iPads.
- (void)DISABLED_testAddButtonOnValidNickname {
[AutofillAppInterface clearCreditCardStore]; [AutofillAppInterface clearCreditCardStore];
[[EarlGrey selectElementWithMatcher:CardNumberTextField()] [[EarlGrey selectElementWithMatcher:CardNumberTextField()]
performAction:grey_typeText(@"4111111111111111")]; performAction:grey_replaceText(@"4111111111111111")];
[[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()] [[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()]
performAction:grey_typeText(@"12")]; performAction:grey_replaceText(@"12")];
[[EarlGrey selectElementWithMatcher:YearOfExpiryTextField()] [[EarlGrey selectElementWithMatcher:YearOfExpiryTextField()]
performAction:grey_typeText(@"2999")]; performAction:grey_replaceText(@"2999")];
[[EarlGrey selectElementWithMatcher:NicknameTextField()] [[EarlGrey selectElementWithMatcher:NicknameTextField()]
performAction:grey_typeText(@"Fav Card")]; performAction:grey_replaceText(@"Fav Card")];
[[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::AddCreditCardButton()]
performAction:grey_tap()]; performAction:grey_tap()];
...@@ -289,7 +286,7 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) { ...@@ -289,7 +286,7 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) {
// Error icon displayed when field is invalid. // Error icon displayed when field is invalid.
[[EarlGrey selectElementWithMatcher:CardNumberTextField()] [[EarlGrey selectElementWithMatcher:CardNumberTextField()]
performAction:grey_typeText(@"1234")]; performAction:grey_replaceText(@"1234")];
[[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()] [[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:CardNumberIconView(kErrorIconIdentifier)] [[EarlGrey selectElementWithMatcher:CardNumberIconView(kErrorIconIdentifier)]
......
...@@ -18,4 +18,7 @@ extern NSString* const kAutofillCreditCardSwitchViewId; ...@@ -18,4 +18,7 @@ extern NSString* const kAutofillCreditCardSwitchViewId;
extern NSString* const kAutofillCreditCardManagedViewId; extern NSString* const kAutofillCreditCardManagedViewId;
extern NSString* const kSettingsAddPaymentMethodButtonId; 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_ #endif // IOS_CHROME_BROWSER_UI_SETTINGS_AUTOFILL_AUTOFILL_CONSTANTS_H_
...@@ -25,3 +25,6 @@ NSString* const kAutofillPaymentMethodsToolbarId = ...@@ -25,3 +25,6 @@ NSString* const kAutofillPaymentMethodsToolbarId =
@"kAutofillPaymentMethodsToolbarId"; @"kAutofillPaymentMethodsToolbarId";
NSString* const kSettingsAddPaymentMethodButtonId = NSString* const kSettingsAddPaymentMethodButtonId =
@"kSettingsAddPaymentMethodButtonId"; @"kSettingsAddPaymentMethodButtonId";
NSString* const kAutofillCreditCardEditTableViewId =
@"kAutofillCreditCardEditTableViewId";
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h" #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/application_commands.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.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/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/settings/cells/copied_to_chrome_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_edit_item_delegate.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_text_edit_item_delegate.h"
...@@ -39,9 +40,6 @@ ...@@ -39,9 +40,6 @@
namespace { namespace {
using ::AutofillTypeFromAutofillUIType; using ::AutofillTypeFromAutofillUIType;
NSString* const kAutofillCreditCardEditTableViewId =
@"kAutofillCreditCardEditTableViewId";
typedef NS_ENUM(NSInteger, SectionIdentifier) { typedef NS_ENUM(NSInteger, SectionIdentifier) {
SectionIdentifierFields = kSectionIdentifierEnumZero, SectionIdentifierFields = kSectionIdentifierEnumZero,
SectionIdentifierCopiedToChrome, SectionIdentifierCopiedToChrome,
......
...@@ -45,6 +45,11 @@ id<GREYMatcher> NavigationBarEditButton() { ...@@ -45,6 +45,11 @@ id<GREYMatcher> NavigationBarEditButton() {
grey_ancestor(grey_kindOfClass([UINavigationBar class])), nil); grey_ancestor(grey_kindOfClass([UINavigationBar class])), nil);
} }
// Returns an action to scroll down (swipe up).
id<GREYAction> ScrollDown() {
return grey_scrollInDirection(kGREYDirectionDown, 150);
}
} // namespace } // namespace
@implementation AutofillEditCreditCardTestCase @implementation AutofillEditCreditCardTestCase
...@@ -80,17 +85,7 @@ id<GREYMatcher> NavigationBarEditButton() { ...@@ -80,17 +85,7 @@ id<GREYMatcher> NavigationBarEditButton() {
// Tests that editing the credit card nickname is possible. // Tests that editing the credit card nickname is possible.
- (void)testValidNickname { - (void)testValidNickname {
#if !TARGET_OS_SIMULATOR [self typeNickname:@"Nickname"];
// 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")];
[[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()]
assertWithMatcher:grey_allOf(grey_sufficientlyVisible(), grey_enabled(), assertWithMatcher:grey_allOf(grey_sufficientlyVisible(), grey_enabled(),
...@@ -102,17 +97,7 @@ id<GREYMatcher> NavigationBarEditButton() { ...@@ -102,17 +97,7 @@ id<GREYMatcher> NavigationBarEditButton() {
// Tests that invalid nicknames are not allowed when editing a card. // Tests that invalid nicknames are not allowed when editing a card.
- (void)testInvalidNickname { - (void)testInvalidNickname {
#if !TARGET_OS_SIMULATOR [self typeNickname:@"1233"];
// 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")];
[[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()]
assertWithMatcher:grey_allOf(grey_sufficientlyVisible(), assertWithMatcher:grey_allOf(grey_sufficientlyVisible(),
...@@ -120,10 +105,8 @@ id<GREYMatcher> NavigationBarEditButton() { ...@@ -120,10 +105,8 @@ id<GREYMatcher> NavigationBarEditButton() {
} }
// Tests that clearing a nickname is allowed. // Tests that clearing a nickname is allowed.
// TODO(crbug.com/1108809): Re-enable the test. - (void)testEmptyNickname {
- (void)DISABLED_testEmptyNickname { [self typeNickname:@"To be removed"];
[[EarlGrey selectElementWithMatcher:NicknameTextField()]
performAction:grey_typeText(@"To be removed")];
[[EarlGrey selectElementWithMatcher:NicknameTextField()] [[EarlGrey selectElementWithMatcher:NicknameTextField()]
performAction:grey_clearText()]; performAction:grey_clearText()];
...@@ -133,4 +116,14 @@ id<GREYMatcher> NavigationBarEditButton() { ...@@ -133,4 +116,14 @@ id<GREYMatcher> NavigationBarEditButton() {
nil)]; 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 @end
...@@ -191,6 +191,9 @@ id<GREYMatcher> SettingsDoneButton(); ...@@ -191,6 +191,9 @@ id<GREYMatcher> SettingsDoneButton();
// settings' navigation bar. // settings' navigation bar.
id<GREYMatcher> SyncSettingsConfirmButton(); 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 // Returns matcher for the Autofill Credit Card "Payment Methods" view in the
// settings menu. // settings menu.
id<GREYMatcher> AutofillCreditCardTableView(); id<GREYMatcher> AutofillCreditCardTableView();
......
...@@ -249,6 +249,10 @@ id<GREYMatcher> SyncSettingsConfirmButton() { ...@@ -249,6 +249,10 @@ id<GREYMatcher> SyncSettingsConfirmButton() {
return [ChromeMatchersAppInterface syncSettingsConfirmButton]; return [ChromeMatchersAppInterface syncSettingsConfirmButton];
} }
id<GREYMatcher> AutofillCreditCardEditTableView() {
return [ChromeMatchersAppInterface autofillCreditCardEditTableView];
}
id<GREYMatcher> AutofillCreditCardTableView() { id<GREYMatcher> AutofillCreditCardTableView() {
return [ChromeMatchersAppInterface autofillCreditCardTableView]; return [ChromeMatchersAppInterface autofillCreditCardTableView];
} }
......
...@@ -190,6 +190,9 @@ ...@@ -190,6 +190,9 @@
// settings' navigation bar. // settings' navigation bar.
+ (id<GREYMatcher>)syncSettingsConfirmButton; + (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 // Returns matcher for the Autofill Credit Card "Payment Methods" view in the
// settings menu. // settings menu.
+ (id<GREYMatcher>)autofillCreditCardTableView; + (id<GREYMatcher>)autofillCreditCardTableView;
......
...@@ -471,6 +471,10 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id, ...@@ -471,6 +471,10 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
return grey_accessibilityID(kSyncSettingsConfirmButtonId); return grey_accessibilityID(kSyncSettingsConfirmButtonId);
} }
+ (id<GREYMatcher>)autofillCreditCardEditTableView {
return grey_accessibilityID(kAutofillCreditCardEditTableViewId);
}
+ (id<GREYMatcher>)addressesAndMoreButton { + (id<GREYMatcher>)addressesAndMoreButton {
return [ChromeMatchersAppInterface return [ChromeMatchersAppInterface
buttonWithAccessibilityLabelID:(IDS_AUTOFILL_ADDRESSES_SETTINGS_TITLE)]; 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