javascript - npm E2E 测试在 Docker 中运行时超时,但在本地计算机上运行时通过

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

图片/框: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 测试。它在本地 headless 运行并且所有测试用例都通过了,但是当我在我们的本地 docker 上执行此操作时,启动需要很长时间,并且在通过几个测试用例后由于超时而停止。我正在使用 headless 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 上无缝运行这些测试用例。

最佳答案

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

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() 返回的元素您可以简单地提及 xpath作为:
"//a[starts-with(@href, '/bangalore/product')]"

作为替代方案,您可以尝试 xpath使用关键字 包含 如下 :
"//a[contains(@href, '/bangalore/product')]"

另一种选择是尝试 CSS (开头)如下:
"a[href^='/bangalore/product']"

另一种选择是尝试 CSS (包含)如下:
"a[href*='/bangalore/product']"

关于javascript - npm E2E 测试在 Docker 中运行时超时,但在本地计算机上运行时通过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49404327/

相关文章:

python - EOL 字符串文字使用 webdriver selenium 创建保存位置

selenium - 比较测试覆盖率指标以确定实现自动化后的增加/减少

在单击按钮之前调用 JavaScript 函数

Java 代码停止在 ChromeDriver 中查看详细日志?

python - docker postgres 角色不存在

node.js - Docker容器和PM2在ec2实例中运行

git - 在 Github 包注册表中绑定(bind) Docker 镜像以更正 Github 提交

javascript - ionic 应用程序 CORS 不存在 'Access-Control-Allow-Origin' header ,使用带有 CORS 中间件的 Lumen API

javascript - 无法从具有 'aspNetHidden' CSS 类的字符串中删除 HTML 标记

javascript - jQuery 复选框并选择 - 对值求和并添加到 var