Aaron
Aaron

Reputation: 2485

Object #<Object> has no method 'getInstance' when trying to run Protractor tests

When I am attempting to run my Protractor tests from the command line all of my tests fail because whenever I try to access the protractor object it does not have the methods I need. The exact error is:

TypeError: Object # has no method 'getInstance'

So this seems to have been a reported and fixed issue, yet I cannot seem to resolve my particular situation. It also seems to be semi-related to this question, but because it arose for me after updating my node_modules I feel like my underlying issue is different. Up until updating my Protractor everything worked just fine.

I installed it globally and used npm link protractor to link my local instance to my global instance (located at /usr/local/lib/node_modules/protractor), but I still for the life of me cannot figure out what is wrong.

The exact code where I'm calling protractor is a page object file that looks like:

module.exports = function() {

    var ptor = protractor.getInstance();

    this.get = function() {
        browser.get('http://localhost');
        this.title = ptor.getTitle();
    };

};

The code instantiating the page object is as follows:

var Login = require('./pageObjects/Login.po.js');
...
var LoginPage = new Login();

Upvotes: 6

Views: 4028

Answers (1)

alecxe
alecxe

Reputation: 474081

You don't need to call protractor.getInstance() anymore, use globally-available browser object:

this.title = browser.getTitle();

And, yes, this was a breaking change in 1.5.0, see:

Upvotes: 16

Related Questions