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

update #301

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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
'cypress/no-force': 'warn',
'cypress/no-async-tests': 'error',
'cypress/no-pause': 'error',
'max-len': ['error', 80, {
'max-len': ['error', 85, {
ignoreTemplateLiterals: true,
ignoreRegExpLiterals: true,
ignoreComments: true
Expand Down
52 changes: 49 additions & 3 deletions cypress/e2e/checkout.cy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,57 @@
/// <reference types='cypress' />
const username = 'testpacka';
const password = 'testpack3a';
const {
getRandomName,
getRandomCountry,
getRandomCity,
getRandomCreditCard,
getRandomMonth,
getRandomYear
} = require('../support/testData');

describe('', () => {
before(() => {
const testData = {
name: getRandomName(),
country: getRandomCountry(),
city: getRandomCity(),
creditCard: getRandomCreditCard(),
month: getRandomMonth(),
year: getRandomYear()
};

describe('Login and Add to Cart Workflow', () => {
before(() => {
cy.visit('https://www.demoblaze.com/');
});

it('', () => {
it('should log in and place an order', () => {
cy.get('#signin2').click();
cy.get('#sign-username').type(username);
cy.get('#sign-password').type(password);
cy.get('#signInModal .btn-primary').click();
cy.get('#signInModal .close > span').click();

cy.get('#login2').click();
cy.get('#loginusername').type(username);
cy.get('#loginpassword').type(password);
cy.get('#logInModal .btn-primary').click();
cy.get('#logInModal .close > span').click();

cy.contains('a', 'Laptops', { timeout: 10000 }).click();
cy.contains('a', 'Sony vaio i5').click();

Choose a reason for hiding this comment

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

The task requires selecting 'Sony vaio i7', but the script currently selects 'Sony vaio i5'. Please update this line to select the correct product.

cy.contains('a', 'Add to cart').click();

Choose a reason for hiding this comment

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

You need to assert the message in the alert after clicking 'Add to cart'. This is a requirement according to the task description.

Choose a reason for hiding this comment

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

Consider adding an assertion here to verify the alert message after adding the product to the cart. This will ensure that the product was successfully added.

cy.contains('a', 'Cart').click();

Choose a reason for hiding this comment

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

After clicking 'Cart', you should assert that the product is in the cart. This is necessary to ensure that the product was successfully added.

Choose a reason for hiding this comment

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

Before navigating to the cart, add an assertion to verify that the product is indeed in the cart. This will confirm that the product was added successfully.

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

cy.get('#name').should('be.visible').type(testData.name);
cy.get('#country').should('be.visible').type(testData.country);
cy.get('#city').should('be.visible').type(testData.city);
cy.get('#card').should('be.visible').type(testData.creditCard);
cy.get('#month').should('be.visible').type(testData.month);
cy.get('#year').should('be.visible').type(testData.year);

cy.contains('button', 'Purchase').click();

Choose a reason for hiding this comment

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

After clicking 'Purchase', you should assert that the entered data is shown on the modal. This is important to verify that the purchase details are correctly displayed.

Choose a reason for hiding this comment

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

After clicking 'Purchase', add assertions to verify that the entered data (name, country, city, credit card, month, year) is correctly displayed on the modal. This will ensure that the purchase details are accurate.


cy.contains('button', 'OK').click();
});
});
16 changes: 14 additions & 2 deletions cypress/e2e/contactForm.cy.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import ContactFormPageObject from '../support/pages/contactForm.pageObject';
import HomeAndCataloguePageObject
from '../support/pages/homeCatalogue.pageObject';
import HomeAndCataloguePageObject from '../support/pages/homeCatalogue.pageObject';
import {
getRandomCountry,
getRandomCity,
getRandomAddress,
getRandomPostalCode,
getRandomPhoneNumber
} from '../support/testData';
import faker from 'faker';

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

const contactForm = new ContactFormPageObject();
const homePage = new HomeAndCataloguePageObject();

const testData = {
country: getRandomCountry(),
city: getRandomCity(),
address: getRandomAddress(),
postalCode: getRandomPostalCode(),
phone: getRandomPhoneNumber(),
email: faker.internet.email(),
name: faker.name.firstName(),
message: faker.random.words(),
Expand Down
41 changes: 41 additions & 0 deletions cypress/support/testData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Functions to generate random data for the required fields

function getRandomName() {
const names = [
'John Doe', 'Jane Smith', 'Alex Johnson', 'Emily Davis', 'Michael Brown'];
return names[Math.floor(Math.random() * names.length)];
}

function getRandomCountry() {
const countries = ['Ukraine', 'USA', 'Canada', 'Germany', 'France'];
return countries[Math.floor(Math.random() * countries.length)];
}

function getRandomCity() {
const cities = ['Kyiv', 'New York', 'Toronto', 'Berlin', 'Paris'];
return cities[Math.floor(Math.random() * cities.length)];
}

function getRandomCreditCard() {
return Math.floor(1000000000000000 + Math.random() * 9000000000000000).toString();
}

function getRandomMonth() {
const months = [
'01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
return months[Math.floor(Math.random() * months.length)];
}

function getRandomYear() {
const currentYear = new Date().getFullYear();
return (currentYear + Math.floor(Math.random() * 5)).toString(); // Next 5 years
}

module.exports = {
getRandomName,
getRandomCountry,
getRandomCity,
getRandomCreditCard,
getRandomMonth,
getRandomYear
};
Loading