代码之家  ›  专栏  ›  技术社区  ›  snikt

expect-expect(browser.getTitle())错误-browser.getTitle不是函数

  •  -1
  • snikt  · 技术社区  · 8 年前

    “TypeError:browser.getTitle不是函数。” 我到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);
    });
    

    const chai = require('chai');
    const chaiAsPromised = require('chai-as-promised');
    
    class Globals {
        constructor() {
            this.expect = chai.expect;
            chai.use(chaiAsPromised);
        }
    }
    
    module.exports = Globals;
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   yong    8 年前

    browser 是全局变量,您可以直接使用它而不需要它。因此,以下行是不必要的:

    const browser = require('protractor');