-
Notifications
You must be signed in to change notification settings - Fork 318
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 #298
base: main
Are you sure you want to change the base?
Solution #298
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,60 @@ | ||
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('', () => { | ||
before(() => { | ||
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(), | ||
productName: 'Sony vaio i7', | ||
successMessage: 'Product added' | ||
}; | ||
|
||
describe('Shopping Cart', () => { | ||
before(() => { | ||
homePage.visit(); | ||
}); | ||
|
||
it('', () => { | ||
it('should allow a user to add a product to the cart', () => { | ||
homePage.clickOnLaptops(); | ||
homePage.clickOnProduct(testData.productName); | ||
homePage.addToCart(); | ||
|
||
// Assert the product was added | ||
cy.on('window:alert', (alertText) => { | ||
expect(alertText).to.contains(testData.successMessage); | ||
}); | ||
|
||
homePage.clickOnCart(); | ||
cartPage.assertProductInCart(testData.productName); | ||
|
||
cartPage.clickOnPlaceOrder(); | ||
cartPage.fillOrderDetails( | ||
testData.name, | ||
testData.country, | ||
testData.city, | ||
testData.creditCard, | ||
testData.month, | ||
testData.year | ||
); | ||
cartPage.clickOnPurchase(); | ||
|
||
// Assert the modal shows the correct information | ||
cartPage.assertModalData( | ||
testData.name, | ||
testData.country, | ||
testData.city, | ||
testData.creditCard, | ||
testData.month, | ||
testData.year | ||
); | ||
cartPage.clickOnOk(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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
+25
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
clickOnOk() { | ||
cy.contains('OK').click(); | ||
} | ||
} | ||
|
||
export default CartPageObject; |
There was a problem hiding this comment.
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({ years: 5 }).getFullYear()
might not work as expected becausefaker.date.future()
returns a Date object, and callinggetFullYear()
directly on it may not be valid. Consider usingfaker.date.future(5).getFullYear()
instead.