【问题标题】:npm E2E test is getting timed out when running in Docker but getting passed when running on local machinenpm E2E 测试在 Docker 中运行时超时,但在本地机器上运行时通过
【发布时间】:2018-03-21 10:49:23
【问题描述】:

图像/框:gfy94/wercker-chromium-node:v0.0.2 Docker-Selenium 镜像版本:node-chrome Docker 版本:17.12.1-ce, 操作系统:Ubuntu 16.04

您好,我正在尝试使用节点版本 6.9.3 在 docker box (Ubuntu 16.04) 中运行 npm E2E 测试。它在本地无头运行并且所有测试用例都通过了,但是当我在我们的本地 docker 上执行此操作时,启动需要很长时间,并且在通过几个测试用例后由于超时而停止。我正在使用无头 chrome 在 docker 上运行测试。实际上,最后我必须在 wercker 上运行测试。所以,目前我只是在本地 docker 上运行它。

在 nightwatch.js 中,这些是 chrome 属性:

  >   desiredCapabilities: {
  >     javascriptEnabled: true,
  >     acceptSslCerts: true,
  >     browserName: 'chrome',
  >     chromeOptions: {
  >     args: ['headless', 'no-sandbox', 'disable-gpu','window-size=1100,800'],
  >     },
  >    },

## 预期行为 -

yashwant@yashwant-Inspiron-3537:~/website-node-react$ npm run test:e2e:desktop -- --tag authorised-bulk

  > website-node-react@1.0.0 test:e2e:desktop /home/yashwant/website-node-react
  > APP_DEVICE='desktop' nightwatch --config nightwatch.js "--tag" "authorised-bulk"

Starting selenium server... started - PID:  8410

[Authorised Bulk] Test Suite
================================

