简体   繁体   中英

Why can't Protractor find Angular on an automatically initialized Angular site?

I can't use browser.get() without receiving this error:

Error: Angular could not be found on the page http://localhost:5000/#/login
debug=timing&saveLogs=true&displayAll=true : angular never provided resumeBootstrap

I can use browser.driver.get() but then I have issues with needing to write in specific waits and flaky tests.

I've been reading up on this and I haven't found any suggestions that help. Here are some added details:

  • The login page is part of the Angular app.
  • ng-app is called in <html> (Protractor defaults to <body> , and I have tried setting rootElement to html but that made no difference)
  • $timeout is used in the app, but switching every $timeout with $interval did nothing
  • directConnect: true with chromeDriver, but I assume this shouldn't cause issue
  • Using Angular 1.2.28 and Protractor 2.0

And here is the full error message:

Using ChromeDriver directly...
[launcher] Running 1 instances of WebDriver
Error: Angular could not be found on the page http://localhost:5000/#/login?debug=timing&saveLogs=true&displayAll=true : angular never provided resumeBootstrap
  at /Users/brandenbyers/Projects/admin-ui/node_modules/grunt-protractor-runner/node_modules/protractor/lib/protractor.js:479:17
  at [object Object].promise.ControlFlow.runInFrame_ (/Users/brandenbyers/Projects/admin-ui/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1877:20)
  at [object Object].promise.Callback_.goog.defineClass.notify (/Users/brandenbyers/Projects/admin-ui/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:2464:25)
  at [object Object].promise.Promise.notify_ (/Users/brandenbyers/Projects/admin-ui/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:563:12)
  at Array.forEach (native)
  at Object.goog.array.forEach (/Users/brandenbyers/Projects/admin-ui/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/array/array.js:203:43)
  at [object Object].promise.Promise.notifyAll_ (/Users/brandenbyers/Projects/admin-ui/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:552:16)
  at goog.async.run.processWorkQueue (/Users/brandenbyers/Projects/admin-ui/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/async/run.js:125:21)
  at runMicrotasksCallback (node.js:337:7)
  at process._tickCallback (node.js:355:11)

From: Task: WebDriver.manage().timeouts().setScriptTimeout(11000)
  at [object Object].webdriver.WebDriver.schedule (/Users/brandenbyers/Projects/admin-ui/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:360:15)
  at [object Object].webdriver.WebDriver.Timeouts.setScriptTimeout (/Users/brandenbyers/Projects/admin-ui/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:1367:23)
  at [object Object].Runner.createBrowser (/Users/brandenbyers/Projects/admin-ui/node_modules/grunt-protractor-runner/node_modules/protractor/lib/runner.js:181:30)
  at /Users/brandenbyers/Projects/admin-ui/node_modules/grunt-protractor-runner/node_modules/protractor/lib/runner.js:257:21
  at _fulfilled (/Users/brandenbyers/Projects/admin-ui/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/q/q.js:797:54)
  at self.promiseDispatch.done (/Users/brandenbyers/Projects/admin-ui/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/q/q.js:826:30)
  at Promise.promise.promiseDispatch (/Users/brandenbyers/Projects/admin-ui/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/q/q.js:759:13)
  at /Users/brandenbyers/Projects/admin-ui/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/q/q.js:573:44
  at flush (/Users/brandenbyers/Projects/admin-ui/node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/q/q.js:108:17)
  at process._tickCallback (node.js:355:11)
  at Function.Module.runMain (module.js:503:11)
  at startup (node.js:129:16)
  at node.js:814:3

The issue was that Protractor expects the default window.name :

window.name = "NG_DEFER_BOOTSTRAP!"

But the app that I am testing does not use this default. Therefore, Protractors testForAngular fails everytime. Link to protractor code: https://github.com/angular/protractor/blob/8a3412e98614bb69978869b34b5b7243619f015d/lib/clientsidescripts.js#L550-L583

Commenting out the custom window.name = in app.js solves this issue but now we need to figure out how to either have Protractor use a different variable or dynamically comment out this line for tests only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM