UNPKG

cypress-run

Version:

Cypress run replacement that supports parallel execution and retries

46 lines (37 loc) 1.24 kB
/// <reference types="Cypress" /> context('Files', () => { beforeEach(() => { cy.visit('https://example.cypress.io/commands/files') }) it('cy.readFile() - read a files contents', () => { // https://on.cypress.io/readfile // You can read a file and yield its contents // The filePath is relative to your project's root. cy.readFile('cypress.json').then((json) => { expect(json).to.be.an('object') }) }) it('cy.writeFile() - write to a file', () => { // https://on.cypress.io/writefile // You can write to a file // Use a response from a request to automatically // generate a fixture file for use later cy.request('https://jsonplaceholder.typicode.com/users') .then((response) => { cy.writeFile('cypress/fixtures/users.json', response.body) }) cy.fixture('users').should((users) => { expect(users[0].name).to.exist }) // JavaScript arrays and objects are stringified // and formatted into text. cy.writeFile('cypress/fixtures/profile.json', { id: 8739, name: 'Jane', email: 'jane@example.com', }) cy.fixture('profile').should((profile) => { expect(profile.name).to.eq('Jane') }) }) })