0
0
Cypresstesting~10 mins

Reading file contents 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 named 'example.txt' using Cypress.

Cypress
cy.[1]('example.txt').then((content) => {
  expect(content).to.exist
})
Drag options to blanks, or click blank then click option'
AreadFile
BwriteFile
Cvisit
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'writeFile' instead of 'readFile'.
Using 'visit' which is for URLs, not files.
2fill in blank
medium

Complete the code to assert that the file content includes the word 'Hello'.

Cypress
cy.readFile('example.txt').then((content) => {
  expect(content).to.[1]('Hello')
})
Drag options to blanks, or click blank then click option'
Aequal
Bhave.length
Cbe.empty
Dinclude
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'equal' which requires exact match.
Using 'be.empty' which checks for empty content.
3fill in blank
hard

Fix the error in the code to correctly read a JSON file and assert a property value.

Cypress
cy.readFile('data.json').then((data) => {
  expect(data.[1]).to.equal('John')
})
Drag options to blanks, or click blank then click option'
Ausername
BName
Cname
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Name' with uppercase 'N' which does not match the JSON property.
Using unrelated property names like 'username' or 'user'.
4fill in blank
hard

Fill both blanks to read a file and assert its length is greater than 10.

Cypress
cy.readFile('log.txt').then((content) => {
  expect(content.[1]).to.[2](10)
})
Drag options to blanks, or click blank then click option'
Alength
Bbe.greaterThan
Cbe.lessThan
Dlength()
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'length()' which is not a property but a method (strings use property).
Using 'be.lessThan' which checks for smaller values.
5fill in blank
hard

Fill all three blanks to read a JSON file, filter users older than 18, and assert the count.

Cypress
cy.readFile('users.json').then((users) => {
  const adults = users.filter(user => user.[1] [2] 18)
  expect(adults.[3]).to.equal(3)
})
Drag options to blanks, or click blank then click option'
Aage
B>
Clength
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' instead of 'age' for filtering.
Using '<' instead of '>' operator.
Checking 'length()' instead of 'length' property.