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 #281

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
43 changes: 40 additions & 3 deletions cypress/e2e/checkout.cy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
/// <reference types='cypress' />

describe('', () => {
before(() => {
import { CartPageObject } from '../support/pages/cart.pageObject';
import HomeAndCataloguePageObject

Choose a reason for hiding this comment

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

There is a missing semicolon at the end of the import statement. This might cause issues depending on your project's configuration.

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',

Choose a reason for hiding this comment

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

The alert message 'Product added' should be consistent with the actual alert message displayed by the application. Ensure that this string matches exactly what the application shows.

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,

Choose a reason for hiding this comment

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

The random year generation logic seems to be correct, but ensure that the range (1900 to 2024) is what you intend for your test case. If you need a specific range, adjust the logic accordingly.

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');

Choose a reason for hiding this comment

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

Ensure that the alert message 'Product added' used here matches the actual alert message from the application. Any discrepancy will cause this verification to fail.


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);

Choose a reason for hiding this comment

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

Ensure that the method 'verifyEnteredDataOnModalWindow' correctly verifies the data on the modal window. If the modal displays data differently, you may need to adjust this method.


cartPage.clickOnButton('OK');
});
});
29 changes: 29 additions & 0 deletions cypress/support/pages/cart.pageObject.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
10 changes: 10 additions & 0 deletions cypress/support/pages/homeCatalogue.pageObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;