Chai expect - expect(browser.getTitle()) 错误 - browser.getTitle 不是函数
Chai expect - expect(browser.getTitle()) errors with - browser.getTitle is not a function
我有以下使用 Chai 的代码,但是当执行失败并且控制台 returns "TypeError: browser.getTitle is not a function."
我通往 Globals.js 的路径是正确的,因为如果我这样做,它会起作用 - expect('Test abc').toContain('abc')
。请帮忙。
const Globals = require('../utilities/Globals');
const browser = require('protractor');
const { Given } = require('cucumber');
// Chai
const globals = new Globals();
const expect = globals.expect;
Given('I am on google page with title {string}', function (title) {
return expect(browser.getTitle()).to.eventually.equal(title);
});
这是Globals.js-
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
class Globals {
constructor() {
this.expect = chai.expect;
chai.use(chaiAsPromised);
}
}
module.exports = Globals;
browser
是全局变量,可以直接使用,不需要。因此下面一行是不必要的:
const browser = require('protractor');
我有以下使用 Chai 的代码,但是当执行失败并且控制台 returns "TypeError: browser.getTitle is not a function."
我通往 Globals.js 的路径是正确的,因为如果我这样做,它会起作用 - expect('Test abc').toContain('abc')
。请帮忙。
const Globals = require('../utilities/Globals');
const browser = require('protractor');
const { Given } = require('cucumber');
// Chai
const globals = new Globals();
const expect = globals.expect;
Given('I am on google page with title {string}', function (title) {
return expect(browser.getTitle()).to.eventually.equal(title);
});
这是Globals.js-
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
class Globals {
constructor() {
this.expect = chai.expect;
chai.use(chaiAsPromised);
}
}
module.exports = Globals;
browser
是全局变量,可以直接使用,不需要。因此下面一行是不必要的:
const browser = require('protractor');