无头镀铬的量角器没有执行browser.actions()

时间:2017-06-29 15:02:53

标签: angular testing selenium-webdriver protractor selenium-chromedriver

我的protractor.conf.js(相关部分)

  capabilities: {
    'browserName': 'chrome',
    'chromeOptions': {
      'args': ['headless', 'disable-gpu']
    }
  }

如果我在正常模式下运行量角器,所有测试都会通过。以及如果我用map.click()替换这段代码。

  browser.actions()
  .mouseDown()
  .mouseMove(map, {x: 500, y: 150})
  .click()
  .mouseDown()
  .perform();

编辑:之前我没有添加错误,因为我觉得它们在我的情况下没用。但在这里他们是因为有人认为他们是相关的。

故障:

  

1)量角器演示应用场所排序应创建2个位置   离地图中心的距离不同消息:       预期0为2.堆栈:       错误:期望失败           在Object.it(/home/piliponful/projects/mocha-test/spec.js:138:38)           at /home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/jasminewd2/index.js:112:25           在新的ManagedPromise(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1067:7)           在ControlFlow.promise(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2396:12)           at schedulerExecute(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/jasminewd2/index.js:95:18)           在TaskQueue.execute_(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2970:14)           在TaskQueue.executeNext_(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2953:27)           在asyncRun(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2860:25)           at /home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:676:7           at process._tickCallback(internal / process / next_tick.js:109:7)

     

2)量角器演示应用场所排序应排序位置消息:       预期0为2.堆栈:       错误:期望失败           在Object.it(/home/piliponful/projects/mocha-test/spec.js:148:38)           at /home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/jasminewd2/index.js:112:25           在新的ManagedPromise(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1067:7)           在ControlFlow.promise(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2396:12)           at schedulerExecute(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/jasminewd2/index.js:95:18)           在TaskQueue.execute_(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2970:14)           在TaskQueue.executeNext_(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2953:27)           在asyncRun(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2860:25)           at /home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:676:7           at process._tickCallback(internal / process / next_tick.js:109:7)消息:       失败:索引越界。尝试访问index:0处的元素,但只有0个元素与locator匹配   by.binding(" place.title")Stack:       NoSuchElementError:索引超出范围。尝试访问index:0处的元素,但只有0个元素与locator匹配   by.binding(" place.title&#34)           在selenium_webdriver_1.promise.all.then(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/lib/element.ts:287:17)           在ManagedPromise.invokeCallback_(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1366:14)           在TaskQueue.execute_(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2970:14)           在TaskQueue.executeNext_(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2953:27)           在asyncRun(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2813:27)           at /home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:676:7           at process._tickCallback(internal / process / next_tick.js:109:7)错误           在ElementArrayFinder.applyAction_(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/lib/element.ts:482:23)           在ElementArrayFinder。(匿名函数).args [as getText](/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/lib/element.ts:96:21)           在ElementFinder。(匿名函数).args [as getText](/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/lib/element.ts:873:14)           at placeListText.then.places(/home/piliponful/projects/mocha-test/spec.js:150:38)           在ManagedPromise.invokeCallback_(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1366:14)           在TaskQueue.execute_(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2970:14)           在TaskQueue.executeNext_(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2953:27)           在asyncRun(/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2813:27)           at /home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:676:7           at process._tickCallback(internal / process / next_tick.js:109:7)       来自:任务:在控制流程中运行它("应该排序位置")           在对象。 (/home/piliponful/.nvm/versions/node/v7.10.0/lib/node_modules/protractor/node_modules/jasminewd2/index.js:94:19)           在runCallback(timers.js:672:20)           在tryOnImmediate(timers.js:645:5)           at processImmediate [as _immediateCallback](timers.js:617:5)       从异步测试:       错误           在Suite.describe(/home/piliponful/projects/mocha-test/spec.js:140:5)           在Suite.describe(/home/piliponful/projects/mocha-test/spec.js:87:3)           在对象。 (/home/piliponful/projects/mocha-test/spec.js:1:1)           在Module._compile(module.js:571:32)           at Object.Module._extensions..js(module.js:580:10)           在Module.load(module.js:488:32)           在tryModuleLoad(module.js:447:12)           在Function.Module._load(module.js:439:3)           在Module.require(module.js:498:17)

     

13个规格,3个失败

3 个答案:

答案 0 :(得分:0)

我没有找到解决方案让protractor browser.actions()在chrome中使用无头模式。但是我使用了Xvfb docker图像(webnicer / protractor-headless),它都按预期工作。

答案 1 :(得分:0)

我可以看到您的选项语法与Protractor specifications不同。此外,无头需要您预先指定窗口大小。请试一试,看看是否有帮助。

capabilities: {
    'browserName': 'chrome',
    'chromeOptions': {
      'args': ['--headless', '--disable-gpu', '--window-size=800,600']
    }
  }

答案 2 :(得分:0)

是的,您无法在无头Chrome中使用mouseMove(),因为并非所有浏览器操作都能按预期工作。例如,browser.actions().sendKeys(Key.DELETE).perform()

而不是mouseMove(),只需使用:

browser.executeScript("arguments[0].scrollIntoView();", map)

map.click()