forked from cypress-io/cypress-example-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
using-file-spec.js
32 lines (29 loc) · 1.06 KB
/
using-file-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
30
31
32
/// <reference types="cypress" />
describe('Two domains using file', () => {
const filename = 'test-data.json'
it('visits 1nd domain', () => {
cy.visit('https://www.cypress.io/')
// there are several GitHub links on the page, make sure
// to use the selector that returns a single item
cy.get('header [aria-label="Check out our github page"]')
.should('have.length', 1)
// from the jQuery wrapping <a href="https://github.io ..." />
// get the "href" value
.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')
})
})