12

There other question on SO with same problem, but the solutions didnt worked for me. Here my spec.js

describe('Protractor Demo App', function() {
  it('should have a title', function() {
    browser.driver.get('http://rent-front-static.s3-website-us-east-1.amazonaws.com/');

    expect(browser.getTitle()).toEqual('How It Works');
  });
});

And here my conf.js

exports.config = {
  framework: 'jasmine',
  rootElement: 'body',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['spec.js']
}

So when i try to run my test im getting the error

  Message:
    Failed: Error while waiting for Protractor to sync with the page: "[ng:test] no injector found for element argument to getTestability\nhttp://errors.angularjs.org/1.5.0/ng/test"
  Stack:
    Error: Failed: Error while waiting for Protractor to sync with the page: "[ng:test] no injector found for element argument to getTestability\nhttp://errors.angularjs.org/1.5.0/ng/test"
        at C:\Users\ShapeR\PycharmProjects\ratest\node_modules\jasminewd2\index.js:101:16
        at Promise.invokeCallback_ (C:\Users\ShapeR\PycharmProjects\ratest\node_modules\selenium-webdriver\lib\promise.js:1329:14)
        at TaskQueue.execute_ (C:\Users\ShapeR\PycharmProjects\ratest\node_modules\selenium-webdriver\lib\promise.js:2790:14)
        at TaskQueue.executeNext_ (C:\Users\ShapeR\PycharmProjects\ratest\node_modules\selenium-webdriver\lib\promise.js:2773:21)

1 spec, 1 failure

I have a manual bootstrapping for body element and set the rootElement to body in config, but it didnt help. I even tried to remove manual boostraping and just add ng-app='rentapplicationApp' to body element, but it changes nothing, still same error.

So what is wrong?

