4

In an AngularJS application is it possible to detect if the environment is Protractor?

I would like to disable certain functionality such as Geolocation when running my tests. It's not something I want to test at the moment and I am pretty sure it is what is causing my tests to fail to run.

In my App I use window.jasmine to disable certain polling actions when running Jasmine tests so something similar would be good.

i.e.

if(!window.protractor) {
  geoLocationRun()
}

This doesn't work and there doesn't appear to be anything I can use on Window.

Note: I know I can mock out the geolocation which I can do if this isn't possible. Perhaps this is the best approach in any case however it would be good to know if there is a suitable solution. How do I enable geolocation support in chromedriver for Selenium?

Community
  • 1
  • 1
Asta
  • 1,569
  • 13
  • 23

1 Answers1

1

I would recommend you to move your geo location code into an angular module. Then you can mock the module in your protractor tests using browser.addMockModule

http://angular.github.io/protractor/#/api?view=Protractor.prototype.addMockModule

Andres D
  • 8,910
  • 2
  • 26
  • 31
  • 1
    I didn't know about that method so that looks like a better way than the other approach to enable geolocation. I have it in a module already so that should work nicely. I'd still like to know if you can detect the Protractor environment though – Asta Apr 24 '15 at 08:09