What I am trying: Pass multiple arguments in cy.task()
command and print those argument values declared in function mentioned in plugins/index.js
file
Issue: The function print prints only the first argument value and undefined for a second argument
Code:
//test file with cy.task() command
class LoginPage {
let site = abc
let userDetails = xyz
openPage(env, site, userDetails) {
cy.task('loadUserAccountDetails', site, userDetails)
}
}
module.exports = LoginPage
// plugins/index.js file where the event is registered with declared function
const validUserDetails = (site, userDetails) => {
console.log('--->' + site) // This prints abc
console.log('--->' + userDetails) // This prints undefined
}
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
on('task', {
loadUserAccountDetails: validUserDetails
})
}
Kindly help.
Looks like only one param is handled. But you can always pass in an object with the vars as properties.
on("task", {
async "rename"({var1, var2, var2}) {
}
and in the .spec
call it as
cy.task('rename', {var1: 'val1', var2:'val2', var3: 'val3'}, ()=>{
console.log('renamed');
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With