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

develop #300

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
58 changes: 53 additions & 5 deletions cypress/e2e/checkout.cy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,59 @@
/* eslint-disable */
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('', () => {
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 does not exist in the Faker.js library. You should use a valid method to generate a future year, such as new Date().getFullYear() + 5 to get a year 5 years in the future.

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

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

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

cy.on('window:alert', (alertText) => {
expect(alertText).to.contains(testData.successMessage)
})

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

it('', () => {
cartPage.clickOnPlaceOrder()
cartPage.fillOrderDetails(
testData.name,
testData.country,
testData.city,
testData.creditCard,
testData.month,
testData.year
)
cartPage.clickOnPurchase()

});
});
cartPage.assertModalData(
testData.name,
testData.country,
testData.city,
testData.creditCard,
testData.month,
testData.year
)
cartPage.clickOnOk()
})
})
36 changes: 18 additions & 18 deletions cypress/e2e/contactForm.cy.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import ContactFormPageObject from '../support/pages/contactForm.pageObject';
import HomeAndCataloguePageObject
from '../support/pages/homeCatalogue.pageObject';
import faker from 'faker';
/* eslint-disable */
import { faker } from '@faker-js/faker'
import ContactFormPageObject from '../support/pages/contactForm.pageObject'
import HomeAndCataloguePageObject from '../support/pages/homeСatalogue.pageObject'
/// <reference types='cypress' />

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

const testData = {
email: faker.internet.email(),
name: faker.name.firstName(),
message: faker.random.words(),
successMessage: 'Thanks for the message!!'
};
successMessage: 'Thanks for the message!!',
}

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

it('should provide the ability to send feedback', () => {
homePage.clickOnLink('Contact');
contactForm.typeEmail(testData.email);
contactForm.typeName(testData.name);
contactForm.typeMessage(testData.message);
contactForm.clickOnSendMessageBtn();
homePage.clickOnLink('Contact')
contactForm.typeEmail(testData.email)
contactForm.typeName(testData.name)
contactForm.typeMessage(testData.message)
contactForm.clickOnSendMessageBtn()

contactForm.assertAllert(testData.successMessage);
});
});
contactForm.assertAllert(testData.successMessage)
})
})
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) => { ... })
41 changes: 41 additions & 0 deletions cypress/support/pages/cart.pageObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* eslint-disable */

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 +27 to +34

Choose a reason for hiding this comment

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

The assertModalData method should verify that the modal contains the expected values for name, country, city, creditCard, month, and year. Currently, it only checks for the presence of certain text elements. Consider using assertions that compare the actual text content of these elements with the expected values passed as parameters.


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

export default CartPageObject
23 changes: 12 additions & 11 deletions cypress/support/pages/contactForm.pageObject.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
import PageObject from '../PageObject';
/* eslint-disable */
import PageObject from '../PageObject'

class ContactFormPageObject extends PageObject {
url = '/index.html';
url = '/index.html'

get emailField() {
return cy.get('#recipient-email');
return cy.get('#recipient-email')
}

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

get messageField() {
return cy.get('#message-text');
return cy.get('#message-text')
}

get sendMessageBtn() {
return cy.contains('.btn', 'Send message');
return cy.contains('.btn', 'Send message')
}

typeEmail(email) {
this.emailField.type(email, { force: true });
this.emailField.type(email, { force: true })
}

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

typeMessage(message) {
this.messageField.type(message);
this.messageField.type(message)
}

clickOnSendMessageBtn() {
this.sendMessageBtn.click();
this.sendMessageBtn.click()
}
}

export default ContactFormPageObject;
export default ContactFormPageObject
30 changes: 20 additions & 10 deletions cypress/support/pages/homeCatalogue.pageObject.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
import PageObject from '../PageObject';
/* eslint-disable */

import PageObject from '../PageObject'

class HomeAndCataloguePageObject extends PageObject {
url = '/index.html';
url = '/index.html'

clickOnLink(linkName) {
cy.contains('.nav-link', linkName)
.click();
cy.contains('.nav-link', linkName).click()
}

clickOnCategory(categoryName) {
cy.contains('#itemc', categoryName)
.click();
cy.contains('#itemc', categoryName).click()
}

clickOnProduct(product) {
cy.contains('.hrefch', product)
.click();
cy.contains('.hrefch', product).click()
}

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

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

clickOnCart() {
cy.contains('Cart').click()
}
}
export default HomeAndCataloguePageObject
Loading