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

Open
wants to merge 4 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
14 changes: 11 additions & 3 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { defineConfig } = require('cypress');
const { faker } = require('@faker-js/faker');

module.exports = defineConfig({
e2e: {
Expand All @@ -7,13 +8,20 @@ module.exports = defineConfig({
on('task', {
generateUser() {
const randomNumber = Math.ceil(Math.random(1000) * 1000);

Choose a reason for hiding this comment

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

The Math.random(1000) function does not accept any arguments. To generate a random number between 1 and 1000, you should use Math.ceil(Math.random() * 1000).

const randomMonth = Math.ceil(Math.random() * 12);
const randomYear = Math.ceil(Math.random() * 2024);
return {
username: faker.name.firstName() + `${randomNumber}`,
email: 'test' + `${randomNumber}` + '@mail.com',
password: 'Password12345!'
email: 'user' + `${randomNumber}` + '@mail.com',
password: 'Password12345!',
country: faker.lorem.word(),
city: faker.lorem.word(),
card: faker.lorem.word(),
month: randomMonth,
year: randomYear
};
}
})
});
}
}
});
49 changes: 45 additions & 4 deletions cypress/e2e/checkout.cy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
import PlaceOrderFormPageObject from '../support/pages/orderForm.pageObject';
import HomeAndCataloguePageObject

Choose a reason for hiding this comment

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

There seems to be a missing from keyword in the import statement for HomeAndCataloguePageObject. Ensure that the import statement is correctly formatted.

from '../support/pages/homeСatalogue.pageObject';
// eslint-disable-next-line max-len
import ConfirmationFormPageObject from '../support/pages/confirmForm.pageObject';
import CartFormPageObject from '../support/pages/cartForm.pageObject';

const orderForm = new PlaceOrderFormPageObject();
const homePage = new HomeAndCataloguePageObject();
const confirmWindowValue = new ConfirmationFormPageObject();
const cartWindow = new CartFormPageObject();

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

describe('', () => {
before(() => {
describe('The order', () => {
let user;

before(() => {
cy.task('generateUser').then((generateUser) => {
user = generateUser;
});
homePage.visit();
});

it('', () => {

it('should be placed by purchase the form', () => {
const confirmationMessage = 'Thank you for your purchase!';
homePage.clickOnCategory('Laptops');
homePage.clickOnProduct('Sony vaio i7');
homePage.clickOnBtnOnProductPage('Add to cart');
orderForm.handleConfirmWindow();
homePage.clickOnLink('Cart');
cartWindow.table.should('contain', 'Sony vaio i7');
homePage.clickOnBtnInCart('Place Order');
orderForm.typeName(user.username);
orderForm.typeCountry(user.country);
orderForm.typeCity(user.city);
orderForm.typeCard(user.card);
orderForm.typeMonth(user.month);
orderForm.typeYear(user.year);
homePage.clickOnBtnInOrderForm('Purchase');
confirmWindowValue.confirmWindow.should('exist');
confirmWindowValue.customerName
.should('contain', user.username);
confirmWindowValue.confirmMsg
.should('contain', confirmationMessage);
confirmWindowValue.customerCard
.should('contain', user.card);
confirmWindowValue.orderId
.should('contain', 'Id');
homePage.clickOnOk();
});
});
2 changes: 1 addition & 1 deletion cypress/e2e/contactForm.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ContactFormPageObject from '../support/pages/contactForm.pageObject';
import HomeAndCataloguePageObject

Choose a reason for hiding this comment

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

There seems to be a missing from keyword in the import statement for HomeAndCataloguePageObject. Ensure that the import statement is correctly formatted.

from '../support/pages/homeCatalogue.pageObject';
from '../support/pages/homeAndCataloguePageObject';
import faker from 'faker';
/// <reference types='cypress' />

Expand Down
2 changes: 1 addition & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
11 changes: 11 additions & 0 deletions cypress/support/pages/cartForm.pageObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import PageObject from '../PageObject';

class CartFormPageObject extends PageObject {
url = '/cart.html';

get table() {
return cy.get('.table-responsive');
}
}

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

class ConfirmationFormPageObject extends PageObject {
url = '/cart.html';

get confirmWindow() {
return cy.get('.sweet-alert');
}

get customerName() {
return cy.get('.lead');

Choose a reason for hiding this comment

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

The selector .lead is used for customerName, customerCard, and orderId. Ensure that this selector uniquely identifies the intended element, or consider using more specific selectors to avoid potential conflicts.

}

get confirmMsg() {
return cy.get('.sweet-alert > h2');
}

get customerCard() {
return cy.get('.lead');

Choose a reason for hiding this comment

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

The selector .lead is used for customerName, customerCard, and orderId. Ensure that this selector uniquely identifies the intended element, or consider using more specific selectors to avoid potential conflicts.

}

get orderId() {
return cy.get('.lead');

Choose a reason for hiding this comment

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

The selector .lead is used for customerName, customerCard, and orderId. Ensure that this selector uniquely identifies the intended element, or consider using more specific selectors to avoid potential conflicts.

}
}

export default ConfirmationFormPageObject;
23 changes: 22 additions & 1 deletion cypress/support/pages/homeCatalogue.pageObject.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable max-len */
import PageObject from '../PageObject';
const purchase = '#orderModal > .modal-dialog > .modal-content > .modal-footer > .btn-primary';

class HomeAndCataloguePageObject extends PageObject {
url = '/index.html';
Expand All @@ -17,6 +19,25 @@ class HomeAndCataloguePageObject extends PageObject {
cy.contains('.hrefch', product)
.click();
}
}

clickOnBtnInCart(buttonName) {
cy.contains('.col-lg-1 > .btn', buttonName)
.click();
}

clickOnBtnOnProductPage(button) {
cy.contains('.col-sm-12 > .btn', button)
.click();
}

clickOnBtnInOrderForm(button) {
cy.contains(purchase, button)
.click();
}

clickOnOk() {
cy.get('.confirm')
.click();
}
}
export default HomeAndCataloguePageObject;
62 changes: 62 additions & 0 deletions cypress/support/pages/orderForm.pageObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import PageObject from '../PageObject';

class PlaceOrderFormPageObject extends PageObject {
url = '/cart.html';

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

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

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

get creditCardField() {
return cy.get('#card');
}

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

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

handleConfirmWindow() {
cy.on('window:alert', (alertText) => {
expect(alertText).to.equal('Product added');
cy.contains('button', 'OK').click();
});
}

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

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

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

typeCard(card) {
this.creditCardField.type(card, { force: true });
}

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

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

export default PlaceOrderFormPageObject;
Loading