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

added tests #299

Open
wants to merge 2 commits 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: 39 additions & 4 deletions cypress/e2e/checkout.cy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,46 @@
import HomeAndCataloguePageObject from '../support/pages/homeCatalogue.pageObject';
import ProdPagePageObject from '../support/pages/prodPage.pageObject';
import CartPageObject from '../support/pages/cart.pageObject';
const homePage = new HomeAndCataloguePageObject();
const productPage = new ProdPagePageObject();
const cartPage = new CartPageObject();
const { faker } = require('@faker-js/faker');
const testData = {
categoryName: 'Laptops',
product: 'Sony vaio i7',
message: 'Product added',
cartLinkName: 'Cart',
customerName: faker.person.firstName(),
customerCountry: 'USA',
customerCity: 'NY',
customerCardNo: faker.finance.creditCardNumber(),
cardMonth: faker.number.int({ min: 1, max: 12 }),
cardYear: faker.number.int({ min: 1900, max: 2012 })

Choose a reason for hiding this comment

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

The range for cardYear seems incorrect. Typically, credit card expiration years should be in the future or recent past, not starting from 1900. Consider adjusting the range to a more realistic set of years, such as from the current year onwards.

};
/// <reference types='cypress' />

describe('', () => {
describe('checkout flow', () => {
before(() => {

homePage.visit();
});

it('', () => {

it('should add the product to the cart', () => {
homePage.clickOnCategory(testData.categoryName);
homePage.clickOnProduct(testData.product);
productPage.addToCart();
productPage.assertAllert(testData.message);

Choose a reason for hiding this comment

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

The method assertAllert seems to have a typo. It should likely be assertAlert to correctly reflect the word 'alert'. Ensure that the method name matches the implementation in the ProdPagePageObject class.

Choose a reason for hiding this comment

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

Ensure that the assertAllert method is correctly implemented to handle alert messages. If this method is supposed to check for a browser alert, make sure it interacts with the alert correctly.

homePage.clickOnLink(testData.cartLinkName);
cartPage.assertProductInCart(testData.product);
cartPage.placeOrder();
cartPage.fillTheForm(
testData.customerName,
testData.customerCountry,
testData.customerCity,
testData.customerCardNo,
testData.cardMonth,
testData.cardYear
);
cartPage.assertPurchaseInfo(testData.customerName);
cartPage.closePurchaseModal();
});
});
36 changes: 36 additions & 0 deletions cypress/support/pages/cart.pageObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import PageObject from '../PageObject';

class CartPageObject extends PageObject {
assertProductInCart(prodName) {
cy.get('tbody tr td:nth-child(2)')
.should('have.text', prodName);

Choose a reason for hiding this comment

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

Consider using a more flexible assertion like should('include.text', prodName) instead of should('have.text', prodName). This change can help avoid issues if there are additional spaces or text around the product name.

}

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

fillTheForm(name, country, city, cardNo, month, year) {
cy.get('input#name').type(name);
cy.get('input#country').type(country);
cy.get('input#city').type(city);
cy.get('input#card').type(cardNo);
cy.get('input#month').type(month);
cy.get('input#year').type(year);
cy.contains('button', 'Purchase')
.click();
}

assertPurchaseInfo(name) {
cy.get('.sweet-alert p.text-muted')
.should('contain.text', 'Name: ' + name);

Choose a reason for hiding this comment

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

Ensure that the selector .sweet-alert p.text-muted correctly targets the element containing the purchase information. If the structure of the alert changes, this selector might need to be updated.

}

closePurchaseModal() {
cy.get('button.confirm')
.click();
}
}

export default CartPageObject;
11 changes: 11 additions & 0 deletions cypress/support/pages/prodPage.pageObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import PageObject from '../PageObject';

class ProductPageObject extends PageObject {
url = '/prod.html';
addToCart() {
cy.contains('.btn-success', 'Add to cart')
.click();
}
}

export default ProductPageObject;