Bird
0
0

What will be the content of 'data.txt' after running this Cypress code?

medium📝 Predict Output Q4 of 15
Cypress - File Operations
What will be the content of 'data.txt' after running this Cypress code?
cy.writeFile('data.txt', 'Line 1')
cy.writeFile('data.txt', 'Line 2')
ALine 2
BLine 1\nLine 2
CLine 1
DLine 1Line 2
Step-by-Step Solution
Solution:
  1. Step 1: Understand cy.writeFile() default behavior

    Each call overwrites the file content unless append option is used.
  2. Step 2: Analyze the two writeFile calls

    First writes 'Line 1', second overwrites with 'Line 2'. So final content is 'Line 2'.
  3. Final Answer:

    Line 2 -> Option A
  4. Quick Check:

    writeFile overwrites by default = last write wins [OK]
Quick Trick: cy.writeFile overwrites file unless append option used [OK]
Common Mistakes:
  • Assuming writes append by default
  • Expecting both lines concatenated
  • Confusing writeFile with appendFile

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes