Writing our first tests
Log in command
First lets add a command for log in to our shared commands:
Add the following function to the commands
object:
cypress/support/e2e/commands.ts
// Shared commands (always loaded)
const commands = {
login: (data) => {
const { username, password } = data
cy.get('#user-name').type(username)
cy.get('#password').type(password)
cy.get('#login-button').click()
},
};
Test files
Now we are going to create three test files:
check-inventory.cy.ts
add-to-cart.cy.ts
remove-from-cart.cy.ts
Check Inventory
cypress/e2e/saucedemo/check-inventory.cy.ts
import { users, getUrl } from '@support/helpers'
describe('Check inventory', () => {
beforeEach(() => {
cy.visit(getUrl())
cy.login(users.standard)
})
it('Check if inventory has six displayed items', () => {})
})
Add to cart
cypress/e2e/saucedemo/add-to-cart.cy.ts
import { users, getUrl } from '@support/helpers'
describe('Add to cart', () => {
beforeEach(() => {
cy.visit(getUrl())
cy.login(users.standard)
})
it('Add an item to the cart', () => {})
})
Remove from cart
cypress/e2e/saucedemo/remove-from-cart.cy.ts
import { users, getUrl } from '@support/helpers'
describe('Remove from cart', () => {
beforeEach(() => {
cy.visit(getUrl())
cy.login(users.standard)
})
it('Add an item to the cart', () => {})
})
info
We won't add actual code since we just need these files to exist so we can see how to create, and extend multiple configs in the next steps
Run
We can run our project by running the following command in the CLI
$ npm run saucedemo-staging