【问题标题】:angular never provided resumeBootstrap角度从未提供 resumeBootstrap
【发布时间】:2015-09-22 14:03:55
【问题描述】:

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

  • 角度更新 -> 我们使用最新版本的 1.4
  • waitForAngular()
  • window.title
  • ...

但他们从来没有工作过。

我们的设置:

我们正在开发一个版本号为 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"

有人遇到过这种奇怪的行为吗?

提前致谢!

【问题讨论】:

  • 什么错误?你还没有真正解释问题是什么......
  • 在标题中。我认为这很清楚,因为有些人已经遇到了这个问题。但完整的错误消息是:“失败:在页面 localhost:3123/de 上找不到 Angular:从未提供 Angular resumeBootstrap”
  • @AndrewFerrier 你有什么建议吗?
  • 我还没有弄清楚这一点,但我也在使用 browserSync、ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.js 和最新的量角器……也许我们看到了一些新东西?

标签: javascript angularjs protractor angularjs-e2e e2e-testing


【解决方案1】:

简答:

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

长答案:

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

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

此功能使 Batarang 和测试运行程序等工具能够挂接到 Angular 的引导过程中,并将更多模块潜入 DI 注册表中,这些模块可以替换或增强 DI 服务,以实现检测或模拟大量依赖项。

如果 window.name 包含前缀 NG_DEFER_BOOTSTRAP!当 angular.bootstrap 被调用时,bootstrap 进程将被暂停,直到 angular.resumeBootstrap() 被调用。

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

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

【讨论】:

  • 这听起来合乎逻辑,但不幸的是它并没有解决我的问题。如上所示,我在 logPrefix 行之后插入了该行。此外,我更新到量角器 2.47.1。我是否必须设置 NG_DEFER_BOOTSTRAP!手动?或者你有什么其他想法?
  • @Benjamin Kitt:为我工作..!!出色的观察... :)
猜你喜欢
  • 2014-10-31
  • 2021-06-24
  • 1970-01-01
  • 1970-01-01
  • 2013-07-18
  • 1970-01-01
  • 2018-09-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多