mdtest
mdtest

Reputation: 1

uninitialized constant SitePrism from page declariation

I'm trying to set up a basic framework using Capybara, Cucumber and SitePrism, but I keep getting the error, "uninitialized constant SitePrism (NameError)" when I kick off a test.

Gemfile:

gem 'cucumber', '2.3.3'
gem 'capybara', '2.6.2'
gem 'selenium-webdriver', '2.53.0'
gem 'rspec'
gem 'site_prism'
gem 'mime-types', '>2.6', '<2.99.1'

Env.rb

require 'capybara'
require 'capybara/rspec'
require 'capybara/dsl'
require 'capybara/cucumber'
require 'selenium-webdriver'
require 'site_prism'
require 'cucumber'

require_rel '../features/pages'
require_rel '../features/classes'

World(Capybara::DSL)
World(Capybara::RSpecMatchers)

Login page

class LoginPage < SitePrism::Page
end

Login class

class Login

def initialize
  @current_page = LoginPage.new
end 

The error is being thrown on the line with "class LoginPage < SitePrism::Page". RubyMine can't find the SitePrism declaration to go to either. Am I missing something in the setup?

Upvotes: 0

Views: 1293

Answers (2)

Luke Hill
Luke Hill

Reputation: 458

So the reason you were getting this problem is because of the files being auto-loaded. Just ensure you require the gem files first so the namespaces are understood

Upvotes: 0

jeremy04
jeremy04

Reputation: 314

Your error looks 'require' related, but here is how I got it to work via: https://github.com/thuss/standalone-cucumber

Haven't used cucumber in a while, but the way I see "pages" currently implemented in my Rails project:

  • Create a file in "features/support/pages"
  • Follow the namespace conventions
  • Use modules, then import via the World() method.

Maybe this might work:

features/support/pages/login_page.rb

module Pages
 module LoginPage

  class LoginPageObj < SitePrism::Page
  end

  def login_obj
   LoginPageObj.new
  end

 end
end
World(Pages::LoginPage)

Env file:

require 'capybara'
require 'capybara/cucumber'
require 'site_prism'


Capybara.configure do |config|
  config.default_driver = :selenium
  config.app_host   = 'http://www.google.com'
end

World(Capybara::DSL)
World(Capybara::RSpecMatchers)

Notice how I didn't have to explicitly require any pages class, it looks like Cucumber might require it for you?

  • Note this is without RubyMine (I dont use it). If it works without RubyMine, I'd point fingers to that.

Upvotes: 1

Related Questions