0
0
Cypresstesting~10 mins

cy.readFile() assertions 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 read a file and check its content includes 'Hello'.

Cypress
cy.readFile('example.txt').should('[1]', 'Hello')
Drag options to blanks, or click blank then click option'
Ainclude
Bcontain
Chave.text
Dequal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'equal' instead of 'include' causes the test to fail if the content is longer.
Using 'have.text' is for DOM elements, not file content.
2fill in blank
medium

Complete the code to assert the file content equals exactly 'Test data'.

Cypress
cy.readFile('data.txt').should('[1]', 'Test data')
Drag options to blanks, or click blank then click option'
Acontain
Bequal
Cinclude
Dhave.length
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'include' or 'contain' will pass if the content has extra text.
Using 'have.length' is for checking length, not content.
3fill in blank
hard

Fix the error in the assertion to check the file content length is 10.

Cypress
cy.readFile('log.txt').should('have.[1]', 10)
Drag options to blanks, or click blank then click option'
Alengths
BlengthOf
Csize
Dlength
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lengthOf' causes the test to fail because it's not a valid property.
Using 'size' or 'lengths' are invalid in this context.
4fill in blank
hard

Fill both blanks to assert the file content includes 'success' and has length 5.

Cypress
cy.readFile('output.log').should('[1]', 'success').and('have.[2]', 5)
Drag options to blanks, or click blank then click option'
Ainclude
Bcontain
Clength
DlengthOf
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contain' instead of 'include' may work but is less common here.
Using 'lengthOf' causes assertion errors.
5fill in blank
hard

Fill all three blanks to assert the file content equals 'Done', contains 'Done', and has length 4.

Cypress
cy.readFile('status.txt').should('[1]', 'Done').and('[2]', 'Done').and('have.[3]', 4)
Drag options to blanks, or click blank then click option'
Aequal
Binclude
Clength
Dcontain
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing 'contain' and 'include' inconsistently.
Using 'lengthOf' instead of 'length' causes errors.