2016-07-11 376 views
1

我想從我的javascript項目的源代碼構建一個docker鏡像。我用摩卡框架寫了一些測試。測試應該在構建docker構建過程中運行,因爲我想用Jenkins自動化構建。在Docker容器中運行硒測試

測試應該使用Firefox webdriver。我在Docker鏡像中安裝了Xvfb,爲Firefox進程提供虛擬顯示。

但每次我運行生成的所有測試失敗,我得到錯誤信息如下所示:

Uncaught WebDriverError: Unable to parse new session response: {"error":"unknown error","message":"connection refused"} 
    at WebDriverError (node_modules/selenium-webdriver/lib/error.js:27:5) 
    at client_.send.then.response (node_modules/selenium-webdriver/http/index.js:477:17) 
    at ManagedPromise.invokeCallback_ (node_modules/selenium-webdriver/lib/promise.js:1379:14) 
    at TaskQueue.execute_ (node_modules/selenium-webdriver/lib/promise.js:2913:14) 
    at TaskQueue.executeNext_ (node_modules/selenium-webdriver/lib/promise.js:2896:21) 
    at asyncRun (node_modules/selenium-webdriver/lib/promise.js:2820:25) 
    at node_modules/selenium-webdriver/lib/promise.js:639:7 
    at process._tickDomainCallback (internal/process/next_tick.js:129:7) 
From: Task: WebDriver.createSession() 
    at Function.createSession (node_modules/selenium-webdriver/lib/webdriver.js:329:24) 
    at Driver (node_modules/selenium-webdriver/firefox/index.js:386:38) 
    at Builder.build (node_modules/selenium-webdriver/builder.js:467:16) 
    at Object.<anonymous> (test/e2e/driver.js:10:69) 
... 

當我在我的本地機器運行一切泊塢窗容器外部的測試工作正常。

我初始化以下命令的webdriver:

var webdriver = require('selenium-webdriver'); 

var capabilities = webdriver.Capabilities.firefox(); 
capabilities.set('marionette', true); 
var driver = new webdriver.Builder().withCapabilities(capabilities).build(); 

是否有關於如何將泊塢窗容器內headlessly運行Selenium測試的最佳做法?

+0

您可以添加Dockerfile? –

回答

0

我固定通過運行啓動硒獨立服務器,並與xvfb的運行測試吞氣任務的問題:

CMD xvfb-run ./node_modules/gulp/bin/gulp.js test