0
0
Cypresstesting~10 mins

Custom plugin development 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 define a Cypress plugin function.

Cypress
module.exports = (on, config) => {
  on('task', {
    [1]() {
      return null;
    }
  });
};
Drag options to blanks, or click blank then click option'
AmyCustomTask
BtaskFunction
ChandleTask
DcustomTaskHandler
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a function name.
Forgetting to pass the handler function.
2fill in blank
medium

Complete the code to register a custom task that logs a message.

Cypress
module.exports = (on, config) => {
  on('task', {
    logMessage(message) {
      console.[1](message);
      return null;
    }
  });
};
Drag options to blanks, or click blank then click option'
Alog
Bprint
Cwrite
Dsend
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'print' which is not a console method in JavaScript.
Using 'send' which is unrelated.
3fill in blank
hard

Fix the error in the plugin code to correctly return a value from a custom task.

Cypress
module.exports = (on, config) => {
  on('task', {
    getNumber() {
      return [1];
    }
  });
};
Drag options to blanks, or click blank then click option'
A42
Breturn 42
CPromise.resolve(42)
Dconsole.log(42)
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a raw value without Promise in async context.
Using console.log instead of returning a value.
4fill in blank
hard

Fill both blanks to define and export a plugin that registers two custom tasks.

Cypress
module.exports = ([1], [2]) => {
  on('task', {
    taskOne() {
      return 'done';
    },
    taskTwo() {
      return 123;
    }
  });
};
Drag options to blanks, or click blank then click option'
Aon
Bconfig
Cevent
Dsettings
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of parameters.
Using incorrect parameter names.
5fill in blank
hard

Fill all three blanks to create a plugin that logs a message and returns a value asynchronously.

Cypress
module.exports = ([1], [2]) => {
  on('task', {
    async logAndReturn(value) {
      console.[3](`Value is: ${value}`);
      return Promise.resolve(value);
    }
  });
};
Drag options to blanks, or click blank then click option'
Aon
Bconfig
Clog
Dprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'print' instead of 'log' for console output.
Mixing up the order of parameters.