Challenge - 5 Problems
Cypress Plugin Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a Cypress custom command plugin
What will be the output in the Cypress test runner console after running this custom command?
Cypress
Cypress.Commands.add('logMessage', (msg) => { cy.log(`Message: ${msg}`) return msg.length }) describe('Test logMessage command', () => { it('logs and returns length', () => { cy.logMessage('hello').then(length => { cy.log(`Length is ${length}`) }) }) })
Attempts:
2 left
💡 Hint
Remember that Cypress commands are asynchronous and return chainable objects.
✗ Incorrect
The custom command logs the message and returns the length of the string. The test then logs the length, so both logs appear in order.
❓ assertion
intermediate1:30remaining
Correct assertion for a plugin-modified DOM element
A Cypress plugin modifies a button's text to 'Clicked' after a click. Which assertion correctly verifies this change?
Cypress
cy.get('button#submit').click() // Which assertion verifies the text change?
Attempts:
2 left
💡 Hint
Check the difference between text content and attributes.
✗ Incorrect
The button's visible text changes, so 'have.text' is the correct assertion. 'contain' works but is less strict. 'have.value' and 'have.attr' check different properties.
🔧 Debug
advanced2:00remaining
Identify the cause of plugin command failure
A custom Cypress plugin command fails with 'TypeError: cy.wrap is not a function'. What is the most likely cause?
Attempts:
2 left
💡 Hint
Remember where Cypress commands can be used vs plugin code.
✗ Incorrect
The plugins/index.js runs in Node environment without Cypress commands. Using cy.wrap there causes this error.
🧠 Conceptual
advanced1:30remaining
Purpose of Cypress plugin file
What is the main purpose of the Cypress plugins file (cypress/plugins/index.js)?
Attempts:
2 left
💡 Hint
Think about what runs in Node vs browser in Cypress.
✗ Incorrect
The plugins file runs in Node and is used to extend Cypress behavior outside the browser, like tasks or config.
❓ framework
expert2:30remaining
Correct way to register a custom task in Cypress plugin
Which code snippet correctly registers a custom task named 'readFile' in Cypress plugins file to read a file asynchronously?
Cypress
const fs = require('fs').promises; module.exports = (on, config) => { // Register tasks here }
Attempts:
2 left
💡 Hint
Remember tasks can return promises and should be async if needed.
✗ Incorrect
Option A correctly defines an async function returning a promise from fs.readFile. Option A misses async/await, D misses return, C uses sync method without return.