为什么量角器不会认出Angular?

时间:2014-02-05 01:01:18

标签: protractor

量角器给我错误告诉我它无法在页面上找到角度。还有什么我应该考虑麻烦拍这个?

protractorConf.js

exports.config = {
  seleniumAddress: 'http://0.0.0.0:4444/wd/hub',
  capabilities: { 'browserName': 'chrome' },
  specs: ['spec/javascripts/integration/main_spec.js'],
  baseUrl: 'http://127.0.0.1:3000/',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000
  }
};

失败消息,浏览器实际上正在打开,这是我昨天在哪里的改进,对此有何看法?

jd@mbp ~/Dropbox/apps/lookingtolunch (master *)]$ protractor protractorConf.js
Using the selenium server at http://0.0.0.0:4444/wd/hub
F

Failures:

  1) E2E: main page should find title element
   Message:
     Error: Angular could not be found on the page http://127.0.0.1:3000/ : angular never provided resumeBootstrap
   Stacktrace:
     Error: Angular could not be found on the page http://127.0.0.1:3000/ : angular never provided resumeBootstrap
    at assertAngularOnPage (/usr/local/lib/node_modules/protractor/lib/protractor.js:668:13)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)
==== async task ====
WebDriver.executeScript()
    at Protractor.get (/usr/local/lib/node_modules/protractor/lib/protractor.js:675:15)
    at null.<anonymous> (/Users/jd/Dropbox/apps/lookingtolunch/spec/javascripts/integration/main_spec.js:16:13)
    at /usr/local/lib/node_modules/protractor/jasminewd/index.js:54:12
    at wrapper [as _onTimeout] (timers.js:252:14)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
==== async task ====
    at null.<anonymous> (/usr/local/lib/node_modules/protractor/jasminewd/index.js:53:12)
    at null.<anonymous> (/usr/local/lib/node_modules/protractor/node_modules/minijasminenode/lib/async-callback.js:45:37)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

2 个答案:

答案 0 :(得分:3)

我也遇到了同样的问题,并且由于OP已经沉默,也许我可以使用此答案空间来提供问题的第二个实例,并根据其他用户反馈对其进行编辑以使其工作。

编辑我找到了解决方案。请参阅答案底部的编辑

我正在运行运行webdriver-manager start的Windows 8.1以启动Selenium独立服务器,并运行python -m SimpleHTTPServer来托管该网站。

示例-specs.js

describe("something peaceful", function() {
    it("shouldn't be this hard", function() {
        browser.get("http://127.0.0.1:8000"); // times out here
        expect(true).toEqual(true);
    });
});

<强> conf.js

// protractor configuration for end-to-end (e2e) tests
exports.config = {
    seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
    capabilities: { 'browserName': 'chrome' },
    specs: [ 'example-specs.js' ],
}

<强>的index.html

<!doctype html>
<html>
<body ng-app >
    I can add: {{1+5}}.

    <!-- script src="https://ajax.googleapis.com/ajax/libs/angularjs/**1.0.4**/angular.min.js"></script -->

    <!-- Updated to 1.2.9 and the problem went away -->
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>

</body>
</html>

编辑1 我是从WebStorm运行的,但我也尝试使用python -m SimpleHTTPServer(并相应地更改地址)来提供网站服务,但我的结果是一样的。

编辑2 如果我删除baseUrl并直接致电browser.get(...),我可以http://www.angularjs.org工作,但不能使用我的本地网站,也不能jsfiddle angular app I found。也许它只是不适用于自动引导

编辑3 显着减少了重现的代码(删除了控制器)。将脚本移动到正文末尾as recommended

编辑4 我正在使用Angular的旧版本(1.0.4)appeared in this book。升级到1.2.9(最新)修复了问题。

答案 1 :(得分:-1)

如果您需要导航到不使用Angular的页面,则在此browser.get()行之前添加以下代码行:

browser.waitForAngularEnabled(false);

参考:https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular-on-page-load