angular从未提供过resumeBootstrap
angular never provided resumeBootstrap
首先,我们已经找到了一些解决问题的方法。
- angular update ->我们使用1.4的最新版本
- waitForAngular ()
- window.title
- …
但他们从来没有工作过。
给我们的设置:
我们正在开发一个版本号为1.4.x的AngularJS应用。当我们尝试测试I18n集成时,这个错误出现在E2E测试中。对于I18n,我们使用角转换。
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%的时间里得到错误。有时测试通过没有任何错误,然后我们有至少一个测试失败,由于这个错误。
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中的"run"任务:
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'
到你的browsersync配置
长答:
Browsersync (>=2.7.11)在刷新时恢复您的滚动位置,并将该信息存储在两个地方之一- window.name
(默认)或cookie。
不幸的是,Protractor使用了一个叫做Deferred Bootstrap的Angular特性,它使用了window.name
,并与BrowserSync发生冲突。来自AngularJS文档:
这个特性使得像Batarang和测试运行器这样的工具可以钩入angular的引导过程,并将更多的模块偷偷地插入到DI注册表中,这些注册表可以替换或增强DI服务,以实现插装或模拟重依赖关系的目的。
如果window.name包含前缀NG_DEFER_BOOTSTRAP!当角。当angular.resumeBootstrap()被调用时,引导进程将被暂停。
如果Browsersync在window.name
值被Angular捕获之前覆盖了它,Angular将不会延迟它的Bootstrap,并且Protractor随后将无法找到resumeBootstrap
函数,因为它不存在。
告诉Browsersync使用cookie而不是window.name可以解决冲突。