Skip to content

Commit

Permalink
CT-2901 | Billing info UI tests & refactor (#241)
Browse files Browse the repository at this point in the history
* Add happy path billing info test

* Add UK post code validation test and refactor

* Add missing postcode check on happy path test

* Add US and CA post code validation tests

* Test data and selectors refactor

* Address PR comment
  • Loading branch information
eugenezhernakov authored May 8, 2024
1 parent b9e019c commit c0b2300
Show file tree
Hide file tree
Showing 7 changed files with 516 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import XCTest

func assertResultObject(_ app: XCUIApplication, _ type: String, _ message: String, _ result: String) {
let tableView = app.tables["Results View"]
let tableView = app.tables[Selectors.Other.resultsTable]
XCTAssert(tableView.waitForExistence(timeout: 10))
let rawData = tableView.cells.element(boundBy: 15)
rawData.tap()
Expand All @@ -32,6 +32,27 @@ func assertResultObject(_ app: XCUIApplication, _ type: String, _ message: Strin
XCTAssertEqual(resultValue, result, "Result value on result object does not match the expected string")
}

func assertBillingInfo(_ app: XCUIApplication, _ countryCode: String, _ town: String, _ addressOne: String, _ addressTwo: String, _ postCode: String) {
let tableView = app.tables[Selectors.Other.resultsTable]
XCTAssert(tableView.waitForExistence(timeout: 10))
tableView.cells.element(boundBy: 16).tap()

XCTAssertEqual(tableView.cells.element(matching: .cell, identifier: "countryCode").staticTexts.element(boundBy: 1)
.label, countryCode, "Country code value on result object does not match the expected string")

XCTAssertEqual(tableView.cells.element(matching: .cell, identifier: "postCode").staticTexts.element(boundBy: 1)
.label, postCode, "Postcode value on result object does not match the expected string")

XCTAssertEqual(tableView.cells.element(matching: .cell, identifier: "address1").staticTexts.element(boundBy: 1)
.label, addressOne, "Address 1 value on result object does not match the expected string")

XCTAssertEqual(tableView.cells.element(matching: .cell, identifier: "address2").staticTexts.element(boundBy: 1)
.label, addressTwo, "Address 2 value on result object does not match the expected string")

XCTAssertEqual(tableView.cells.element(matching: .cell, identifier: "town").staticTexts.element(boundBy: 1)
.label, town, "City value on result object does not match the expected string")
}

func tapCompleteButton(_ app: XCUIApplication) {
let completeButton = app.buttons["COMPLETE"]
XCTAssert(completeButton.waitForExistence(timeout: 10))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,50 @@
import Foundation

class Selectors {
static let cardNumberField = "Card Number Field"
static let cardHolderNameField = "Cardholder Name Field"
static let expiryDateField = "Expiry Date Field"
static let securityCodeField = "Security Code Field"
static let cardDetailsSubmitButtonSelector = "Submit Button"
static let settingsSectionButton = "Settings Button"
static let cancelCardEntryButton = "CANCEL"
static let threeDS2CancelButton = "Cancel"
static let tokenizeNewCardButtonSelector = "Tokenize a new card"
static let tokenPaymentButtonSelector = "Payment"
static let tokenPreAuthButton = "Preauth"
static let addNewCardButton = "ADD CARD"
static let payNowButtonSelector = "PAY NOW"
static let editCardsButtonSelector = "EDIT"
static let deleteCardButtonSelector = "Delete"
struct CardEntry {
static let cardNumberField = "Card Number Field"
static let cardHolderNameField = "Cardholder Name Field"
static let expiryDateField = "Expiry Date Field"
static let securityCodeField = "Security Code Field"
static let cardDetailsSubmitButtonSelector = "Submit Button"
static let cancelCardEntryButton = "CANCEL"
}
struct FeatureList {
static let payWithCard = "Pay with card"
static let preAuthWithCard = "Pre-auth with card"
static let registerCard = "Register card"
static let checkCard = "Check card"
static let tokenPayment = "Token Payments"
static let paymentMethods = "Payment methods"
static let preAuthMethods = "PreAuth methods"
static let settingsSectionButton = "Settings Button"
}
struct TokenPayments {
static let tokenizeNewCardButtonSelector = "Tokenize a new card"
static let tokenPaymentButtonSelector = "Payment"
static let tokenPreAuthButton = "Preauth"
}
struct PaymentMethods {
static let addNewCardButton = "ADD CARD"
static let payNowButtonSelector = "PAY NOW"
static let editCardsButtonSelector = "EDIT"
static let deleteCardButtonSelector = "Delete"
}
struct BillingInfo {
static let emailField = "Cardholder Email Field"
static let phoneField = "Cardholder phone number Field"
static let addressOneField = "Cardholder address line 1 code Field"
static let addressTwoField = "Cardholder address line 2 Field"
static let cityField = "Cardholder city Field"
static let postCodeField = "Post Code Field"
static let addAddressLineButton = "Add address line Button"
static let fieldErrorLabel = "Error Floating Label"
static let stateField = "State Field"
static let countryField = "Country Field"
}
struct Other {
static let threeDS2CancelButton = "Cancel"
static let resultsTable = "Results View"
static let cancelButton = "Cancel"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,44 @@
import Foundation

class TestData {
static let CARD_NUMBER = "4976 3500 0000 6891"
static let CARDHOLDER_NAME = "Test User"
static let CARD_EXPIRY = "1225"
static let CARD_SECURITY_CODE = "341"

static let PAY_WITH_CARD_LABEL = "Pay with card"
static let PREAUTH_WITH_CARD_LABEL = "Pre-auth with card"
static let REGISTER_CARD_LABEL = "Register card"
static let CHECK_CARD_LABEL = "Check card"
static let TOKEN_PAYMENTS_LABEL = "Token Payments"
static let PAYMENT_METHODS_LABEL = "Payment methods"
static let PREAUTH_METHODS_LABEL = "PreAuth methods"

static let CANCEL_BUTTON = "Cancel"

static let CANCELLED_PAYMENT_TOAST = "The transaction was cancelled by the user."
static let CANCELLED_3DS2_PAYMENT_TOAST = "Unable to process transaction. Card authentication failed with 3DS Server."

static let ALLOW = "ALLOW"
static let PREVENT = "PREVENT"
static let REVIEW = "REVIEW"
static let AUTHORISE = "AUTHORISE"
static let AUTHENTICATE = "AUTHENTICATE"
static let TRA = "TRANSACTION_RISK_ANALYSIS"
static let LOW_VALUE = "LOW_VALUE"
static let NO_CHALLENGE = "NO_CHALLENGE_REQUESTED"
static let NO_PREFERENCE = "NO_PREFERENCE"
static let CHALLENGE_MANDATE = "CHALLENGE_REQUESTED_AS_MANDATE"
static let CHALLENGE_REQUESTED = "CHALLENGE_REQUESTED"
struct CardDetails {
static let CARD_NUMBER = "4976 3500 0000 6891"
static let CARDHOLDER_NAME = "Test User"
static let CARD_EXPIRY = "1225"
static let CARD_SECURITY_CODE = "341"
}
struct Ravelin {
static let ALLOW = "ALLOW"
static let PREVENT = "PREVENT"
static let REVIEW = "REVIEW"
static let AUTHORISE = "AUTHORISE"
static let AUTHENTICATE = "AUTHENTICATE"
static let TRA = "TRANSACTION_RISK_ANALYSIS"
static let LOW_VALUE = "LOW_VALUE"
static let NO_CHALLENGE = "NO_CHALLENGE_REQUESTED"
static let NO_PREFERENCE = "NO_PREFERENCE"
static let CHALLENGE_MANDATE = "CHALLENGE_REQUESTED_AS_MANDATE"
static let CHALLENGE_REQUESTED = "CHALLENGE_REQUESTED"
}
struct BillingInfo {
static let VALID_EMAIL = "[email protected]"
static let VALID_MOBILE = "07812345678"
static let VALID_ADDRESS = "235 Regent Street"
static let VALID_CITY = "London"
static let VALID_POSTCODE = "W1B 2EL"
static let VALID_ADDRESS_TWO = "West End"
static let VALID_COUNTRY_CODE = "826"
static let INVALID_POSTCODE = "38GL112"
static let SPECIAL_CHARACTERS = "#$@*"
static let INVALID_POSTCODE_LABEL = "Invalid postcode entered"
static let INVALID_ZIPCODE_LABEL = "Invalid ZIP code entered"
static let INVALID_EMAIL_LABEL = "Please enter a valid email"
static let INVALID_PHONE_LABEL = "Please enter a valid mobile number"
static let INVALID_ADDRESS_LABEL = "Please enter a valid address"
static let INVALID_CITY_LABEL = "Please enter a valid city"
}
struct Other {
static let CANCELLED_PAYMENT_TOAST = "The transaction was cancelled by the user."
static let CANCELLED_3DS2_PAYMENT_TOAST = "Unable to process transaction. Card authentication failed with 3DS Server."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,94 +24,158 @@ extension XCUIApplication {
func buttonWithLabel(_ label: String) -> XCUIElement? {
return buttons.matching(NSPredicate(format: "label == %@", label)).firstMatch
}

func textWithIdentifier(_ identifier: String) -> XCUIElement? {
return staticTexts.matching(identifier: identifier).firstMatch
}

var cardNumberTextField: XCUIElement? {
get {
return textFieldWithIdentifier(Selectors.cardNumberField)
return textFieldWithIdentifier(Selectors.CardEntry.cardNumberField)
}
}

var cardholderTextField: XCUIElement? {
get {
return textFieldWithIdentifier(Selectors.cardHolderNameField)
return textFieldWithIdentifier(Selectors.CardEntry.cardHolderNameField)
}
}

var expiryDateTextField: XCUIElement? {
get {
return textFieldWithIdentifier(Selectors.expiryDateField)
return textFieldWithIdentifier(Selectors.CardEntry.expiryDateField)
}
}

var securityCodeTextField: XCUIElement? {
get {
return textFieldWithIdentifier(Selectors.securityCodeField)
return textFieldWithIdentifier(Selectors.CardEntry.securityCodeField)
}
}

var cardDetailsSubmitButton: XCUIElement? {
get {
return buttonWithIdentifier(Selectors.cardDetailsSubmitButtonSelector)
return buttonWithIdentifier(Selectors.CardEntry.cardDetailsSubmitButtonSelector)
}
}

var settingsButton: XCUIElement? {
get {
return buttonWithIdentifier(Selectors.settingsSectionButton)
return buttonWithIdentifier(Selectors.FeatureList.settingsSectionButton)
}
}

var cancelButton: XCUIElement? {
get {
return buttonWithLabel(Selectors.cancelCardEntryButton)
return buttonWithLabel(Selectors.CardEntry.cancelCardEntryButton)
}
}

var cancelButton3DS2: XCUIElement? {
get {
return buttonWithLabel(Selectors.threeDS2CancelButton)
return buttonWithLabel(Selectors.Other.threeDS2CancelButton)
}
}

var tokenizeNewCardButton: XCUIElement? {
get {
return buttonWithLabel(Selectors.tokenizeNewCardButtonSelector)
return buttonWithLabel(Selectors.TokenPayments.tokenizeNewCardButtonSelector)
}
}

var tokenPaymentButton: XCUIElement? {
get {
return buttonWithLabel(Selectors.tokenPaymentButtonSelector)
return buttonWithLabel(Selectors.TokenPayments.tokenPaymentButtonSelector)
}
}

var tokenPreauthButton: XCUIElement? {
get {
return buttonWithLabel(Selectors.tokenPreAuthButton)
return buttonWithLabel(Selectors.TokenPayments.tokenPreAuthButton)
}
}

var addCard: XCUIElement? {
get {
return buttonWithLabel(Selectors.addNewCardButton)
return buttonWithLabel(Selectors.PaymentMethods.addNewCardButton)
}
}

var payNowButton: XCUIElement? {
get {
return buttonWithLabel(Selectors.payNowButtonSelector)
return buttonWithLabel(Selectors.PaymentMethods.payNowButtonSelector)
}
}

var editCardsButton: XCUIElement? {
get {
return buttonWithLabel(Selectors.editCardsButtonSelector)
return buttonWithLabel(Selectors.PaymentMethods.editCardsButtonSelector)
}
}

var deleteCardButton: XCUIElement? {
get {
return buttonWithLabel(Selectors.deleteCardButtonSelector)
return buttonWithLabel(Selectors.PaymentMethods.deleteCardButtonSelector)
}
}

var emailField: XCUIElement? {
get {
return textFieldWithIdentifier(Selectors.BillingInfo.emailField)
}
}

var mobileField: XCUIElement? {
get {
return textFieldWithIdentifier(Selectors.BillingInfo.phoneField)
}
}

var addressLineOne: XCUIElement? {
get {
return textFieldWithIdentifier(Selectors.BillingInfo.addressOneField)
}
}

var addressLineTwo: XCUIElement? {
get {
return textFieldWithIdentifier(Selectors.BillingInfo.addressTwoField)
}
}

var cityField: XCUIElement? {
get {
return textFieldWithIdentifier(Selectors.BillingInfo.cityField)
}
}

var postCodeField: XCUIElement? {
get {
return textFieldWithIdentifier(Selectors.BillingInfo.postCodeField)
}
}

var stateField: XCUIElement? {
get {
return textFieldWithIdentifier(Selectors.BillingInfo.stateField)
}
}

var countryField: XCUIElement? {
get {
return textFieldWithIdentifier(Selectors.BillingInfo.countryField)
}
}

var addAddressLineButton: XCUIElement? {
get {
return buttonWithIdentifier(Selectors.BillingInfo.addAddressLineButton)
}
}

var fieldErrorLabel: String? {
get {
return textWithIdentifier(Selectors.BillingInfo.fieldErrorLabel)?.label
}
}

Expand Down Expand Up @@ -156,6 +220,16 @@ extension XCUIApplication {
securityCodeTextField?.tapAndTypeText(securityCode)
}

func fillBillingInfoDetails(email: String, phone: String, addressOne: String, addressTwo: String, city: String, postCode: String) {
emailField?.tapAndTypeText(email)
mobileField?.tapAndTypeText(phone)
addressLineOne?.tapAndTypeText(addressOne)
addAddressLineButton?.tap()
addressLineTwo?.tapAndTypeText(addressTwo)
cityField?.tapAndTypeText(city)
postCodeField?.tapAndTypeText(postCode)
}

func clearTextFieldByIndex(index: Int) {
let textField = textFields.element(boundBy: index)
textField.tap(withNumberOfTaps: 3, numberOfTouches: 1)
Expand Down
Loading

0 comments on commit c0b2300

Please sign in to comment.