protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Protractor.prototype.getInstance fails when Protractor is globally installed

Open davemo opened this issue 13 years ago • 7 comments

summary

I ran into this when installing protractor globally with npm install -g protractor and attempting to run with protractor example/protractorConf.js, it seems that with protractor installed globally there is a problem with protractor.getInstance() returning undefined which leads me to think this is a path issue with one of the module imports within the protractor code.

The two lines of code that trigger the below exception are:

https://github.com/juliemr/protractor/blob/master/example/onProtractor.js#L10 https://github.com/juliemr/protractor/blob/master/example/onProtractor.js#L21

steps to reproduce

  1. npm install -g protractor
  2. cd [path-where-you-have-protractor-checked-out]
  3. protractor example/protractorConf.js

protractor terminal output

$ pwd
/Users/davidmosher/code/protractor
davidmosher@localhost:~/code/protractor (master)  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  [11:30:57]
$ protractor example/protractorConf.js 
Using the selenium server at http://localhost:4444/wd/hub
FF

Failures:

  1) angularjs homepage should greet using binding
   Message:
     TypeError: Cannot call method 'get' of undefined
   Stacktrace:
     TypeError: Cannot call method 'get' of undefined
    at null.<anonymous> (/Users/davidmosher/code/protractor/example/onProtractor.js:10:10)
    at /Users/davidmosher/code/protractor/jasminewd/index.js:54:12
    at webdriver.promise.ControlFlow.runInNewFrame_ (/Users/davidmosher/code/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1431:20)
    at webdriver.promise.ControlFlow.runEventLoop_ (/Users/davidmosher/code/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1296:8)
    at wrapper [as _onTimeout] (timers.js:252:14)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
==== async task ====
    at null.<anonymous> (/Users/davidmosher/code/protractor/jasminewd/index.js:53:12)
    at null.<anonymous> (/usr/local/lib/node_modules/protractor/node_modules/minijasminenode/lib/async-callback.js:45:37)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

  2) angularjs homepage should list todos
   Message:
     TypeError: Cannot call method 'get' of undefined
   Stacktrace:
     TypeError: Cannot call method 'get' of undefined
    at null.<anonymous> (/Users/davidmosher/code/protractor/example/onProtractor.js:21:10)
    at /Users/davidmosher/code/protractor/jasminewd/index.js:54:12
    at webdriver.promise.ControlFlow.runInNewFrame_ (/Users/davidmosher/code/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1431:20)
    at webdriver.promise.ControlFlow.runEventLoop_ (/Users/davidmosher/code/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1296:8)
    at wrapper [as _onTimeout] (timers.js:252:14)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
==== async task ====
    at null.<anonymous> (/Users/davidmosher/code/protractor/jasminewd/index.js:53:12)
    at null.<anonymous> (/usr/local/lib/node_modules/protractor/node_modules/minijasminenode/lib/async-callback.js:45:37)

Finished in 0.044 seconds
2 tests, 2 assertions, 2 failures

selenium server terminal output

$ java -jar /usr/local/opt/selenium-server-standalone/selenium-server-standalone-2.33.0.jar -p 4444 -Dwebdriver.chrome.driver=/usr/local/opt/chromedriver/bin/chromedriver
Jul 20, 2013 11:34:03 AM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
Setting system property webdriver.chrome.driver to /usr/local/opt/chromedriver/bin/chromedriver
11:34:08.149 INFO - Java: Apple Inc. 20.51-b01-457
11:34:08.150 INFO - OS: Mac OS X 10.8.4 x86_64
11:34:08.161 INFO - v2.33.0, with Core v2.33.0. Built from revision 4e90c97
11:34:08.287 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
11:34:08.288 INFO - Version Jetty/5.1.x
11:34:08.289 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
11:34:08.289 INFO - Started HttpContext[/selenium-server,/selenium-server]
11:34:08.290 INFO - Started HttpContext[/,/]
11:34:08.332 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@47d62270
11:34:08.333 INFO - Started HttpContext[/wd,/wd]
11:34:08.342 INFO - Started SocketListener on 0.0.0.0:4444
11:34:08.342 INFO - Started org.openqa.jetty.jetty.Server@54cbf30e
11:34:34.683 INFO - Executing: [new session: {browserName=chrome}] at URL: /session)
11:34:34.697 INFO - Creating a new session for Capabilities [{browserName=chrome}]
Started ChromeDriver
port=47466
version=26.0.1383.0
log=/Users/davidmosher/code/protractor/chromedriver.log
objc[38541]: Object 0x79a75480 of class NSPathStore2 autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[38541]: Object 0x79c752a0 of class NSPathStore2 autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[38541]: Object 0x79c75550 of class NSConcreteData autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[38541]: Object 0x79a75510 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[38541]: Object 0x79c75210 of class NSBundle autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
11:34:36.265 INFO - Done: /session
11:34:36.281 INFO - Executing: org.openqa.selenium.remote.server.handler.GetSessionCapabilities@472462b3 at URL: /session/0307b782-d185-4af4-acd8-8dbe4b52be6a)
11:34:36.281 INFO - Done: /session/0307b782-d185-4af4-acd8-8dbe4b52be6a
11:34:36.295 INFO - Executing: [set script timeoutt: 100000] at URL: /session/0307b782-d185-4af4-acd8-8dbe4b52be6a/timeouts/async_script)
11:34:36.301 INFO - Done: /session/0307b782-d185-4af4-acd8-8dbe4b52be6a/timeouts/async_script
11:34:36.306 INFO - Executing: [delete session: 0307b782-d185-4af4-acd8-8dbe4b52be6a] at URL: /session/0307b782-d185-4af4-acd8-8dbe4b52be6a)
11:34:36.874 INFO - Done: /session/0307b782-d185-4af4-acd8-8dbe4b52be6a

