簡體   English   中英

npm E2E測試在Docker中運行時超時,但在本地計算機上運行時通過

[英]npm E2E test is getting timed out when running in Docker but getting passed when running on local machine

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

嗨,我正在嘗試在節點版本為6.9.3的泊塢窗(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上無縫運行這些測試用例。

根據本地計算機上的跟蹤日志,成功解析了//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()返回的第一個元素, findElements()您可以簡單地將xpath提及為:

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

另外,您可以嘗試使用關鍵字包含以下內容的xpath

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

另一種選擇是嘗試CSS (開始於),如下所示:

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

另一種選擇是嘗試CSS (包含),如下所示:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM