0
0
Cypresstesting~10 mins

Writing to files (cy.writeFile) in Cypress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to write the string 'Hello World' to a file named 'greeting.txt'.

Cypress
cy.[1]('greeting.txt', 'Hello World')
Drag options to blanks, or click blank then click option'
Avisit
Bget
CwriteFile
DreadFile
Attempts:
3 left
💡 Hint
Common Mistakes
Using cy.readFile instead of cy.writeFile
Forgetting to specify the file name
Using cy.visit which is for visiting URLs
2fill in blank
medium

Complete the code to write an object { name: 'Alice' } to 'user.json' as JSON.

Cypress
cy.[1]('user.json', { name: 'Alice' })
Drag options to blanks, or click blank then click option'
AwriteFile
Blog
Crequest
DreadFile
Attempts:
3 left
💡 Hint
Common Mistakes
Using cy.readFile instead of cy.writeFile
Trying to write objects with cy.log
Using cy.request which is for HTTP calls
3fill in blank
hard

Fix the error in the code to correctly write 'Test data' to 'data.txt'.

Cypress
cy.writeFile('data.txt', [1])
Drag options to blanks, or click blank then click option'
AwriteFile
B'Test data'
CTest data
Dcy.writeFile
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the string data
Passing the command name instead of data
Using cy.writeFile inside the argument
4fill in blank
hard

Fill both blanks to write an array ['apple', 'banana'] to 'fruits.json' as JSON.

Cypress
cy.[1]('fruits.json', [2])
Drag options to blanks, or click blank then click option'
AwriteFile
BreadFile
C['apple', 'banana']
D{apple: 'banana'}
Attempts:
3 left
💡 Hint
Common Mistakes
Using cy.readFile instead of cy.writeFile
Passing an object instead of an array
Passing the array as a string
5fill in blank
hard

Fill all three blanks to write a JSON object with uppercase keys to 'config.json'.

Cypress
const config = { [1]: 'value1', [2]: 'value2' };
cy.[3]('config.json', config);
Drag options to blanks, or click blank then click option'
A'API_KEY'
B'TIMEOUT'
CwriteFile
D'api_key'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase keys instead of uppercase
Not quoting the keys
Using cy.readFile instead of cy.writeFile