Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Test to validate finish purchase using credit card and food voucher.

## [0.5.3] - 2021-09-28
### Fixed
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ In the `utils` folder you have at your disposal a series of implemented actions
- `payWithCreditCard` - Selects Credit card payment method
- `typeCVV` - Types CVV for recurring purchases
- `completePurchase` - Clicks finish purchase button
- `payWithFoodVoucher` - Selects Food Voucher payment method
- `combinePaymentMethods` - Clicks to combine payment methods

**Summary**

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import test from './models/Payment - Credit card and Food Voucher - Finish Purchase.model'

test('gatewayio')
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '../../../utils/profile-actions'
import {
selectCreditCardGroup,
queryIframe,
queryCreditCardIframe,
getIframeBody,
} from '../../../utils/payment-actions'

Expand All @@ -24,7 +24,7 @@ export default function test(account) {
fillEmail(email)
confirmSecondPurchase()
selectCreditCardGroup()
queryIframe($iframe => {
queryCreditCardIframe($iframe => {
const body = getIframeBody($iframe)

cy.wrap(body)
Expand All @@ -49,7 +49,7 @@ export default function test(account) {
fillEmail(email)
confirmSecondPurchase()
selectCreditCardGroup()
queryIframe($iframe => {
queryCreditCardIframe($iframe => {
const body = getIframeBody($iframe)

cy.wrap(body)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { setup, visitAndClearCookies } from '../../../utils'
import {
fillEmail,
getRandomEmail,
fillProfile,
} from '../../../utils/profile-actions'
import {
goToPayment,
fillShippingInformation,
} from '../../../utils/shipping-actions'
import {
completePurchase,
combinePaymentMethods,
selectSamsungPay,
fillCreditCardInfo,
fillFoodVoucherInfo,
} from '../../../utils/payment-actions'
import { SKUS, CREDIT_CARD } from '../../../utils/constants'

export default function test(account) {
describe(`Payment - Credit Card and Food Voucher - Finish Purchase - ${account}`, () => {
before(() => {
visitAndClearCookies(account)
})

it('Completing purchase using Credit Card and Food Voucher', () => {
const email = getRandomEmail()

setup({ skus: [SKUS.CC_FOOD_VOUCHER], account })
fillEmail(email)
fillProfile()
fillShippingInformation(account)
goToPayment()
selectSamsungPay()
combinePaymentMethods()
cy.contains(
'Adicione até duas opções de pagamento para combiná-las'
).should('be.visible')
cy.contains('Pagamentos (0)').should('be.visible')
fillCreditCardInfo()
cy.contains('Pagamentos (1)').should('be.visible')
fillFoodVoucherInfo()
cy.contains('Pagamentos (2)').should('be.visible')
completePurchase()

cy.url({ timeout: 120000 }).should('contain', '/orderPlaced')
cy.wait(2000)
cy.contains(email).should('be.visible')
cy.contains('Fernando Coelho').should('be.visible')
cy.contains('Rua Saint Roman 12').should('be.visible')
cy.contains('Copacabana').should('be.visible')
cy.contains('5521999999999').should('be.visible')
cy.contains('Cartão de crédito').should('be.visible')
cy.contains(`${CREDIT_CARD.FINAL}`).should('be.visible')
})
})
}
20 changes: 20 additions & 0 deletions utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@ export const SKUS = {
PICKUP_RJ_BARRA: '331',
PARAGUAY_DELIVERY: '369',
DELIVERY_ARGENTINA: '370',
CC_FOOD_VOUCHER: '42',
}

export const CREDIT_CARD = {
NUMBER: '4040240009008936',
FINAL: '8936',
NAME: 'Fernando Coelho',
INSTALLMENTS: '1',
EXPIRATION_DATE_MONTH: '02',
EXPIRATION_DATE_YEAR: '22',
CVV: '066',
}

export const FOOD_VOUCHER = {
NUMBER: '123456789101',
NAME: 'Alice L Lima',
INSTALLMENTS: '1',
EXPIRATION_DATE_MONTH: '01',
EXPIRATION_DATE_YEAR: '30',
CVV: '123',
}

export const ENV_BASE_URLS = {
Expand Down
97 changes: 85 additions & 12 deletions utils/payment-actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { waitLoad } from '.'
import { CREDIT_CARD, FOOD_VOUCHER } from './constants'

export function payWithBoleto() {
cy.get('#payment-group-bankInvoicePaymentGroup:visible').click()
Expand All @@ -22,9 +23,16 @@ export function getIframeBody($iframe) {
return $iframe.contents().find('body')
}

export function queryIframe(callback) {
export function queryCreditCardIframe(callback) {
cy.waitAndGet(
'#iframe-placeholder-creditCardPaymentGroup > iframe',
'[id^=iframe-placeholder-creditCardPaymentGroup]:first > iframe',
3000
).then(callback)
}

export function queryFoodVoucherIframe(callback) {
cy.waitAndGet(
'[id^=iframe-placeholder-customPrivate_404PaymentGroup]:first > iframe',
3000
).then(callback)
}
Expand All @@ -40,33 +48,80 @@ export function fillCreditCardInfo(

cy.wait(5000)

queryIframe($iframe => {
queryCreditCardIframe($iframe => {
const $body = getIframeBody($iframe)

// We type with force:true because of https://github.com/cypress-io/cypress/issues/5830
cy.wrap($body)
.find(`#creditCardpayment-card-${options.id || '0'}Number`)
.type('4040240009008936', { force: true })
.type(CREDIT_CARD.NUMBER, { force: true })

cy.wrap($body)
.find(`#creditCardpayment-card-${options.id || '0'}Name`)
.type('Fernando A Coelho', { force: true })
.type(CREDIT_CARD.NAME, { force: true })

cy.wrap($body)
.find(`#creditCardpayment-card-${options.id || '0'}Brand`)
.select('1')
.select(CREDIT_CARD.INSTALLMENTS)

cy.wrap($body)
.find(`#creditCardpayment-card-${options.id || '0'}Month`)
.select('02')
.select(CREDIT_CARD.EXPIRATION_DATE_MONTH)

cy.wrap($body)
.find(`#creditCardpayment-card-${options.id || '0'}Year`)
.select('22')
.select(CREDIT_CARD.EXPIRATION_DATE_YEAR)

cy.wrap($body)
.find(`#creditCardpayment-card-${options.id || '0'}Code`)
.type('066', { force: true })
.type(CREDIT_CARD.CVV, { force: true })

if (!options.withAddress) {
return
}

fillBillingAddress({ id: options.id, postalCode: '22071060', number: '12' })
})
}

export function fillFoodVoucherInfo(
options = {
withAddress: false,
id: '0',
}
) {
cy.wait(3000)
cy.get('#payment-group-customPrivate_404PaymentGroup').click({ force: true })

cy.wait(5000)

queryFoodVoucherIframe($iframe => {
const $body = getIframeBody($iframe)

// We type with force:true because of https://github.com/cypress-io/cypress/issues/5830
cy.wrap($body)
.find(`#creditCardpayment-card-${options.id || '0'}Number`)
.type(FOOD_VOUCHER.NUMBER, { force: true })

cy.wrap($body)
.find(`#creditCardpayment-card-${options.id || '0'}Name`)
.type(FOOD_VOUCHER.NAME, { force: true })

cy.wrap($body)
.find(`#creditCardpayment-card-${options.id || '0'}Brand`)
.select(FOOD_VOUCHER.INSTALLMENTS)

cy.wrap($body)
.find(`#creditCardpayment-card-${options.id || '0'}Month`)
.select(FOOD_VOUCHER.EXPIRATION_DATE_MONTH)

cy.wrap($body)
.find(`#creditCardpayment-card-${options.id || '0'}Year`)
.select(FOOD_VOUCHER.EXPIRATION_DATE_YEAR)

cy.wrap($body)
.find(`#creditCardpayment-card-${options.id || '0'}Code`)
.type(FOOD_VOUCHER.CVV, { force: true })

if (!options.withAddress) {
return
Expand All @@ -77,7 +132,7 @@ export function fillCreditCardInfo(
}

export function fillBillingAddress(options) {
queryIframe($iframe => {
queryCreditCardIframe($iframe => {
const $body = getIframeBody($iframe)

const id = options.id || '0'
Expand Down Expand Up @@ -109,6 +164,14 @@ export function selectCreditCardGroup() {
cy.waitAndGet('#payment-group-creditCardPaymentGroup', 3000).click()
}

export function selectFoodVoucherGroup() {
cy.waitAndGet('#payment-group-customPrivate_404PaymentGroup', 3000).click()
}

export function selectSamsungPay() {
cy.waitAndGet('#payment-group-SamsungPayPaymentGroup', 3000).click()
}

export function payWithCreditCard(options = { withAddress: false }) {
selectCreditCardGroup()
waitLoad()
Expand All @@ -125,7 +188,7 @@ export function payWithTwoCreditCards(options = { withAddress: false }) {

export function selectTwoCards() {
cy.waitAndGet('#payment-group-creditCardPaymentGroup', 1000).click()
queryIframe($iframe => {
queryCreditCardIframe($iframe => {
const $body = getIframeBody($iframe)
cy.wrap($body)
.find('.ChangeNumberOfPayments a:visible')
Expand Down Expand Up @@ -156,7 +219,7 @@ export function typeCVV() {
cy.waitAndGet('#payment-group-creditCardPaymentGroup', 1000).click()
waitLoad()

queryIframe($iframe => {
queryCreditCardIframe($iframe => {
const $body = getIframeBody($iframe)

cy.wrap($body)
Expand Down Expand Up @@ -186,3 +249,13 @@ export function insertFreeShippingCoupon() {
export function goBackToShipping() {
cy.get('#open-shipping').click()
}

export function payWithFoodVoucher(options = { withAddress: false }) {
selectFoodVoucherGroup()
waitLoad()
fillFoodVoucherInfo({ withAddress: options.withAddress, id: 0 })
}

export function combinePaymentMethods() {
cy.waitAndGet('#combine-payment-methods', 3000).click()
}