Home > Mobile >  Capybara using Selenium webdriver undefined method `visit' for #<RSpec::ExampleGroups
Capybara using Selenium webdriver undefined method `visit' for #<RSpec::ExampleGroups

Time:09-16

The following is my setup just three files to start with. no folder structure

Gemfile

gem 'capybara'
gem 'selenium-webdriver'

spec_helper.rb

require 'capybara/rspec'
require "selenium/webdriver"

Capybara.register_driver :chrome do |app|
  Capybara::Selenium::Driver.new(app, browser: :chrome)
end

Capybara.register_driver :headless_chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    chromeOptions: { args: %w(headless disable-gpu) }
  )

  Capybara::Selenium::Driver.new app,
    browser: :chrome,
    desired_capabilities: capabilities
end

Capybara.javascript_driver = :headless_chrome

run.rb

require_relative 'spec_helper'
describe "test process" do
    it "checks google" do
        visit("www.google.com")
        puts "LAUNCHED"
    end
end

New to testing. Any help would be appreciated.

I ran it using

rspec run.rb

CodePudding user response:

By default Capybaras methods are only included in RSpec tests of type :feature and :system - https://github.com/teamcapybara/capybara/blob/master/lib/capybara/rspec.rb#L10

Tag your test with the correct type and the methods will be available

describe 'test proces', type: :feature do
  • Related