|
1 | 1 | /// <reference types="cypress" /> |
2 | 2 |
|
3 | | -context('Cypress.Commands', () => { |
4 | | - beforeEach(() => { |
5 | | - cy.visit('http://localhost:8080/cypress-api') |
6 | | - }) |
| 3 | +context('Cypress APIs', () => { |
| 4 | + |
| 5 | + context('Cypress.Commands', () => { |
| 6 | + beforeEach(() => { |
| 7 | + cy.visit('http://localhost:8080/cypress-api') |
| 8 | + }) |
7 | 9 |
|
8 | | - // https://on.cypress.io/custom-commands |
| 10 | + // https://on.cypress.io/custom-commands |
9 | 11 |
|
10 | | - it('.add() - create a custom command', () => { |
11 | | - Cypress.Commands.add('console', { |
12 | | - prevSubject: true, |
13 | | - }, (subject, method) => { |
| 12 | + it('.add() - create a custom command', () => { |
| 13 | + Cypress.Commands.add('console', { |
| 14 | + prevSubject: true, |
| 15 | + }, (subject, method) => { |
14 | 16 | // the previous subject is automatically received |
15 | 17 | // and the commands arguments are shifted |
16 | 18 |
|
17 | | - // allow us to change the console method used |
18 | | - method = method || 'log' |
| 19 | + // allow us to change the console method used |
| 20 | + method = method || 'log' |
19 | 21 |
|
20 | | - // log the subject to the console |
21 | | - // eslint-disable-next-line no-console |
22 | | - console[method]('The subject is', subject) |
| 22 | + // log the subject to the console |
| 23 | + // eslint-disable-next-line no-console |
| 24 | + console[method]('The subject is', subject) |
23 | 25 |
|
24 | | - // whatever we return becomes the new subject |
25 | | - // we don't want to change the subject so |
26 | | - // we return whatever was passed in |
27 | | - return subject |
28 | | - }) |
| 26 | + // whatever we return becomes the new subject |
| 27 | + // we don't want to change the subject so |
| 28 | + // we return whatever was passed in |
| 29 | + return subject |
| 30 | + }) |
29 | 31 |
|
30 | | - // eslint-disable-next-line no-unused-vars |
31 | | - cy.get('button').console('info').then(($button) => { |
| 32 | + // eslint-disable-next-line no-unused-vars |
| 33 | + cy.get('button').console('info').then(($button) => { |
32 | 34 | // subject is still $button |
| 35 | + }) |
33 | 36 | }) |
34 | 37 | }) |
35 | | -}) |
36 | 38 |
|
37 | | -context('Cypress.Cookies', () => { |
38 | | - beforeEach(() => { |
39 | | - cy.visit('http://localhost:8080/cypress-api') |
40 | | - }) |
| 39 | + context('Cypress.Cookies', () => { |
| 40 | + beforeEach(() => { |
| 41 | + cy.visit('http://localhost:8080/cypress-api') |
| 42 | + }) |
41 | 43 |
|
42 | | - // https://on.cypress.io/cookies |
43 | | - it('.debug() - enable or disable debugging', () => { |
44 | | - Cypress.Cookies.debug(true) |
45 | | - |
46 | | - // Cypress will now log in the console when |
47 | | - // cookies are set or cleared |
48 | | - cy.setCookie('fakeCookie', '123ABC') |
49 | | - cy.clearCookie('fakeCookie') |
50 | | - cy.setCookie('fakeCookie', '123ABC') |
51 | | - cy.clearCookie('fakeCookie') |
52 | | - cy.setCookie('fakeCookie', '123ABC') |
| 44 | + // https://on.cypress.io/cookies |
| 45 | + it('.debug() - enable or disable debugging', () => { |
| 46 | + Cypress.Cookies.debug(true) |
| 47 | + |
| 48 | + // Cypress will now log in the console when |
| 49 | + // cookies are set or cleared |
| 50 | + cy.setCookie('fakeCookie', '123ABC') |
| 51 | + cy.clearCookie('fakeCookie') |
| 52 | + cy.setCookie('fakeCookie', '123ABC') |
| 53 | + cy.clearCookie('fakeCookie') |
| 54 | + cy.setCookie('fakeCookie', '123ABC') |
| 55 | + }) |
53 | 56 | }) |
54 | | -}) |
55 | 57 |
|
56 | | -context('Cypress.arch', () => { |
57 | | - beforeEach(() => { |
58 | | - cy.visit('http://localhost:8080/cypress-api') |
59 | | - }) |
| 58 | + context('Cypress.arch', () => { |
| 59 | + beforeEach(() => { |
| 60 | + cy.visit('http://localhost:8080/cypress-api') |
| 61 | + }) |
60 | 62 |
|
61 | | - it('Get CPU architecture name of underlying OS', () => { |
| 63 | + it('Get CPU architecture name of underlying OS', () => { |
62 | 64 | // https://on.cypress.io/arch |
63 | | - expect(Cypress.arch).to.exist |
| 65 | + expect(Cypress.arch).to.exist |
| 66 | + }) |
64 | 67 | }) |
65 | | -}) |
66 | 68 |
|
67 | | -context('Cypress.config()', () => { |
68 | | - beforeEach(() => { |
69 | | - cy.visit('http://localhost:8080/cypress-api') |
70 | | - }) |
| 69 | + context('Cypress.config()', () => { |
| 70 | + beforeEach(() => { |
| 71 | + cy.visit('http://localhost:8080/cypress-api') |
| 72 | + }) |
71 | 73 |
|
72 | | - it('Get and set configuration options', () => { |
| 74 | + it('Get and set configuration options', () => { |
73 | 75 | // https://on.cypress.io/config |
74 | | - let myConfig = Cypress.config() |
| 76 | + let myConfig = Cypress.config() |
75 | 77 |
|
76 | | - expect(myConfig).to.have.property('animationDistanceThreshold', 5) |
77 | | - expect(myConfig).to.have.property('baseUrl', null) |
78 | | - expect(myConfig).to.have.property('defaultCommandTimeout', 4000) |
79 | | - expect(myConfig).to.have.property('requestTimeout', 5000) |
80 | | - expect(myConfig).to.have.property('responseTimeout', 30000) |
81 | | - expect(myConfig).to.have.property('viewportHeight', 660) |
82 | | - expect(myConfig).to.have.property('viewportWidth', 1000) |
83 | | - expect(myConfig).to.have.property('pageLoadTimeout', 60000) |
84 | | - expect(myConfig).to.have.property('waitForAnimations', true) |
| 78 | + expect(myConfig).to.have.property('animationDistanceThreshold', 5) |
| 79 | + expect(myConfig).to.have.property('baseUrl', null) |
| 80 | + expect(myConfig).to.have.property('defaultCommandTimeout', 4000) |
| 81 | + expect(myConfig).to.have.property('requestTimeout', 5000) |
| 82 | + expect(myConfig).to.have.property('responseTimeout', 30000) |
| 83 | + expect(myConfig).to.have.property('viewportHeight', 660) |
| 84 | + expect(myConfig).to.have.property('viewportWidth', 1000) |
| 85 | + expect(myConfig).to.have.property('pageLoadTimeout', 60000) |
| 86 | + expect(myConfig).to.have.property('waitForAnimations', true) |
85 | 87 |
|
86 | | - expect(Cypress.config('pageLoadTimeout')).to.eq(60000) |
| 88 | + expect(Cypress.config('pageLoadTimeout')).to.eq(60000) |
87 | 89 |
|
88 | | - // this will change the config for the rest of your tests! |
89 | | - Cypress.config('pageLoadTimeout', 20000) |
| 90 | + // this will change the config for the rest of your tests! |
| 91 | + Cypress.config('pageLoadTimeout', 20000) |
90 | 92 |
|
91 | | - expect(Cypress.config('pageLoadTimeout')).to.eq(20000) |
| 93 | + expect(Cypress.config('pageLoadTimeout')).to.eq(20000) |
92 | 94 |
|
93 | | - Cypress.config('pageLoadTimeout', 60000) |
| 95 | + Cypress.config('pageLoadTimeout', 60000) |
| 96 | + }) |
94 | 97 | }) |
95 | | -}) |
96 | 98 |
|
97 | | -context('Cypress.dom', () => { |
98 | | - beforeEach(() => { |
99 | | - cy.visit('http://localhost:8080/cypress-api') |
100 | | - }) |
| 99 | + context('Cypress.dom', () => { |
| 100 | + beforeEach(() => { |
| 101 | + cy.visit('http://localhost:8080/cypress-api') |
| 102 | + }) |
101 | 103 |
|
102 | | - // https://on.cypress.io/dom |
103 | | - it('.isHidden() - determine if a DOM element is hidden', () => { |
104 | | - let hiddenP = Cypress.$('.dom-p p.hidden').get(0) |
105 | | - let visibleP = Cypress.$('.dom-p p.visible').get(0) |
| 104 | + // https://on.cypress.io/dom |
| 105 | + it('.isHidden() - determine if a DOM element is hidden', () => { |
| 106 | + let hiddenP = Cypress.$('.dom-p p.hidden').get(0) |
| 107 | + let visibleP = Cypress.$('.dom-p p.visible').get(0) |
106 | 108 |
|
107 | | - // our first paragraph has css class 'hidden' |
108 | | - expect(Cypress.dom.isHidden(hiddenP)).to.be.true |
109 | | - expect(Cypress.dom.isHidden(visibleP)).to.be.false |
| 109 | + // our first paragraph has css class 'hidden' |
| 110 | + expect(Cypress.dom.isHidden(hiddenP)).to.be.true |
| 111 | + expect(Cypress.dom.isHidden(visibleP)).to.be.false |
| 112 | + }) |
110 | 113 | }) |
111 | | -}) |
112 | 114 |
|
113 | | -context('Cypress.env()', () => { |
114 | | - beforeEach(() => { |
115 | | - cy.visit('http://localhost:8080/cypress-api') |
116 | | - }) |
| 115 | + context('Cypress.env()', () => { |
| 116 | + beforeEach(() => { |
| 117 | + cy.visit('http://localhost:8080/cypress-api') |
| 118 | + }) |
117 | 119 |
|
118 | | - // We can set environment variables for highly dynamic values |
| 120 | + // We can set environment variables for highly dynamic values |
119 | 121 |
|
120 | | - // https://on.cypress.io/environment-variables |
121 | | - it('Get environment variables', () => { |
| 122 | + // https://on.cypress.io/environment-variables |
| 123 | + it('Get environment variables', () => { |
122 | 124 | // https://on.cypress.io/env |
123 | 125 | // set multiple environment variables |
124 | | - Cypress.env({ |
125 | | - host: 'veronica.dev.local', |
126 | | - api_server: 'http://localhost:8888/v1/', |
127 | | - }) |
| 126 | + Cypress.env({ |
| 127 | + host: 'veronica.dev.local', |
| 128 | + api_server: 'http://localhost:8888/v1/', |
| 129 | + }) |
128 | 130 |
|
129 | | - // get environment variable |
130 | | - expect(Cypress.env('host')).to.eq('veronica.dev.local') |
| 131 | + // get environment variable |
| 132 | + expect(Cypress.env('host')).to.eq('veronica.dev.local') |
131 | 133 |
|
132 | | - // set environment variable |
133 | | - Cypress.env('api_server', 'http://localhost:8888/v2/') |
134 | | - expect(Cypress.env('api_server')).to.eq('http://localhost:8888/v2/') |
| 134 | + // set environment variable |
| 135 | + Cypress.env('api_server', 'http://localhost:8888/v2/') |
| 136 | + expect(Cypress.env('api_server')).to.eq('http://localhost:8888/v2/') |
135 | 137 |
|
136 | | - // get all environment variable |
137 | | - expect(Cypress.env()).to.have.property('host', 'veronica.dev.local') |
138 | | - expect(Cypress.env()).to.have.property('api_server', 'http://localhost:8888/v2/') |
| 138 | + // get all environment variable |
| 139 | + expect(Cypress.env()).to.have.property('host', 'veronica.dev.local') |
| 140 | + expect(Cypress.env()).to.have.property('api_server', 'http://localhost:8888/v2/') |
| 141 | + }) |
139 | 142 | }) |
140 | | -}) |
141 | 143 |
|
142 | | -context('Cypress.log', () => { |
143 | | - beforeEach(() => { |
144 | | - cy.visit('http://localhost:8080/cypress-api') |
145 | | - }) |
| 144 | + context('Cypress.log', () => { |
| 145 | + beforeEach(() => { |
| 146 | + cy.visit('http://localhost:8080/cypress-api') |
| 147 | + }) |
146 | 148 |
|
147 | | - it('Control what is printed to the Command Log', () => { |
| 149 | + it('Control what is printed to the Command Log', () => { |
148 | 150 | // https://on.cypress.io/cypress-log |
| 151 | + }) |
149 | 152 | }) |
150 | | -}) |
151 | 153 |
|
152 | | -context('Cypress.platform', () => { |
153 | | - beforeEach(() => { |
154 | | - cy.visit('http://localhost:8080/cypress-api') |
155 | | - }) |
| 154 | + context('Cypress.platform', () => { |
| 155 | + beforeEach(() => { |
| 156 | + cy.visit('http://localhost:8080/cypress-api') |
| 157 | + }) |
156 | 158 |
|
157 | | - it('Get underlying OS name', () => { |
| 159 | + it('Get underlying OS name', () => { |
158 | 160 | // https://on.cypress.io/platform |
159 | | - expect(Cypress.platform).to.be.exist |
| 161 | + expect(Cypress.platform).to.be.exist |
| 162 | + }) |
160 | 163 | }) |
161 | | -}) |
162 | 164 |
|
163 | | -context('Cypress.version', () => { |
164 | | - beforeEach(() => { |
165 | | - cy.visit('http://localhost:8080/cypress-api') |
166 | | - }) |
| 165 | + context('Cypress.version', () => { |
| 166 | + beforeEach(() => { |
| 167 | + cy.visit('http://localhost:8080/cypress-api') |
| 168 | + }) |
167 | 169 |
|
168 | | - it('Get current version of Cypress being run', () => { |
| 170 | + it('Get current version of Cypress being run', () => { |
169 | 171 | // https://on.cypress.io/version |
170 | | - expect(Cypress.version).to.be.exist |
| 172 | + expect(Cypress.version).to.be.exist |
| 173 | + }) |
171 | 174 | }) |
172 | | -}) |
173 | 175 |
|
174 | | -context('Cypress.spec', () => { |
175 | | - beforeEach(() => { |
176 | | - cy.visit('http://localhost:8080/cypress-api') |
177 | | - }) |
| 176 | + context('Cypress.spec', () => { |
| 177 | + beforeEach(() => { |
| 178 | + cy.visit('http://localhost:8080/cypress-api') |
| 179 | + }) |
178 | 180 |
|
179 | | - it('Get current spec information', () => { |
| 181 | + it('Get current spec information', () => { |
180 | 182 | // https://on.cypress.io/spec |
181 | 183 | // wrap the object so we can inspect it easily by clicking in the command log |
182 | | - cy.wrap(Cypress.spec).should('include.keys', ['name', 'relative', 'absolute']) |
| 184 | + cy.wrap(Cypress.spec).should('include.keys', ['name', 'relative', 'absolute']) |
| 185 | + }) |
183 | 186 | }) |
184 | 187 | }) |
0 commit comments