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

Solution #298

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
55 changes: 52 additions & 3 deletions cypress/e2e/checkout.cy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,60 @@
import { faker } from '@faker-js/faker';
import HomeAndCataloguePageObject from '../support/pages/homeСatalogue.pageObject';
import CartPageObject from '../support/pages/cart.pageObject';
/// <reference types='cypress' />

describe('', () => {
before(() => {
const homePage = new HomeAndCataloguePageObject();
const cartPage = new CartPageObject();

const testData = {
name: faker.name.firstName(),
country: faker.address.country(),
city: faker.address.city(),
creditCard: faker.finance.creditCardNumber(),
month: faker.date.month(),
year: faker.date.future({ years: 5 }).getFullYear(),

Choose a reason for hiding this comment

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

The method faker.date.future({ years: 5 }).getFullYear() might not work as expected because faker.date.future() returns a Date object, and calling getFullYear() directly on it may not be valid. Consider using faker.date.future(5).getFullYear() instead.

productName: 'Sony vaio i7',
successMessage: 'Product added'
};

describe('Shopping Cart', () => {
before(() => {
homePage.visit();
});

it('', () => {
it('should allow a user to add a product to the cart', () => {
homePage.clickOnLaptops();
homePage.clickOnProduct(testData.productName);
homePage.addToCart();

// Assert the product was added
cy.on('window:alert', (alertText) => {
expect(alertText).to.contains(testData.successMessage);
});

homePage.clickOnCart();
cartPage.assertProductInCart(testData.productName);

cartPage.clickOnPlaceOrder();
cartPage.fillOrderDetails(
testData.name,
testData.country,
testData.city,
testData.creditCard,
testData.month,
testData.year
);
cartPage.clickOnPurchase();

// Assert the modal shows the correct information
cartPage.assertModalData(
testData.name,
testData.country,
testData.city,
testData.creditCard,
testData.month,
testData.year
);
cartPage.clickOnOk();
});
});
2 changes: 1 addition & 1 deletion cypress/e2e/contactForm.cy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { faker } from '@faker-js/faker';
import ContactFormPageObject from '../support/pages/contactForm.pageObject';
import HomeAndCataloguePageObject
from '../support/pages/homeСatalogue.pageObject';
import faker from 'faker';
/// <reference types='cypress' />

const contactForm = new ContactFormPageObject();
Expand Down
39 changes: 39 additions & 0 deletions cypress/support/pages/cart.pageObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import PageObject from '../PageObject';

class CartPageObject {
assertProductInCart(productName) {
cy.contains('td', productName).should('be.visible');
}

clickOnPlaceOrder() {
cy.contains('Place Order').click();
}

fillOrderDetails(name, country, city, creditCard, month, year) {
cy.get('input[id^="name"]').type(name);
cy.get('input[id^="country"]').type(country);
cy.get('input[id^="city"]').type(city);
cy.get('input[id^="card"]').type(creditCard);
cy.get('input[id^="month"]').type(month);
cy.get('input[id^="year"]').type(year);
}

clickOnPurchase() {
cy.contains('Purchase').click();
}

assertModalData(name, country, city, creditCard, month, year) {
cy.contains('Id').should('be.visible');
cy.contains('Amount').should('be.visible');
cy.contains('Card Number').should('be.visible');
cy.contains('Name').should('exist');
cy.contains('Date').should('be.visible');
cy.contains('Country').should('be.visible');
}
Comment on lines +25 to +32

Choose a reason for hiding this comment

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

The assertModalData method currently checks for the visibility of certain elements but does not verify that the modal contains the expected data values (name, country, city, credit card, month, year) passed as parameters. Consider adding assertions to check that these values are correctly displayed in the modal.


clickOnOk() {
cy.contains('OK').click();
}
}

export default CartPageObject;
13 changes: 12 additions & 1 deletion cypress/support/pages/homeСatalogue.pageObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ class HomeAndCataloguePageObject extends PageObject {
cy.contains('.hrefch', product)
.click();
}
}

clickOnLaptops() {
cy.contains('Laptops').click();
}

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

clickOnCart() {
cy.contains('Cart').click();
}
}
export default HomeAndCataloguePageObject;
Binary file added cypress/videos/checkout.cy.js.mp4
Binary file not shown.
Loading