当使用 capybara/rails 运行 selenium 时,如何配置服务器?

发布于 2024-12-20 02:46:45 字数 340 浏览 1 评论 0原文

通常我在端口 3000 处使用 Rails 开发服务器。Capybara

/Cucumber 使用 Capybara.server_port = 31337。如果我从默认驱动程序切换到selenium,它看起来会尝试在端口80上连接。

我试图理解:

  • 使用selenium时,我是否需要在测试环境上单独实例化测试服务器。
  • 如果上述问题的答案是肯定的,我该如何做到这一点,以便我可以在网络驱动程序之间无缝切换,而不必不断更改内容?

如果有人有 env.rb 配置示例可以帮助请告诉我!

谢谢!

克里斯.

Normally I use the rails dev server at port 3000.

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.

I'm trying to understand:

  • When using selenium, do I need to separately instantiate a test server on the test environment.
  • If the answer to the above question is yes, how can I make it so I can seamlessly swap between web drivers without having to keep changing things?

If someone has an example of a env.rb configuration that would help please let me know!

Thanks!

Chris.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

书信已泛黄 2024-12-27 02:46:45

如果你使用selenium,你应该在测试环境中启动Web服务器。您可以在与开发不同的端口上启动它。然后你应该配置 Capybara 使用该端口:

  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

如果你不想在运行黄瓜场景之前每次都启动服务器,我建议你使用 水豚 webkit 驱动程序。所有 JavaScript 场景都将在后台运行。它还将在持续集成服务器上工作。

如果您使用的是 Linux 平台,capybara-webkit 需要 X 服务器才能运行。要设置它,您可以使用 headless gem。这是黄瓜的无头配置:

# 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

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

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.

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
挽心 2024-12-27 02:46:45

这可能会也可能不会回答您的问题,但这是我的 env.rb 文件(相关位)。

Capybara.app_host = "http://0.0.0.0:3000"
Capybara.server_port = 3000

我也有这个:

Capybara.register_driver :iphone do |app|
  require 'selenium/webdriver'
  profile = Selenium::WebDriver::Firefox::Profile.new
  profile['general.useragent.override'] = "iPhone"

  Capybara::Selenium::Driver.new(app, :profile => profile)
end

也许你可以在你的 Cucumber 脚本中的 register_driver 位和 switch 驱动程序中包含 Capybara.app_host 和 .server_port 行。 :/

This may or may not answer your question, but here's my env.rb file (the relevant bits).

Capybara.app_host = "http://0.0.0.0:3000"
Capybara.server_port = 3000

I also have this in there:

Capybara.register_driver :iphone do |app|
  require 'selenium/webdriver'
  profile = Selenium::WebDriver::Firefox::Profile.new
  profile['general.useragent.override'] = "iPhone"

  Capybara::Selenium::Driver.new(app, :profile => profile)
end

Maybe you can have the Capybara.app_host and .server_port lines inside the register_driver bit and switch driver in your Cucumber scripts. :/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文