收到错误:错误等待量角器与网页同步:{} [英] Getting error: Error while waiting for Protractor to sync with the page: {}

查看:132
本文介绍了收到错误:错误等待量角器与网页同步:{}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 e2e.conf.coffee 文件是:

exports.config =
  baseUrl: 'http://localhost:9001'
  specs: [
    'e2e/**/*.coffee'
  ]

  framework: 'jasmine'

我有我的节点项目运行,并侦听端口9001。

I have my node project running and listening on port 9001.

我的测试方法是:

describe 'Happy Path', ->
  it 'should show the login page', ->
    console.log browser

    expect(browser.getLocationAbsUrl()).toMatch("/view1");
  it 'should fail to login', ->
    setTimeout ->
      console.log "FAIL!"
    , 1200

和我得到的错误是:

Failures:

  1) Happy Path should show the login page
   Message:
     Error: Error while waiting for Protractor to sync with the page: {}
   Stacktrace:
     Error: Error while waiting for Protractor to sync with the page: {}
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
==== async task ====
WebDriver.executeScript()
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
==== async task ====
Asynchronous test function: it("should show the login page")
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>
    at <anonymous>==== async task ====

我在做什么错了?

What am I doing wrong??

推荐答案

(非常)短版:使用 browser.driver.get 而不是 browser.get

更长的版本:量角器基本上是围绕硒和它的JavaScript的webdriver code的包装。量角器增加了code等待角为落户与你的测试code继续之前(即完成通过$消化循环去)。但是,如果你的页面上没有它的角,然后将量角器等待永远(其实只是直到超时)等角度来解决。

The longer version: Protractor is basically a wrapper around Selenium and its Javascript WebDriver code. Protractor adds code to wait for Angular to "settle down" (i.e., finish going through its $digest loops) before proceeding with your test code. However, if your page doesn't have Angular on it, then Protractor will wait "forever" (actually just until it times out) waiting for Angular to settle.

这量角器暴露到测试的浏览器对象是量角器(即,如果你看到堆栈溢出旧的答案与 VAR ptor的一个实例= protractor.getInstance(); ptor.doSomething(),那么你可以替换 ptor 浏览器在那些老的答案)。量角器也暴露了包裹硒的webdriver API为 browser.driver 。所以,如果你叫 browser.get ,你用量角器(它会等待角落户),但是如果你调用浏览器。 driver.get ,你使用硒(不知道角)。

The browser object that Protractor exposes to your test is an instance of Protractor (i.e., if you see old answers on Stack Overflow with var ptor = protractor.getInstance(); ptor.doSomething(), then you can replace ptor with browser in those old answers). Protractor also exposes the wrapped Selenium WebDriver API as browser.driver. So if you call browser.get, you're using Protractor (and it will wait for Angular to settle down), but if you call browser.driver.get, you're using Selenium (which does not know about Angular).

在大多数情况下,您会测试角的网页,所以你需要使用 browser.get 来获得量角器的好处。但是如果你的登录页面不使用角的话,那么你应该使用 browser.driver.get 而不是 browser.get 在测试你的登录页面的测试。请注意,您还需要使用硒API而不是在试验的其余量角器API:例如,如果你有ID =用户名的HTML输入元素的地方在你的页面,你会想与 browser.driver.findElement访问它(by.id(用户名))而不是元素(by.model(用户名) )

Most of the time, you'll be testing Angular pages, so you'll want to use browser.get to get the benefits of Protractor. But if your login page doesn't use Angular at all, then you should be using browser.driver.get instead of browser.get in the tests that test your login page. Do note that you'll also need to use the Selenium API rather than the Protractor API in the rest of the test: for example, if you have an HTML input element with id="username" somewhere in your page, you'll want to access it with browser.driver.findElement(by.id('username')) instead of element(by.model('username')).

有关更多示例,请参见这个例子从量角器测试套件(或尝试<一href=\"https://github.com/angular/protractor/blob/a368de0b74db35a90d9a2d8aa48a7e57a45a2aa7/spec/withLoginConf.js\">this链接如果previous人会消失)。另请参见量角器文档其状态:

For more examples, see this example from the Protractor test suite (or try this link if the previous one ever goes away). See also the Protractor docs which state:

在无法找到网页上的角图书馆量角器将失败。如果您的测试需要用无棱角页面交互,直接与 browser.driver 访问webdriver的实例。

Protractor will fail when it cannot find the Angular library on a page. If your test needs to interact with a non-angular page, access the webdriver instance directly with browser.driver.

示例code :在上面登录测试,你会想要做这样的事情:

Example code: In your login test above, you would want to do something like:

describe 'Logging in', ->
  it 'should show the login page', ->
    browser.driver.get "http://my.site/login.html"
    // Wait for a specific element to appear before moving on
    browser.driver.wait ->
      browser.driver.isElementPresent(by.id("username"))
    , 1200
    expect(browser.driver.getCurrentUrl()).toMatch("/login.html");
  it 'should login', ->
    // We're still on the login page after running the previous test
    browser.driver.findElement(by.id("username")).sendKeys("some_username")
    browser.driver.findElement(by.id("password")).sendKeys("some_password")
    browser.driver.findElement(by.xpath('//input[@type="submit"]')).click()

(务必注意:我没有做太多的CoffeeScript,它完全有可能我做在上面的code一个CoffeeScript的语法错误,你可能想之前盲目检查其语法复制和粘贴我的上午的,但是,有信心在逻辑,因为这是复制并从我的Javascript code测试一个无棱角的登录页粘贴几乎一字不差。)

(A note of caution: I haven't done much CoffeeScript, and it's entirely possible I made a CoffeeScript syntax error in the code above. You may want to check its syntax before blindly copying and pasting it. I am, however, confident in the logic, because that's copied and pasted almost verbatim from my Javascript code that tests a non-Angular login page.)

这篇关于收到错误:错误等待量角器与网页同步:{}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