How correctly config rails test to run it in browser? ( site_prism, cucumber, capybara, selenium webdriver )
Asked Answered
G

1

2

I am writing test for rails app, I use site_prism, capybara, selenium and cucumber. How can I setup Selenium driver to run my tests in browser (firefox)?

For example, it is one of features:


    Given /^I navigate to Dashboard page$/ do 
      @page = DashboardPage.new # Dashboardpage is inheritor of SitePrism::Page
      @page.load
      @page.login_form.login_field.set 'admin'
      @page.login_form.password_field.set 'test'
      @page.login_form.signin_button.click
      @page.title.include? 'Dashboard'  
    end

This is my features/support/env.rb config file:


    require 'cucumber/rails'
    require 'capybara'  
    require 'capybara/cucumber'
    require 'selenium-webdriver' 
    require 'site_prism'

    # cypabara settings
    Capybara.default_selector       = :css
    Capybara.ignore_hidden_elements = false 
    Capybara.default_wait_time      = 20 
    Capybara.app_host               = "http://0.0.0.0:9292" 

    # selenium setting
    Capybara.register_driver :selenium do |app| 
        profile = Selenium::WebDriver::Firefox::Profile.new 
        Capybara::Selenium::Driver.new( app, :browser => :firefox, :profile => profile ) 
    end

    # enable/disable rescue
    ActionController::Base.allow_rescue = false

    # DB cleaner strategy
    begin
      DatabaseCleaner.strategy = :transaction
    rescue NameError
      raise "You need to add database_cleaner to your Gemfile to use it."
    end

    # JS strategy
    Cucumber::Rails::Database.javascript_strategy = :truncation

I know, with capybara I can run scenario in browser like this:


      Capybara.app_host = 'http://0.0.0.0:9292'
      session = Capybara::Session.new(:selenium)
      session.visit '/home'
      session.driver.browser.quit

But! Using site_prism, I just have Page#load method. Maybe I need to integrate load method with capybara session, but how can I do this?

Mostly, I do everything as it's described in documentation (cypabara wiki on github), but my tests runs without browser. And I can't understand why.

Please, help. Thanks.

Gentianella answered 4/10, 2013 at 9:7 Comment(0)
D
4

Actually you've set up browser in selenium setting:

Capybara.register_driver :selenium do |app| 
   profile = Selenium::WebDriver::Firefox::Profile.new 
   Capybara::Selenium::Driver.new( app, :browser => :firefox, :profile => profile ) 
end

By default selenium driver use firefox as default browser. You can set it in capybara settings:

Capybara.default_driver = :selenium

For site_prism you need such requirements:

require 'capybara'
require 'capybara/dsl'
require 'capybara/cucumber'
require 'selenium-webdriver'
require 'site_prism'
Decretal answered 7/10, 2013 at 16:58 Comment(1)
I just forgot to require 'capybara/dsl'. Thanks a lot, @Helga ChekhGentianella

© 2022 - 2024 — McMap. All rights reserved.