Bird
0
0

You want to assert that the file summary.txt contains the substring Completed. Which Cypress code snippet correctly performs this check?

hard📝 framework Q8 of 15
Cypress - File Operations
You want to assert that the file summary.txt contains the substring Completed. Which Cypress code snippet correctly performs this check?
Acy.readFile('summary.txt').then((text) => { expect(text).to.include('Completed') })
Bcy.readFile('summary.txt').should('include', 'Completed')
Ccy.readFile('summary.txt').should('contain.text', 'Completed')
Dcy.readFile('summary.txt').should('have.text', 'Completed')
Step-by-Step Solution
Solution:
  1. Step 1: Understand assertion methods

    cy.readFile() returns file content as a string, so assertions must be on that string.
  2. Step 2: Analyze options

    cy.readFile('summary.txt').then((text) => { expect(text).to.include('Completed') }) uses then() to get the text and asserts with expect(text).to.include(), which is correct.
  3. Step 3: Why others are wrong

    Options A, C, and D use should() with incorrect assertions for string content.
  4. Final Answer:

    cy.readFile('summary.txt').then((text) => { expect(text).to.include('Completed') }) -> Option A
  5. Quick Check:

    Use then() with expect() for substring assertions [OK]
Quick Trick: Use then() and expect() to assert file content substrings [OK]
Common Mistakes:
  • Using should() with incorrect string assertions
  • Trying to assert on chainable directly
  • Not using expect() inside then()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes