问题描述
通常我在 3000 端口使用 rails 开发服务器.
Normally I use the rails dev server at port 3000.
Capybara/Cucumber 使用 Capybara.server_port = 31337
.如果我从默认驱动程序切换到 selenium,它看起来会尝试连接端口 80.
Capybara/Cucumber uses Capybara.server_port = 31337
. If I swap from the default driver to selenium, it looks like it tries to connect on port 80.
我正在努力理解:
- 使用 selenium 时,是否需要在测试环境中单独实例化一个测试服务器.
- 如果上述问题的答案是肯定的,我该如何做到这一点,以便我可以在 Web 驱动程序之间无缝切换,而无需不断更改?
如果有人有 env.rb 配置的示例可以帮助,请告诉我!
If someone has an example of a env.rb configuration that would help please let me know!
谢谢!
克里斯.
推荐答案
如果你使用selenium,你应该在测试环境中启动web server.您可以在与开发不同的端口上启动它.然后你应该配置 Capybara 使用那个端口:
If you use selenium, you should start web server in test environment. You can start it on a different port from development. Then you should configure Capybara to use that port:
Capybara.run_server = true #Whether start server when testing
Capybara.server_port = 8200
Capybara.default_selector = :css #:xpath #default selector , you can change to :css
Capybara.default_wait_time = 5 #When we testing AJAX, we can set a default wait time
Capybara.ignore_hidden_elements = false #Ignore hidden elements when testing, make helpful when you hide or show elements using javascript
Capybara.javascript_driver = :selenium #default driver when you using @javascript tag
# Other option is:
# Capybara.javascript_driver = :webkit
如果您不想每次在运行黄瓜场景之前都启动服务器,我建议您使用 capybara webkit 司机.所有 javascript 场景都将在后台运行.它也适用于持续集成服务器.
If you don't want to start server every time before you run your cucumber scenarios I suggest you to use capybara webkit driver. All javascript scenarios will run at background. It also will work on continuous integration server.
如果您在 Linux 平台上,capybara-webkit 需要 X 服务器才能运行.要设置它,您可以使用 headless gem.这是黄瓜的无头配置:
If you are on Linux platform, capybara-webkit requires an X server to run. To setup it you can use headless gem. Here is headless configuration for cucumber:
# place code below in features/support/headless.rb
if Capybara.current_driver == :webkit
require 'headless'
headless = Headless.new
headless.start
at_exit do
headless.destroy
end
end
这篇关于使用 capybara/rails 运行 selenium 时,如何配置服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!