Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When running selenium with capybara/rails, how do I configure the server?

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.

like image 852
cjm2671 Avatar asked Dec 07 '11 10:12

cjm2671


1 Answers

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
like image 181
Voldy Avatar answered Sep 29 '22 21:09

Voldy