-
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
update #301
base: main
Are you sure you want to change the base?
update #301
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,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(); | ||
cy.contains('a', 'Add to cart').click(); | ||
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. You need to assert the message in the alert after clicking 'Add to cart'. This is a requirement according to the task description. 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 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(); | ||
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. After clicking 'Cart', you should assert that the product is in the cart. This is necessary to ensure that the product was successfully added. 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. 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(); | ||
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. 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. 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. 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(); | ||
}); | ||
}); |
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 | ||
}; |
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 task requires selecting 'Sony vaio i7', but the script currently selects 'Sony vaio i5'. Please update this line to select the correct product.