forked from cypress-io/cypress-example-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
users-spec.js
29 lines (25 loc) · 814 Bytes
/
users-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/// <reference types="cypress" />
// we can access the Cypress.env() object outside the test
const users = Cypress.env('users')
describe('Users from API', () => {
before(() => {
// confirm the users data has been set
expect(users).to.be.an('array').and.to.have.length(3)
})
beforeEach(() => {
cy.visit('index.html')
})
users.forEach((user) => {
it(`has the user ${user.id} ${user.username} ${user.email}`, () => {
// confirm the user object has the expected keys
expect(user).to.include.keys(['id', 'username', 'email'])
// check the page
cy.contains('td[data-cy=userId]', user.id)
.parent('tr')
.within(() => {
cy.contains('td[data-cy=username]', user.username)
cy.contains('td[data-cy=email]', user.email)
})
})
})
})