我正在努力为登录功能添加额外的检查。如果传递给函数的对象包含属性名称additionalSteps,它将调用additionalSteps 属性。但是,每当我到达调用步骤时,都会收到一条错误消息,指出该属性不是函数或未定义。options.additionalSteps
(取决于我如何通过调用对象 property( ) 或将局部变量分配给对象 property( )来调整代码let additionalSteps
。)
我想知道是否可以传递一个具有定义函数/方法的属性的对象,然后将该对象传递到导入类(或使用)的函数中,该函数将检查属性名称是否存在,然后调用该对象的require
函数如果条件为真。我可以让其他文件定义并处理该函数,但我希望用户按照他们的意愿定义属性函数。
根据我对该主题的研究,我对属性的感觉是不可能通过对象内的另一个文件传递函数/方法。(有关具有函数的对象属性的所有信息和示例似乎暗示这不受支持。)
测试代码:
async function fewMoreSteps({page, options} = {}) {
console.log('This is the addtional step...')
await page.waitForSelector('#header_notification_link', {visible: true})
await page.click('#header_notification_link')
}
describe('Test Login', () => {
// eslint-disable-next-line jest/no-focused-tests
it.only('Login with custom function', () => {
const username = Cypress.env('steamUserName')
const password = Cypress.env('steamUserNamePW')
const loginUrl = Cypress.env('loginUrl')
const loginSelector = Cypress.env('loginSelector')
const cookieName = Cypress.env('cookieName')
const socialLoginOptions = {
username,
password,
loginUrl,
// Add username/pw fields and buttons and addtional steps
usernameField: '#input_username',
passwordField: '#input_password',
passwordSubmitBtn: '#login_btn_signin',
// make this a global passed function
additionalSteps: async function({page, options} = {}) {
/*console.log('This is the addtional step...')
await page.waitForSelector('#header_notification_link', {visible: true})
await page.click('#header_notification_link') */
await fewMoreSteps({page, options})
},
isPopup: true,
popupDelay: 6000,
logs: true,
headless: false,
loginSelector: loginSelector,
postLoginClick: '#account_pulldown',
postLoginSelector: '#account_dropdown div.popup_menu a.popup_menu_item:first-of-type'
}
慕姐4208626
相关分类