Running:  Authorised checkout, bulk products
 ✔ Element <//div[@class="modal-base  modal-base--after-open modal-base--  sticky-top"]//p[text()="Bangalore"]> was visible after 53 milliseconds.
 ✔ Element <//div[@tabindex="-100"]//a[text()="Bangalore"]> was visible after 46 milliseconds.
 ✔ Element <//a[contains(text(),"Login")]> was visible after 336 milliseconds.
 ✔ Element <//div[@role="tabpanel"]//input[@name="email"]> was visible  after 64 milliseconds.
 ✔ Element <//div[@role="tabpanel"]//input[@name="password"]> was visible after 47 milliseconds.
 ✔ Element <//button[contains(text(),"Sign In")]> was visible after 67 milliseconds.
 ✔ Element <(//a[starts-with(@href, "/bangalore/product")])[1]> was visible after 2781 milliseconds.
 Warn: WaitForElement found 4 elements for selector "//span[text()="Available in Bulk"]". Only the first one will be checked.
 ✔ Element <//span[text()="Available in Bulk"]> was visible after 2358 milliseconds.
 ✔ Element <//a[contains(text(),"Quantity:")]> was visible after 1114 milliseconds.
✔ Passed [equal]: object == object
✔ Passed [equal]: 0 == 0
✔ Element <//button[@value = 2]> was visible after 247 milliseconds.
✔ Element <//button[text()="Buy Now"]> was visible after 370 milliseconds.
✔ Element <//div/p[contains(text(), "Order Summary")]> was visible after 1741 milliseconds.
✔ Element <//a[contains(text(),"Quantity:")]> was visible after 61 milliseconds.
✔ Passed [equal]: object == object
✔ Passed [equal]: 0 == 0
✔ Element <//button[@value = 2]> was visible after 37 milliseconds.
✔ Element <//button[text()="PROCEED TO NEXT STEP"]> was visible after 36 milliseconds.
  Warn: WaitForElement found 83 elements for selector "//button[contains(text(),"DELIVER HERE")]". Only the first one will be checked.
✔ Element <//button[contains(text(),"DELIVER HERE")]> was visible after 1216 milliseconds.
✔ Element <//li[text()="Cash/Card on Delivery"]> was visible after 1664 milliseconds.

OK. 21 assertions passed. (31.36s)

## 实际行为 -

root@7ccf6a97ea58:/website-node-react# npm run test:e2e:desktop -- --tag authorised-bulk

 > website-node-react@1.0.0 test:e2e:desktop /website-node-react
 > APP_DEVICE='desktop' nightwatch --config nightwatch.js "--tag" "authorised-bulk"

Starting selenium server... started - PID:  945

[Authorised Bulk] Test Suite
================================

Running:  Authorised checkout, bulk products
 ✔ Element <//div[@class="modal-base  modal-base--after-open modal-base--sticky-top"]//p[text()="Bangalore"]> was visible after 44 milliseconds.
 ✔ Element <//div[@tabindex="-100"]//a[text()="Bangalore"]> was visible after 47 milliseconds.
 ✔ Element <//a[contains(text(),"Login")]> was visible after 323 milliseconds.
 ✔ Element <//div[@role="tabpanel"]//input[@name="email"]> was visible after 41 milliseconds.
 ✔ Element <//div[@role="tabpanel"]//input[@name="password"]> was visible after 39 milliseconds.
 ✔ Element <//button[contains(text(),"Sign In")]> was visible after 53 milliseconds.
 ✖ Timed out while waiting for element <(//a[starts-with(@href, "/bangalore/product")])[1]> to be present for 10000 milliseconds.  - expected "visible" but got: "not found"
at Object.waitForProductVisibilty (/website-node-react/e2e/desktop/pages/home.js:19:12)
at Object.Authorised checkout, bulk products (/website-node-react/e2e/desktop/tests/authorised-bulk.js:27:14)


 FAILED:  1 assertions failed and 6 passed (30.476s)

 _________________________________________________

TEST FAILURE:  1 assertions failed, 6 passed. (32.172s)

请帮助我在 docker 上无缝运行这些测试用例。

【问题讨论】:

  • 请您的代码试用和相关的HTML
  • 对不起,我听不懂。代码试用是什么意思?

标签: javascript selenium docker nightwatch.js google-chrome-headless


【解决方案1】:

根据您本地计算机上的跟踪日志,//a[starts-with(@href, "/bangalore/product")])[1]xpath 已成功解析。因此生成以下日志:

Element <(//a[starts-with(@href, "/bangalore/product")])[1]> was visible after 2781 milliseconds.

但是与//a[starts-with(@href, "/bangalore/product")])[1] 相同的xpath 并没有通过Docker 得到解决。作为一种直接的替代方法,您可以尝试如下更改引号:

<(//a[starts-with(@href, '/bangalore/product')])[1]>

现在,由于预期元素是通过 findElements() 返回的 first 元素,您可以简单地将 xpath 提及为:

"//a[starts-with(@href, '/bangalore/product')]"

作为替代方案,您可以尝试使用关键字 containsxpath,如下所示:

"//a[contains(@href, '/bangalore/product')]"

另一种选择是尝试CSS(开头为),如下所示:

"a[href^='/bangalore/product']"

另一种选择是尝试CSS(包含),如下所示:

"a[href*='/bangalore/product']"

【讨论】:

  • 谢谢,但我认为问题不在于 Xpath,因为它在 docker 中也通过了几次。在这里,主要问题是测试用例在 docker 中运行非常缓慢。假设在 e2e 测试用例中,执行登录的 xpath,那么 docker 可能会花费大量时间来呈现下一页,因此有时下一个 xpath 会超时。但这并没有发生在本地,因为它在本地机器上无缝且快速地运行。
  • 如果是时间问题,请通过WebDriverWaitExpectedConditions 结合使用诱导服务员
  • 我已将超时时间增加到 1 分钟(60 秒),仍然没有运气。
猜你喜欢
  • 2019-07-24
  • 2017-12-18
  • 2016-11-29
  • 1970-01-01
  • 2018-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多