Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add solution #313

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
12 changes: 12 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ module.exports = defineConfig({
email: 'test' + `${randomNumber}` + '@mail.com',
password: 'Password12345!'
};
},
generateOrderInfo() {
const name = faker.person.firstName();
const country = faker.location.country();
const city = faker.location.city();
const creditCardNumber = faker.finance.creditCardNumber();
const month = faker.date.month();
const year = Math.ceil(Math.random() * 30) + 2000;

return {
name, country, city, creditCardNumber, month, year
};
}
});
}
Expand Down
37 changes: 35 additions & 2 deletions cypress/e2e/checkout.cy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
/* eslint-disable max-len */
/// <reference types='cypress' />

import HomeAndCataloguePageObject from '../support/pages/homeCatalogue.pageObject';
import CartPageObject from '../support/pages/cart.pageObject';

const homeCalalogue = new HomeAndCataloguePageObject();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a typo in the variable name homeCalalogue. It should be homeCatalogue to match the class name HomeAndCataloguePageObject and maintain consistency.

const cart = new CartPageObject();
const category = 'Laptops';
const item = 'Sony vaio i7';
const alertMessage = 'Product added';

describe('', () => {
before(() => {
let formData;

before(() => {
cy.task('generateOrderInfo').then((data) => {
formData = data;
homeCalalogue.visit();
});
});

it('', () => {

homeCalalogue.clickOnCategory(category);
homeCalalogue.clickOnProduct(item);
homeCalalogue.addToCart();
homeCalalogue.assertAllert(alertMessage);
homeCalalogue.clickOnLink('Cart');
cart.itemIsInCart(item);
cart.placeOrderBtn();
cart.typeName(formData.name);
cart.typeCountry(formData.country);
cart.typeCity(formData.city);
cart.typeCreditCardNum(formData.creditCardNumber);
cart.typeYear(formData.year);
cart.typeMonth(formData.month);
cart.purchaseOrderBtn();
cart.assertSuccessfulPurchase();
cart.assertPurchaseInfo('Name', formData.name);
cart.assertPurchaseInfo('Card Number', formData.creditCardNumber);
cart.pressOkBtn();
cart.closePurchaseForm();
});
});
95 changes: 95 additions & 0 deletions cypress/support/pages/cart.pageObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import PageObject from '../PageObject';

class CartPageObject extends PageObject {
get creditCardField() {
return cy.get('#card');
}

get nameField() {
return cy.get('#name');
}

get countryField() {
return cy.get('#country');
}

get cityField() {
return cy.get('#city');
}

get yearField() {
return cy.get('#year');
}

get monthField() {
return cy.get('#month');
}

get purchaseBtn() {
return cy.contains('.btn', 'Purchase');
}

get okBtn() {
return cy.contains('.confirm', 'OK');
}

get closeBtn() {
return cy.get('#orderModal .btn-secondary');
}

itemIsInCart(productName) {
cy.get('.success').within(() => {
cy.contains('td', productName).should('be.visible');
});
}

placeOrderBtn() {
cy.contains('button', 'Place Order').click();
}

purchaseOrderBtn() {
this.purchaseBtn.click();
}

typeName(name) {
this.nameField.type(name, { force: true });
}

typeCity(city) {
this.cityField.type(city, { force: true });
}

typeYear(year) {
this.yearField.type(year, { force: true });
}

typeMonth(month) {
this.monthField.type(month, { force: true });
}

typeCreditCardNum(number) {
this.creditCardField.type(number, { force: true });
}

typeCountry(country) {
this.countryField.type(country, { force: true });
}

pressOkBtn() {
this.okBtn.click();
}

closePurchaseForm() {
this.closeBtn.click({ force: true });
}

assertSuccessfulPurchase() {
cy.contains('h2', 'Thank you for your purchase!').should('be.visible');
}

assertPurchaseInfo(field, value) {
cy.contains('.lead.text-muted ', `${field}: ${value}`);
}
}

export default CartPageObject;
2 changes: 1 addition & 1 deletion cypress/support/pages/contactForm.pageObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ContactFormPageObject extends PageObject {
}

get nameField() {
return cy.get('#recipient-name');
return cy.get('#name');
}

get messageField() {
Expand Down
4 changes: 4 additions & 0 deletions cypress/support/pages/homeCatalogue.pageObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class HomeAndCataloguePageObject extends PageObject {
cy.contains('.hrefch', product)
.click();
}

addToCart() {
cy.contains('.btn', 'Add to cart').click();
}
}

export default HomeAndCataloguePageObject;
Loading
Loading