Aldarund
  • 17,312
  • 5
  • 73
  • 104
  • 1
    I think a "manually bootstrapped" app is still challenging to get synced with protractor. Would you be okay with just turning the sync off with `browser.ignoreSynchronization = true`? – alecxe May 26 '16 at 23:21
  • Also, try replacing `$timeout` with `$interval` wherever you use it. Then, bootstrap the app regularly with `ng-app` defined on `body`. Still the same issue? – alecxe May 26 '16 at 23:22
  • @alecxe Yep, as i told replacing manual bootstrapping with ng-app changed nothing. Replacing $timeout with $interval also change nothing. ignoreSynchronization = true make this simple test work, but i dont really think its a solution, since from what im read in http://www.protractortest.org/#/timeouts it used for pages without angular, so i guess other protractor features wont work either with it.. – Aldarund May 26 '16 at 23:43
  • Gotcha. Could you please deploy the version having `ng-app` to aws so that I can play around with it? Thanks. – alecxe May 26 '16 at 23:44
  • @alecxe you can just save the page and change it in html, its just a static assets, html and 2 js files.( although it need to be served using any server e.g. accessed with localhost not as html file).If u still want deployed version - let me know and i deploy it to other url. – Aldarund May 26 '16 at 23:53
  • @Aldarund This may be Help you: (http://stackoverflow.com/questions/28040078/no-injector-found-for-element-argument-to-gettestability) (https://github.com/angular/protractor/issues/2558) – Nick Jun 03 '16 at 21:55
  • @Nick linked issue about non angular pages, while my whole app is a SPA angular. I even created issue myself -> https://github.com/angular/protractor/issues/3250 but it just got closed, without any really looking into it.... The SO link didnt help at all like i said in issue, i have rootElement and tried other thing from it before – Aldarund Jun 03 '16 at 22:03
  • @Aldarund sorry for not getting back earlier. Could you please deploy the version with `ng-app` too? I'll take a look asap. – alecxe Jun 05 '16 at 22:21
  • @alecxe here it is : https://dl.dropboxusercontent.com/u/597502/vxcv/index.html ( although it have errors due to cors it shouldnt matter, its still working angular app) – Aldarund Jun 05 '16 at 23:42

3 Answers3

1

The core value of Protractor is that it manages the angular loading for you, including sync, so you are very right in not wanting to use: browser.ignoreSynchronization = true.

The error message you are getting is that protractor is unable to locate angular in order to sync. This is because of a combination of two issues:

  • The page isn't ready, angular isn't loaded
  • It is unable to locate the ng-app, even once the page is loaded

Firstly, from Protractor setup page.

If your page does manual bootstrap Protractor will not be able to load your page using browser.get. Instead, use the base webdriver instance - browser.driver.get. This means that Protractor does not know when your page is fully loaded, and you may need to add a wait statement to make sure your tests avoid race conditions.

Solution 1

Add a wait statement.

Solution 2

If you don't have a good reason for manually bootstrapping, or don't want to wait:

  • Stop manually bootstrapping the app
  • Use browser.get over browser.driver.get
Luke Exton
  • 3,506
  • 2
  • 19
  • 33
  • Thanks for answer but. Solution 2 not working. i tried both driver.get and browser.get - changes nothing. And i tried it without manual bootstrapping, same error. Solution 1 didnt work too. I even tried to add browser.sleep for 10 second for which app is loaded for sure. Still same error. See this snippet. http://pastebin.com/cK3HfB5w – Aldarund Jun 05 '16 at 15:26
1

[ng:test] no injector found for element argument to getTestability

I suspect there is something wrong with the application itself, the way it is bootstrapped, since Protractor actually finds the root element (you can explicitly set the rootElement: "body.root" inside your config as well), but fails to setup the injector for the root element.

I'd try to figure out what is happening it step by step - first, try running the protractor test against a non-built application started directly from the source to ensure that this is not the webpack's or other part's of the build fault.

Then, I'd try upgrading to the latest 1.x Angular and Protractor (3.3.0 is the most recent version).


The most simple workaround at the moment would be to turn the sync between Protractor and Angular off, by using browser.ignoreSynchronization = true:

describe("Strange Protractor/Angular problem", function () {
    beforeEach(function () {
        browser.ignoreSynchronization = true;
        browser.get("https://dl.dropboxusercontent.com/u/597502/vxcv/index.html");

        var elm = $(".navbar-brand");
        browser.wait(EC.presenceOf(elm), 5000);
    });

    it("should have an expected title", function () {
        expect($(".navbar-brand").getText()).toEqual('RENT APPLICATION');
    });
});

Of course, there are downsides to this approach - you would have to use browser.wait calls here and there to tackle the timing issue. The test flow would not be as natural and simple as it would be when sync is on.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • I cant run against non built since my app requires webpack, otherwise its not in working condition, Also i use latest angular 1.5.5 and protractor 3.3.0. Didnt help. But my app works fine, it dont have js errors, it works. Only protractor cant test it. Isnt it a bug in proctractor? As for disable sync - than the whole point of using protractor is lost for me. – Aldarund Jun 06 '16 at 17:09
  • @Aldarund yeah, I understand that disabling sync is not the most desired workaround here. I've tried multiple things up until now but have not managed to solve it with sync on..it is kind of a weird situation I've never encountered before while testing other apps with Protractor. Btw, I see js errors on the console [here](https://dl.dropboxusercontent.com/u/597502/vxcv/index.html/). – alecxe Jun 06 '16 at 17:58
  • @alexce ye there errors because of cors, they are not happening in normal situation but still same error. I opened a ticket in protractor repo but it was just closed without any looking into it, because its "support request for stackoverflow"... – Aldarund Jun 06 '16 at 18:53
  • @Aldarund well, they are kind of right sending it to SO. We need to at least prove them this is not this specific app's problem and something wrong inside the way protractor syncs with an angular app to be able to get the protractor developers attention. I would suggest starting a bounty to attract attention and get more help - but, since you've already done that...we can try once more. Thanks. I'll definitely take a closer look - this problem is still on my todo list. – alecxe Jun 07 '16 at 18:10
0

The problem was in bootstrapping my app. For some reason it doesnt work with ng-app tag. The only working solution was to manual bootstrap it

angular.bootstrap(document, ["rentapplicationApp"]);

And first argument should be dom node, not a string, like it was in my case, although with string the app will work, but getTestability will fail.

Aldarund
  • 17,312
  • 5
  • 73
  • 104