-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
spec.cy.js
65 lines (56 loc) · 1.45 KB
/
spec.cy.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/// <reference types="cypress" />
describe('Logging In - Basic Auth', function () {
// we can use these values to log in
const username = 'jane.lane'
const password = 'password123'
context('cy.request', () => {
// https://on.cypress.io/request
it('without authorization gets 401', () => {
cy.request({
url: '/',
failOnStatusCode: false,
}).its('status').should('equal', 401)
})
it('with authorization', () => {
cy.request({
url: '/',
auth: {
username, password,
},
}).its('status').should('equal', 200)
})
it('can post', () => {
cy.request({
url: '/echo',
method: 'POST',
auth: {
username, password,
},
body: {
text: 'ping!',
},
}).then((response) => {
expect(response.status, 'status').to.equal(200)
expect(response.body).to.deep.equal({
text: 'ping!',
})
})
})
})
context('cy.visit', () => {
// https://on.cypress.io/visit
it('loads the page using basic auth', () => {
cy.visit('/', {
auth: {
username,
password,
},
})
// confirm that all static resources have loaded
cy.get('#app-message').should('not.be.empty')
cy.log('app.js loaded')
cy.contains('h1', 'Red').should('have.css', 'color', 'rgb(255, 0, 0)')
cy.log('app.css loaded')
})
})
})