gpt4 book ai didi

javascript - angular 从不提供 resumeBootstrap

转载 作者:行者123 更新时间:2023-11-29 19:21:51 25 4
gpt4 key购买 nike

首先:我们已经找到了解决问题的方法:

  • angular update -> 我们使用最新的1.4版本
  • waitForAngular()
  • 窗口标题
  • ...

但他们从来没有工作过。

到我们的设置:

我们正在开发版本号为 1.4.x 的 AngularJS 应用程序。当我们尝试测试 I18n 集成时,错误出现在 E2E 测试中。对于 I18n,我们使用 angular-translate。

exports.config =
seleniumServerJar: "./node_modules/protractor/selenium/selenium-server-standalone-2.45.0.jar"
chromeDriver: "./node_modules/protractor/selenium/chromedriver"
capabilities:
browserName: "chrome"
name: "APP_NAME Selenium"
troubleshoot: true
framework: "jasmine2"
rootElement: "body"
onPrepare: ->
global.By = global.by
browser.manage().window().maximize()
jasmineNodeOpts:
showColors: true
defaultTimeoutInterval: 30000
isVerbose: true

奇怪的是我们只在大约 50% 的时间内得到错误。有时测试没有任何错误地通过,然后我们有时至少有 1 个测试由于这个错误而失败。

describe "The language", ->
it "should be german with german URL", ->
browser.get "/de/"
expect( element( By.id("slogan") ).getText() ).toEqual "SLOGAN HERE!"

it "should be preserved when a link is clicked", ->
browser.get "/de/"
element( By.css(".get-started a") ).click()
expect( browser.getCurrentUrl() ).toEqual "http://localhost:3123/de/import"

element( By.id("option-empty-table") ).click()
expect( browser.getCurrentUrl() ).toEqual "http://localhost:3123/de/editor"

it "should have the correct translations when a link is clicked", ->
browser.get "/de/"

element( By.css(".get-started a") ).click()
expect( element( By.css("#option-empty-table a h3") ).getText() ).toEqual "SOME STRING"

我们使用 Gulp 开始测试。这是 gulp 任务:

gulp.task "e2e",
"Runs all e2e tests.",
[
"run"
],
->
gulp.src E2E_FILES
.pipe protractor
configFile: "./protractor.config.coffee"
args: [
"--baseUrl"
BASEURL
]

BASEURL 变量是“http://localhost:3123

最后但同样重要的是来自 gulp 的“运行”任务:

gulp.task "run", "Serves the App.",
[
"build"
],
->
browserSync.init
server:
baseDir: BUILD.dirs.out
index: "/statics/master.html"
middleware: [modRewrite(['!\\.\\w+$ /statics/master.html [L]'])]
open: false
port: 3123
ui:
port: 3124
weinre: 3125
logLevel: "info"
notify: false
logPrefix: "SOME_PREFIX"

有没有人有过这样奇怪的行为?

提前致谢!

最佳答案

简答:

scrollRestoreTechnique: 'cookie' 添加到您的浏览器同步配置中。

长答案:

浏览器同步 (>=2.7.11) restores your scroll position当它刷新并将该信息存储在两个位置之一时 - window.name(默认)或 cookie。

不幸的是,Protractor 使用了一个名为 Deferred Bootstrap 的 Angular 特性使用 window.name 并与 BrowserSync 冲突。来自 AngularJS 文档:

This feature enables tools like Batarang and test runners to hook into angular's bootstrap process and sneak in more modules into the DI registry which can replace or augment DI services for the purpose of instrumentation or mocking out heavy dependencies.

If window.name contains prefix NG_DEFER_BOOTSTRAP! when angular.bootstrap is called, the bootstrap process will be paused until angular.resumeBootstrap() is called.

如果 Browsersync 在它被 Angular 捕获之前覆盖了那个 window.name 值,Angular 将不会延迟它的 Bootstrap 并且 Protractor 随后将无法找到 resumeBootstrap 函数因为它不会存在。

告诉 Browsersync 使用 cookie 而不是 window.name 解决了冲突。

关于javascript - angular 从不提供 resumeBootstrap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32719042/

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