Recall & Review
beginner
What is a custom plugin in Cypress?
A custom plugin in Cypress is a piece of code that extends Cypress's functionality by adding new tasks or modifying existing behavior, allowing you to customize test runs.
Click to reveal answer
beginner
Where do you define custom plugins in a Cypress project?
Custom plugins are defined in the
cypress/plugins/index.js file, where you can register new tasks or modify Cypress events.Click to reveal answer
intermediate
How do you register a new task in a Cypress plugin?
You use the
on('task', { ... }) event handler inside the plugin file to register new tasks that can be called from test code.Click to reveal answer
intermediate
Why use custom plugins instead of writing all code in test files?
Custom plugins allow you to run Node.js code outside the browser context, access system resources, or perform complex operations that are not possible directly in test files.
Click to reveal answer
advanced
What is the role of the
on and config parameters in the plugin function?The
on parameter lets you listen to Cypress events like task, while config provides the current Cypress configuration that you can modify or use.Click to reveal answer
Where do you add custom plugin code in a Cypress project?
✗ Incorrect
Custom plugins are added in cypress/plugins/index.js to extend Cypress functionality.
Which Cypress event is used to register custom tasks in a plugin?
✗ Incorrect
The 'task' event is used to register custom tasks that run in the Node environment.
Why might you create a custom plugin instead of writing code directly in tests?
✗ Incorrect
Custom plugins allow running Node.js code that cannot run in the browser context of tests.
What does the
config parameter in the plugin function provide?✗ Incorrect
The config parameter gives access to Cypress configuration which can be read or modified.
Which file would you NOT modify to create a custom Cypress plugin?
✗ Incorrect
Test files like integration/sample_spec.js are for writing tests, not plugins.
Explain how to create and register a custom task in a Cypress plugin.
Think about the plugin file and how Cypress listens for tasks.
You got /4 concepts.
Describe why and when you would use a custom plugin in Cypress testing.
Consider what test code cannot do alone.
You got /4 concepts.