问题描述
通常我在端口3000上使用Rails开发服务器.
Normally I use the rails dev server at port 3000.
水豚/黄瓜使用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.
我想了解:
- 使用硒时,是否需要在测试环境中单独实例化测试服务器.
- 如果上述问题的答案是肯定的,那么我该如何做到这一点,这样我就可以在Web驱动程序之间无缝切换而不必不断进行更改?
如果有人举了一个env.rb配置示例,可以帮助您,请告诉我!
If someone has an example of a env.rb configuration that would help please let me know!
谢谢!
克里斯.
推荐答案
如果使用硒,则应在测试环境中启动Web服务器.您可以在与开发不同的端口上启动它.然后,您应该将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服务器.要进行设置,您可以使用无头 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时,如何配置服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!