0
votes

So im going to be writing a framework that uses Rspec/Capybara and Selenium to do some automation testing on an app. Im using purely RSpec (no rails) and im having some difficulties in getting everything setup correctly.

The problem I am running into is when im trying to include page object files into my specs. Right now my directory looks like:

spec (Actual .spec files go here, spec_helper is also here) spec/support (Page Object Files go here)

In my page object files my first problem is it can't find the Capybara DSL unless I do: include Capybara::DSL at the top of each page object file (Which apparently isn't a good idea according to the warning message it gives me)

The other problem is that including my page object files in my tests Im needing to do a require_relative to the specific file (Which is sort of a pain) otherwise it can't find the class.

Is there something in spec_helper that will fix this? Im not an expert in ruby so I assume Im missing something. The Capybara DSL problem I can't figure out either for example requiring require 'capybara/rspec' doesn't seem to help either.

1

1 Answers

1
votes

You have a few options for Capybara::DSL -

  1. Include Capybara::DSL into whatever base class you're using for your PageObjects so the Capybara methods are available in that class (as opposed to on the global object) - ie. the include Capybara::DSL goes inside the class definition - not at the top of the file.

  2. Keep an instance of Capybara::Session in your page object instances and call all capybara methods on that session instance - @my_session.find(...), etc.

  3. Always use Capybara.current_session when calling Capybara methods - Capybara.current_session.find(...), etc

As for the require issue -- you can either use require_relative to specify files to require based from the current file, or you use require and specify the location from the projects root (current working directory). If you have a directory of files you want loaded you can add something like the following to your spec_helper.rb to tell it to load all the files

Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f }