Protractor Angular 2 Failed: unknown error: angular is not defined

15,162

I found the answer on the angular.io site under developer docs.

Upgrading from 1.x

enter image description here

Right now angular selectors by.model and by.binding are not supported. Its not clear if these are features that are possible or that they are working on for angular 2.

Share:
15,162

Related videos on Youtube

Rob
Author by

Rob

Updated on June 22, 2022

Comments

  • Rob
    Rob almost 2 years

    I'm getting the following error:

    • Failed: unknown error: angular is not defined

    This only happens when using angular specific selectors like "by.model". But selectors such as "by.css" work correctly . This is an Angular 2 app...

    Test

    it('should set focus', () => {
        //This works
        //var input = element(by.css('myclass'));
        //This fails
        var input = element(by.model('config.value'));
        input.clear();
        input.sendKeys('test');
        input.sendKeys(Key.TAB);
        input.click();
        var highlightedText = browser.executeScript(function getSelectionText()       
        {         
             return window.getSelection().toString(); 
        });
        expect(highlightedText).toEqual('test');
     });
    
    
    exports.config = {
      baseUrl: 'http://localhost:5555',
    
      specs: [
        'dist/dev/**/*.e2e.js'
      ],
      exclude: [],
    
      framework: 'jasmine2',
    
      allScriptsTimeout: 110000,
    
      jasmineNodeOpts: {
        showTiming: true,
        showColors: true,
        isVerbose: false,
        includeStackTrace: false,
        defaultTimeoutInterval: 400000
      },
      directConnect: true,
    
      capabilities: {
        'browserName': 'chrome'
      },
    
      onPrepare: function() {
        var SpecReporter = require('jasmine-spec-reporter');
        jasmine.getEnv().addReporter(new SpecReporter({displayStacktrace: true}));
    
        browser.ignoreSynchronization = false;
      },
    
      useAllAngular2AppRoots: true
    };
    

    chrome=49.0.2623.87 chromedriver=2.9.248315 platform=Windows NT 6.1 SP1 x86_64 node=5.9.1

    • marpe
      marpe about 8 years
      Could you add your protractor.conf?
    • Rob
      Rob about 8 years
      I updated the post with the config
    • alecxe
      alecxe about 8 years
      What if you would add browser.waitForAngular() to beforeEach after the browser.get()?
    • Rob
      Rob about 8 years
      browser.waitForAngular(); did not fix the issue.
  • OZ_
    OZ_ almost 7 years
    ... few hours of my life were wasted because somebody was too lazy to not it in docs... angular.io/docs/ts/latest/guide/testing.html