Cypress - File OperationsHow can you read a JSON file and modify a property before using it in a test?Choose the correct approach.Acy.readFile('data.json').then(data => data.newProp = 123); cy.log(data.newProp)Bconst data = cy.readFile('data.json'); data.newProp = 123;Ccy.readFile('data.json').newProp = 123;Dcy.readFile('data.json').then(data => { data.newProp = 123; /* use data here */ })Check Answer
Step-by-Step SolutionSolution:Step 1: Use .then() to access and modify JSON dataModification must happen inside the .then() callback where data is available.Step 2: Avoid accessing data outside the callbackAssigning or modifying outside causes errors or undefined behavior.Final Answer:cy.readFile('data.json').then(data => { data.newProp = 123; /* use data here */ }) -> Option DQuick Check:Modify data inside .then() callback only [OK]Quick Trick: Modify JSON data only inside .then() callback [OK]Common Mistakes:Trying to assign outside .then()Assuming cy.readFile returns data synchronouslyAccessing modified data outside callback
Master "File Operations" in Cypress9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepTraceTryChallengeAutomateRecallFrame
More Cypress Quizzes Authentication and Sessions - Local storage management - Quiz 15hard CI/CD and Reporting - Cypress CLI execution - Quiz 14medium CI/CD and Reporting - Docker execution - Quiz 13medium Component Testing - Component test setup - Quiz 6medium File Operations - Writing to files (cy.writeFile) - Quiz 8hard File Operations - File download verification - Quiz 15hard File Operations - File download verification - Quiz 14medium Plugins and Ecosystem - cypress-axe for accessibility - Quiz 1easy Test Organization and Patterns - Page Object Model in Cypress - Quiz 11easy Test Organization and Patterns - App Actions pattern - Quiz 12easy