gpt4 book ai didi

javascript - 为什么 Protractor 在自动初始化的 Angular 站点上找不到 Angular?

转载 作者:行者123 更新时间:2023-11-29 10:40:55 26 4
gpt4 key购买 nike

我不能使用 browser.get()没有收到此错误:

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

我可以使用 browser.driver.get()但后来我遇到了需要编写特定等待和不稳定测试的问题。

我一直在阅读这方面的内容,但没有找到任何有帮助的建议。以下是一些添加的详细信息:

  • 登录页面是 Angular 应用程序的一部分。
  • ng-app<html> 中调用( Protractor 默认为 <body> ,我尝试将 rootElement 设置为 html 但这没有任何区别)
  • $timeout在应用程序中使用,但每隔 $timeout 切换一次与 $interval什么都没做
  • directConnect: true使用 chromeDriver,但我认为这不会引起问题
  • 使用 Angular 1.2.28Protractor 2.0

这里是完整的错误信息:

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

最佳答案

问题是 Protractor 需要默认的 window.name:

window.name = "NG_DEFER_BOOTSTRAP!"

但我正在测试的应用程序不使用此默认值。因此, Protractor testForAngular 每次都会失败。 Protractor 代码链接:https://github.com/angular/protractor/blob/8a3412e98614bb69978869b34b5b7243619f015d/lib/clientsidescripts.js#L550-L583

在 app.js 中注释掉自定义 window.name = 解决了这个问题,但现在我们需要弄清楚如何让 Protractor 使用不同的变量或动态注释掉这一行仅用于测试.

关于javascript - 为什么 Protractor 在自动初始化的 Angular 站点上找不到 Angular?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29498375/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com