-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathusing-file-spec.cy.js
29 lines (26 loc) · 995 Bytes
/
using-file-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
/// <reference types="cypress" />
describe('Two domains using file', () => {
const filename = 'test-data.json'
it('visits 1st domain', () => {
cy.visit('https://example.cypress.io/')
// there are several GitHub links on the page, make sure
// to use the selector that returns a single item
cy.get('[href="https://github.com/cypress-io/cypress-example-kitchensink"]').first()
.invoke('attr', 'href')
.then((url) => {
expect(url).to.be.a('string')
// save the value in a local file
cy.writeFile(filename, JSON.stringify({ url }, null, 2))
})
})
it('visits 2nd domain', () => {
// we assume the first test has finished and stored URL in the file
cy.readFile(filename).then(({ url }) => {
// destructure the file into URL property
expect(url).to.be.a('string')
cy.visit(url)
})
// confirm the GitHub page loads
cy.contains('[data-hovercard-type=organization]', 'cypress-io').should('be.visible')
})
})