diff --git a/cypress/e2e/checkout.cy.js b/cypress/e2e/checkout.cy.js index 7b018f7..9fa4e89 100644 --- a/cypress/e2e/checkout.cy.js +++ b/cypress/e2e/checkout.cy.js @@ -1,11 +1,48 @@ /// -describe('', () => { - before(() => { +import { CartPageObject } from '../support/pages/cart.pageObject'; +import HomeAndCataloguePageObject + from '../support/pages/homeCatalogue.pageObject'; +import { faker } from '@faker-js/faker'; + +const homePage = new HomeAndCataloguePageObject(); +const cartPage = new CartPageObject(); +const testData = { + product: 'Sony vaio i7', + category: 'Laptops', + alertMessage: 'Product added', + name: faker.person.firstName(), + country: faker.location.country(), + city: faker.location.city(), + card: faker.finance.creditCardNumber(), + month: faker.date.month(), + year: Math.floor(Math.random() * (2024 - 1900 + 1)) + 1900, + successMessage: 'Thanks for the message!!' +}; + +describe('Demoblaze flow', () => { + before(() => { + homePage.visit(); }); - it('', () => { + it('should provide an opportunity to make a purchase', () => { + homePage.clickOnCategory('Laptops'); + homePage.clickOnProduct('Sony vaio i7'); + homePage.clickOnButton('Add to cart'); + + homePage.verifyAlertMessage('Product added'); + + homePage.clickOnLink('Cart'); + cartPage.verifyItemInCart('Sony vaio i7'); + cartPage.clickOnButton('Place Order'); + + cartPage.fillOrderForm(testData.name, testData.country, testData.city, + testData.card, testData.month, testData.year); + + cartPage.clickOnButton('Purchase'); + cartPage.verifyEnteredDataOnModalWindow(testData.name, testData.card); + cartPage.clickOnButton('OK'); }); }); diff --git a/cypress/support/pages/cart.pageObject.js b/cypress/support/pages/cart.pageObject.js new file mode 100644 index 0000000..7dae539 --- /dev/null +++ b/cypress/support/pages/cart.pageObject.js @@ -0,0 +1,29 @@ + +import PageObject from '../PageObject'; + +export class CartPageObject extends PageObject { + verifyItemInCart(itemName) { + cy.contains(itemName) + .should('exist'); + } + + clickOnButton(buttonText) { + cy.contains(buttonText) + .should('be.visible') + .click(); + } + + fillOrderForm(name, country, city, card, month, year) { + cy.get('#name').type(name); + cy.get('#country').type(country); + cy.get('#city').type(city); + cy.get('#card').type(card); + cy.get('#month').type(month); + cy.get('#year').type(year); + } + + verifyEnteredDataOnModalWindow(name, card) { + cy.get('.sweet-alert').should('contain', name); + cy.get('.sweet-alert').should('contain', card); + } +} diff --git a/cypress/support/pages/homeCatalogue.pageObject.js b/cypress/support/pages/homeCatalogue.pageObject.js index 971207e..158b55c 100644 --- a/cypress/support/pages/homeCatalogue.pageObject.js +++ b/cypress/support/pages/homeCatalogue.pageObject.js @@ -17,6 +17,16 @@ class HomeAndCataloguePageObject extends PageObject { cy.contains('.hrefch', product) .click(); } + + clickOnButton(buttonText) { + cy.contains(buttonText).click(); + } + + verifyAlertMessage(expectedMessage) { + cy.on('window:alert', (text) => { + expect(text).to.include(expectedMessage); + }); + } } export default HomeAndCataloguePageObject;