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

Bash Script to Comment/uncomment lines in file

I have a standard text configuration file in Linux (Fedora 20). Most lines should apply all the time, but a few lines need to be "turned on" (uncommented) and "turned off" depending on the machine the file is on. So the file looks like this:

 ; configuration file
 parameter1 = a
 parameter2 = b
 optparameter1 = z     ; only applies to %%machine-1%%
 ; optparameter1 = x   ; only applies to %%machine-2%%
 parameter3 = c
 ; optparameter2 = x   ; only applies to %%machine-2%%
 optparameter2 = f     ; only applies to %%machine-1%%  

What I would like to do is run a script that would change the file (or copy the file) altering commenting of the lines based on command line parameters. e.g.

 ./scriptname -u machine-2 -c machine-1 configurationFileName.conf

This would cause all lines with %%machine-2%% in the end comment to be uncommented (of course, leaving the end comments in tact), and all lines with %%machine-1%% in the end comment to be commented.

Any suggestions on how to do this? Thank you.

4

1 回答 1

16

您不再需要调用protractor.getInstance(),使用全局可用的browser对象:

this.title = browser.getTitle();

而且,是的,这是一个重大变化1.5.0,请参阅:

于 2014-12-29T14:37:15.693 回答