conclusions

This does not occur when using the local binary ./bin/protractor example/protractorConf.js or if you have used npm link within the protractor project directory (which makes sense as it just provides a global alias for the protractor command that points to the local binary in ./bin/protractor).

I also tested this against my own project and tests and could not get specs to execute using globally installed protractor. My workaround for the time being has just been to execute specs using ./node_modules/protractor/bin/protractor config/spec-e2e.js as can be seen here

davemo avatar Jul 20 '13 17:07 davemo

As an additional discussion point, I'm not sure if this could be better resolved if the protractor library was separated from the actual spec runner? #17 seems to talk about this somewhat.

davemo avatar Jul 20 '13 17:07 davemo

Thanks for catching this - the error seems to be that example/onProtractor.js is using the local version of protractor, not global (it uses var protractor = require('../lib/protractor.js'); )

It appears that loading from global node modules is not encouraged or clean (http://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation/). I think the best solution may be to export protractor onto global, since it's unlikely to collide with anything else and test methods (describe, it, etc) are already being put onto the global. What do you think?

juliemr avatar Jul 22 '13 16:07 juliemr

The way nodes require works is such that it looks first in the local node_modules folder, and if it can't resolve a dependency there it errors out which is what I was running into when trying to refactor:

var protractor = require('../lib/protractor.js');

into

var protractor = require('protractor');

One solution would be just to have the user link the global module into the local folder using npm link protractor, but that seems clunky as well. I think the most confusing aspect to all of this is the fact that the binary is named the same thing as the library:

"bin": "bin/protractor",
"main": "lib/protractor.js",

I think putting it on the global via exports is an appropriate solution, but long term I'd like to see more distinction between the runner and the library. :)

davemo avatar Jul 23 '13 20:07 davemo

Hello I am very new in using the protractor so, please excuse me if I do some mistakes.. I have updated protractor to the latest version because mine was 0.2.0 and now I am getting this error message : " TypeError: Object # has no method 'getInstance' ". Basically it is the same as it is described in the issue above but I don't know how to fix it. I have read what @juliemr wrote but still didn't get it. For me it is pretty advanced..

Could you be so kind and guide me through the steps so that I can fix this problem?

Thanks a lot!

markuslorand avatar Jan 09 '15 15:01 markuslorand

Hi @markuslorand.

It sounds like you're using a pretty old tutorial - getInstance is long deprecated and was removed two versions ago. Check out the tutorial at http://angular.github.io/protractor/#/tutorial to get started with Protractor.

juliemr avatar Jan 09 '15 18:01 juliemr

Thank you very much for the answer! I have managed to start protractor using the tutorial. Thanks again!

markuslorand avatar Jan 15 '15 07:01 markuslorand

I have installed protractor globally, and after locally. I am using this code: var protractor = require('protractor'); var ptor, driver; ptor.switchTo().frame(driver.findElement(protractor.By.tagName("iframe"))); driver.findElement(protractor.by.css(".cke_editable")).sendKeys("123");

And get this message: Failed: protractor.getInstance is not a function

What am I do wrong? P.S. I havn't "lib/protractor.js", only "bin/protractor".

ayashpatrov avatar Jun 23 '16 10:06 ayashpatrov