Protractor Tests Fail on Build Machine with "Angular Already Bootstrapped" Error

703 views
Skip to first unread message

Paul McCaughtry

unread,
Sep 5, 2015, 12:00:51 AM9/5/15
to AngularJS
Hi all,

I'm perplexed about the following error I receive on my test machine but not local machine running protractor tests. This error occurs at least one time on different tests with no repeatable patterns. The application is bootstrapped in index.html via ng-app directive and does not dynamically bootstrap any other part of the app, does not use angular.bootstrap.

Included below is the error, version information for both local machine and test machine and the protractor.conf.js file.

Has anyone encountered and solved this issue? Any assistance appreciated.

Thank you


/////////////////////////////////////////////////////////////////////////////////////////

Error

UnknownError: unknown error: [ng:btstrpd] App Already Bootstrapped with this Element '<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" ng-app="app" class="ng-scope">' http://errors.angularjs.org/1.3.13/ng/btstrpd?p0=%26lt%3Bhtml%20lang%3D%22en%22%20xml%3Alang%3D%22en%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%20ng-app%3D%app%22%20class%3D%22ng-scope%22%26gt%3B (Session info: chrome=42.0.2311.90) (Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Linux 3.2.0-64-generic x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 10 milliseconds Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50' System info: host: 'my-app-domain', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-64-generic', java.version: '1.7.0_55' Session ID: 1d28ecb032067a5ae2b206a13561be12 Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/tmp/.com.google.Chrome.3h2q0R}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=42.0.2311.90, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, takesScreenshot=true}]
View Stack Trace Info


/////////////////////////////////////////////////////////////////////////////////////////

Versions

Local machine
OSX Version 10.10.5 (14F27)
Node Version: v0.12.4
NPM Version: 2.10.1
V8 Version: 3.28.71.19
Protractor Version: 2.1.0
Selenium Jar: selenium-server-standalone-2.45.0.jar

Test machine 
Distributor ID: Ubuntu
Description: Ubuntu 12.04.4 LTS
Release: 12.04
Codename: precise
Node Version: v0.12.7
NPM Version: 2.11.3
V8 Version: 3.28.71.19
Protractor Version: 2.0.0
Selenium Jar: selenium-server-standalone-2.45.0.jar

/////////////////////////////////////////////////////////////////////////////////////////

protractor.conf.js

var HtmlReporter = require('protractor-html-screenshot-reporter');

exports.config = {
  // The address of a running selenium server.
  //seleniumAddress: 'http://localhost:4444/wd/hub',
  // Recommended: always use seleniumPort
  seleniumPort: 4444,

  // Timeout default for all tests
  allScriptsTimeout: 150000,

  // Capabilities to be passed to the webdriver instance.
  capabilities: {
    'browserName': 'chrome'
  },

  // Spec patterns are relative to the location of this file
  specs: ['../e2e/*_spec.js']
  //
  // ----- Options to be passed to minijasminenode -----
  jasmineNodeOpts: {
    // onComplete will be called just before the driver quits.
    onComplete: null,
    // If true, display spec names.
    isVerbose: true,
    // If true, print colors to the terminal.
    showColors: true,
    // If true, include stack traces in failures.
    includeStackTrace: true,
    // Default time to wait in ms before a test fails.
    defaultTimeoutInterval: 60000
  },
  // Define global variables (sort of like env. variables for the tests)
  params: {
    host: "http://localhost:8084"
  },

  onPrepare: function() {// Add a screenshot reporter and store screenshots:
    jasmine.getEnv().addReporter(new HtmlReporter({
      baseDirectory: 'test_report',
      takeScreenShotsForSkippedSpecs: false,
      takeScreenShotsOnlyForFailedSpecs: false
    }));

    browser.driver.manage().window().maximize();
  }
};

Brian Guetzlaff

unread,
Sep 29, 2015, 5:24:49 PM9/29/15
to AngularJS
Hey Paul,

In our app we were using a lot of browser.get() calls to change routes within our application.  However, within Protractor we were doing this repeatedly for each test.  I suspect that since we never left the app between tests, Angular was never un-bootstrapped (and we used ng-app), and something within Protractor would randomly get confused periodically.

Here's the link that pointed me to that browser.get() call in the first place: http://goo.gl/6yj96z

After playing around with this a bit, we ended up using browser.setLocation() to switch between routes, and before each test do a "reset" of the Angular bootstrap via a global beforeEach:

beforeEach(function resetAngular() {
    // Get a fresh Angular "session" so we can avoid bootstrapping errors
    browser.driver.get("about:blank");
    browser.get(pathToAppLandingPage);  // only check Angular bootstrap once per test
});

Once we did that, the bootstrapping errors seemed to vanish.  I'm not sure if this is actually fixed or just made the error far less likely, but either way thing seem better.

---Brian
Reply all
Reply to author
Forward
0 new messages