-1

I have the following code which uses Chai, but when executed fails and console returns "TypeError: browser.getTitle is not a function." My path to Globals.js is correct because if I do something like this, it works - expect('Test abc').toContain('abc'). Please help.

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);
});

This is 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;
snikt
  • 581
  • 4
  • 11
  • 27

1 Answers1

0

browser is global variable, you can use it directly without to require it. Thus following line is unnecessary:

const browser = require('protractor');
yong
  • 13,357
  • 1
  • 16
  • 27