I think you're doing it wrong.
In your project root folder, add Gemfile
file, this Gemfile can have something like this:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.5'
gem 'rspec', '~> 3.9'
gem 'capybara', '~> 3.30'
gem 'selenium-webdriver', '~> 3.142', '>= 3.142.6'
Create a spec/
directory in your project root
Create a log/
directory in your project root for your selinium logs.
Create a spec/spec_helper.rb
file with configuration like this:
# frozen-string-literal: true
require 'rspec'
require 'capybara/rspec'
require 'capybara/dsl'
require 'selenium-webdriver'
Selenium::WebDriver.logger.level = :debug
Selenium::WebDriver.logger.output = File.dirname(Dir.pwd) + '/project_dir_name/log/selenium.log'
Capybara.register_driver :firefox do |app|
Capybara::Selenium::Driver.new(app, browser: :firefox)
end
Capybara.default_driver = :firefox
Capybara.javascript_driver = :firefox
Capybara.app_host = 'http://127.0.0.1:3005'
Capybara.default_max_wait_time = 10
RSpec.configure do |config|
config.before(:each) do
config.include Capybara::DSL
end
end
The above code will setup rspec, capybara. You can change the driver, host and other configs if you want.
Now create a new spec/features/test.rb
file with something like this:
require 'spec_helper'
describe 'Google homepage test', js: true do
before(:each) do
visit('https://google.com')
end
describe "First test" do
it "check title" do
expect(page.title).to be == "some text"
end
end
end
Then run: bundle exec rspec spec/features/test.rb
from your project root.
If you don't want this way, then the problem is that you're running ruby test.rb
, actually test.rb
this should be runned via rspec
:
$ rspec test.rb
If you're using bundler, then:
$ bundle exec rspec test.rb