Closed InvisibleExo closed 3 years ago
Solved. The problem was that I defined my options.additionalSteps
inside my test spec file. If I added and defined the addtionalSteps function in the index file for Cypress plugins, options.additionSteps was invoked and operated as expected(depending on how the function was defined.
This will allow the function work as expected. I would add a condition to check whether or not I want to include addtionalSteps. (./cypress/plugins/index.js):
const {customizedLogin} = require('../../src/Plugins').CustomizedLogin
async function fewMoreSteps({page, options} = {}) {
console.log('This is the addtional step...')
await page.waitForSelector('#header_notification_link', {visible: true, timeout: 6000})
await page.click('#header_notification_link')
}
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
on('task', {
customizedLogin: (options) => {
if (options.moreSteps) {
options.additionalSteps = fewMoreSteps
}
return CustomizedLogin(options)
}
}
)
}
I don't think its possible for an object with functions to be passed through Cypress.task()
, though I would have to do some research to determine whether or not my initial approach was even possible.
Thanks for sharing @InvisibleExo ❤️ Any chance you want to update the README.md file with a pull request to include that example? I'm sure it'll be helpful for others.
@lirantal sure. I have the additions to Plugins.js I worked and tested on, as well added information for ReadMe.md all ready to be committed, but I'm getting denied when pushing my branch with changes.
@InvisibleExo Did you create a fork of this repo? if you do and you push your branch there then you can open a pull request to this one.
@lirantal I forked my own branch, and was able to push it with the changes. Thanks, used to using git only my own projects.
I'm having trouble trying to invoke a function I created as a property for the
options
Object. I'm trying to add and test a check for an additional check whether user has added a property called:additionalSteps
in theoptions
Object. The purpose foradditionalSteps
property is for the User to define an async functions , which passes in thepage
andoptions
objects as parameters, then can be used to define whatever steps a User may need to do after thetypePassword
function. (Ex: Some sign ins steps might require a PIN, Security Question, etc.) Currently, I have the check foroptions.additionalSteps
right aftertypePassword
function. If condition is true, I would then invoke theadditonalSteps
function. Problem is that it doesn't appear the function is getting invoked and code moves on to theoptions.optSecret
check. I put a boolean variable within theif
condition to determine if the function did get invoked, and the actions are being performed within a second before Chromium session closes, the results show that its not getting invoked. Initially I attempted to invoke the function asoptions.additionalSteps({page, options})
without luck. Second attempt was to declare anadditionalSteps
variable, ifoptions
does contain anadditionalSteps
property, assignaddtionalSteps = options.additionalSteps
which is then passed into parameters forbaseLoginConnect
function. Is there a factor I'm missing when trying to invoke a function from a property? Looking up on topic of invoking functions, I can't see what I'm doing wrong. (Note: I would rather try to invoke the function asoptions.additionalSteps
instead of passing it in as another parameter, to avoid lettingbaseLoginConnect
function have too many parameters.) Any advise would be helpful.Plugins.js (Pieces of Code to review would be CustomizedLogin and additionSteps check in baseLoginConnect -
test code -