6

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();
Community
  • 1
  • 1
Aaron
  • 2,367
  • 3
  • 25
  • 33

1 Answers1

16

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:

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Wow, very embarrassed that I missed that in the notes. Everything is running 100% again. Will mark as correct when I can. Cheers! – Aaron Dec 29 '14 at 14:41