如何在 CodeCeptjs 中调用 customhelper?
How to call a customhelper in CodeCeptjs?
如何调用customhelper中定义的方法?
MycustomHelper
const { Helper } = codeceptjs;
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
const expect = chai.expect;
class MyHelper extends Helper {
async JavaScriptclick(LocatorVale) {
await browser.waitForAngularEnabled(true);
browser.executeScript("arguments[0].click();", element(by.xpath(LocatorVale)));
}
}
module.exports = MyHelper;
Code.js
helpers: {
MyHelper: {
require: './myhelper_helper.js',
},
Stepfile.js
Scenario('Add a new user group', (I, MyHelper) => {
MyHelper.JavaScriptclick(‘.badged-button.mat-raised-button.mat-primar')
});
如果我执行上面的代码,我得到以下错误
Add a new user group:
Object of type MyHelper is not defined in container
请帮我解决这个问题。我需要单击一个按钮,但 I.click 无法找到该按钮。所以在这种情况下我不得不使用 javascriptclick。但是 I.executescript 也不起作用。因此我需要使用本机量角器命令,因为它只能以这种方式工作。
无需直呼助手的名字。
所有方法都添加在actor(I
)object
如文档中所述:
Methods of Helper class will be available in tests in I
object. This abstracts test scenarios from the implementation and allows easily switching between backends.
https://codecept.io/helpers/#extending-codeceptjs-with-custom-helopers
所以,在测试中:
Scenario('Add a new user group', (I) => {
I.JavaScriptclick(‘.badged-button.mat-raised-button.mat-primar')
});
如何调用customhelper中定义的方法?
MycustomHelper
const { Helper } = codeceptjs;
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
const expect = chai.expect;
class MyHelper extends Helper {
async JavaScriptclick(LocatorVale) {
await browser.waitForAngularEnabled(true);
browser.executeScript("arguments[0].click();", element(by.xpath(LocatorVale)));
}
}
module.exports = MyHelper;
Code.js
helpers: {
MyHelper: {
require: './myhelper_helper.js',
},
Stepfile.js
Scenario('Add a new user group', (I, MyHelper) => {
MyHelper.JavaScriptclick(‘.badged-button.mat-raised-button.mat-primar')
});
如果我执行上面的代码,我得到以下错误
Add a new user group:
Object of type MyHelper is not defined in container
请帮我解决这个问题。我需要单击一个按钮,但 I.click 无法找到该按钮。所以在这种情况下我不得不使用 javascriptclick。但是 I.executescript 也不起作用。因此我需要使用本机量角器命令,因为它只能以这种方式工作。
无需直呼助手的名字。
所有方法都添加在actor(I
)object
如文档中所述:
Methods of Helper class will be available in tests in
I
object. This abstracts test scenarios from the implementation and allows easily switching between backends.
https://codecept.io/helpers/#extending-codeceptjs-with-custom-helopers
所以,在测试中:
Scenario('Add a new user group', (I) => {
I.JavaScriptclick(‘.badged-button.mat-raised-button.mat-primar')
});