Bird
0
0

Which of the following is the correct way to read the contents of a file named log.txt using Cypress?

easy📝 Syntax Q3 of 15
Cypress - File Operations
Which of the following is the correct way to read the contents of a file named log.txt using Cypress?
Acy.readFile('log.txt').getContent()
Bcy.readFile('log.txt', (content) => { /* use content */ })
Ccy.readFile('log.txt').then((content) => { /* use content */ })
Dcy.readFile('log.txt').read()
Step-by-Step Solution
Solution:
  1. Step 1: Recall the syntax

    The correct syntax uses then() to handle the promise returned by cy.readFile().
  2. Step 2: Analyze options

    cy.readFile('log.txt').then((content) => { /* use content */ }) correctly chains then() with a callback. Options B, C, and D use invalid syntax or methods.
  3. Final Answer:

    cy.readFile('log.txt').then((content) => { /* use content */ }) -> Option C
  4. Quick Check:

    Use then() to access file content asynchronously [OK]
Quick Trick: Always use .then() to handle readFile results [OK]
Common Mistakes:
  • Passing callback directly as second argument
  • Using non-existent methods like getContent()
  • Trying to read synchronously without then()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes