0
0
Cypresstesting~10 mins

Using fixtures in tests 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 load a fixture file named 'user.json' in a Cypress test.

Cypress
cy.fixture('[1]').then((user) => {
  expect(user).to.have.property('name')
})
Drag options to blanks, or click blank then click option'
Adata.json
Buser
Cuser.json
Dconfig
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the file extension in the fixture filename.
Using a variable name instead of the filename.
2fill in blank
medium

Complete the code to use the loaded fixture data inside a test.

Cypress
cy.fixture('user.json').then(([1]) => {
  cy.log([1].email)
})
Drag options to blanks, or click blank then click option'
Auser
BuserData
Cinfo
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using the fixture filename as the variable name without quotes.
Using an invalid variable name.
3fill in blank
hard

Fix the error in the code to correctly use fixture data in a test.

Cypress
beforeEach(() => {
  cy.fixture('settings.json').[1]((settings) => {
    this.settings = settings
  })
})
Drag options to blanks, or click blank then click option'
Aload
Bthen
Cget
Dread
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'load' or 'get' on the fixture command.
Not handling the asynchronous nature of fixture loading.
4fill in blank
hard

Fill both blanks to correctly assert a property from fixture data in a test.

Cypress
cy.fixture('profile.json').then((data) => {
  expect(data.[1]).to.[2]('active')
})
Drag options to blanks, or click blank then click option'
Astatus
Bequal
Cinclude
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong property name that does not exist in the fixture.
Using an assertion method that checks inclusion instead of equality.
5fill in blank
hard

Fill all three blanks to create a test that loads a fixture, visits a URL, and asserts a page element contains fixture data.

Cypress
cy.fixture('[1]').then((user) => {
  cy.visit('[2]')
  cy.get('[3]').should('contain', user.name)
})
Drag options to blanks, or click blank then click option'
Auser.json
B/profile
C.profile-name
Dsettings.json
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong fixture filename that does not contain 'name'.
Visiting an unrelated URL.
Using an incorrect or missing selector for the element.