-
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
added tests #299
base: main
Are you sure you want to change the base?
added tests #299
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,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 }) | ||
}; | ||
/// <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); | ||
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 method 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. Ensure that the |
||
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(); | ||
}); | ||
}); |
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); | ||
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. Consider using a more flexible assertion like |
||
} | ||
|
||
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); | ||
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. Ensure that the selector |
||
} | ||
|
||
closePurchaseModal() { | ||
cy.get('button.confirm') | ||
.click(); | ||
} | ||
} | ||
|
||
export default CartPageObject; |
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; |
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 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.