0

I'm trying to reference one of my services while executing e2e tests. I need this to have possibility to enable/disable my feature toggles mocking mechanism, and could perform tests for both states on/off of some feature.

I've tried with:

const data = await browser.executeScript(function() {
  //@ts-ignore
  return window.ng.getInjector(window.getAllAngularRootElements()[0]).get('MyService')
})

but the problem is that window.ng is undefined, I got error message:

Failed: javascript error: Cannot read property 'getInjector' of undefined
(Session info: chrome=80.0.3987.122)
(Driver info: chromedriver=80.0.3987.16 (320f6526c1632ad4f205ebce69b99a062ed78647-refs/branch-heads/3987@{#185}),platform=Linux 4.19.121-linuxkit x86_64)

I receive the same error when using browser.executeAsyncScript()

Tests are running in docker

Tomasz
  • 171
  • 9
  • sounds like you just don't have `window.ng` object in the page where you're trying to execute it – Sergey Pleshakov Apr 01 '21 at 13:56
  • @sergey yes I don't have, but as far as i know i should have. Since Angular 9 window.ng is object for console debugging and testing. When I created a brand new project and execute this code, everything is fine, so I believe the problem lies somewhere in configuration of current project – Tomasz Apr 01 '21 at 19:08

1 Answers1

0

The issue was inside my own configuration.

Tests were executed against different environment than I was expecting. This was environment in production mode and this is the reason that ng object was not available.

Tomasz
  • 171
  • 9