我想从我的javascript项目的源代码构建一个docker镜像。我用Mocha Framework写了一些测试。测试应该在构建docker构建过程中运行,因为我想使用Jenkins自动构建。
测试应该使用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)
...
当我在本地机器上的docker容器外运行测试时,一切正常。
我使用以下命令初始化webdriver:
var webdriver = require('selenium-webdriver');
var capabilities = webdriver.Capabilities.firefox();
capabilities.set('marionette', true);
var driver = new webdriver.Builder().withCapabilities(capabilities).build();
是否有关于如何在docker容器内无头地运行selenium测试的最佳实践?
答案 0 :(得分:0)
我通过运行启动selenium-standalone服务器的gulp任务和使用xvfb-run进行测试来解决问题:
def validate_password(value):
if not value or re.match("^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d!.@#$%^&*()?<>]{8,}$", value):
return value
raise forms.ValidationError(_("The password does not match the requirements. "
"It should be at least 8 characters long, contain 1 Uppercase letter, "
"1 lowercase letter and 1 number."))
password = PasswordField(widget=forms.PasswordInput(), label="Password", required=True, validators=[validate_password])