Why Do I Get "Including Capybara::Dsl in the Global Scope Is Not Recommended!"

Why do I get including Capybara::DSL in the global scope is not recommended!

Because including Capybara::DSL in the global scope is not recommended.

This includes many methods globally in the system, which could interfere with your own code.

Here's the correct way:

RSpec.configure do |config|
config.include Capybara::DSL, :type => :feature
end

“including Capybara::DSL in the global scope is not recommended!” want to remove it. console warning

I was having a similar issue tried many things but what worked for me is to remove config.include Capybara::DSL from spec_helper and include the LoginHelper in a Helpers module. In your case, they may look like this:

login_helper.rb

module Helpers
module LoginHelper
def login_user
visit 'https://staging.have2have.it/login'
within(".container-fluid") do
fill_in("email", with: 'shinsaurab@gmail.com', :match => :prefer_exact)
fill_in("password", with: '123', :match => :prefer_exact)
end
click_button('Log In')
end
end
end

And spec_helper will look like this:

require 'capybara'
require 'capybara/dsl'
require 'capybara/rspec'
require './spec/helpers/login_helper.rb'

Capybara.default_driver = :selenium

RSpec.configure do |config|
config.include Helpers::LoginHelper
end

Thanks!
Please let me know if you have any doubts

How can I avoid including Capybara::DSL in the global scope is not recommended! with Cucumber?

You want to include the Capybara::DSL in the Cucumber steps rather than global scope. Cucumber allows you to do this using the World.

The Capybara::DSL is included in the world by using the line:

World(Capybara::DSL)

As mentioned by @engineersmnky, you might want to just:

require 'capybara/cucumber'

This would add the Capybara::DSL to the world, as well as the RSpec::Expectations. It also sets up a couple of hooks. You can see exactly what this would do by checking the capybara/cucumber.rb file.

Allure Reports are not getting created when running the tests with cucumber - capybara - selenium

The problem here is that you are including Capybara::DSL in the global scope. Any relatively modern version of Capybara will print a warning to the console like "including Capybara::DSL in the global scope is not recommended!" specifically because it will have all sorts of strange side effects. This is because when you just do

include Capybara::DSL

outside of any classes or modules you end up including all of Capybaras methods on every object in your project. That's not what you want. It's impossible to say exactly what you need to put where without looking at your project, but assuming you have a normal project you probably want to put

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

in your env.rb, or just require 'capybara/cucumber' like instructed - https://github.com/teamcapybara/capybara#using-capybara-with-cucumber - which will get things set up correctly.

Selenium keep trying to find geckodriver, even when I think I've set it up with Chromedriver while using Ruby 2.3.3

You need to register a driver with a specific configuration to tell Capybara to use a different browser - https://github.com/teamcapybara/capybara#configuring-and-adding-drivers. However, if all you want is Selenium using Chrome with a default setup then Capybara already has a driver registered for you - https://github.com/teamcapybara/capybara#selenium

Capybara.default_driver = :selenium_chrome

That will require you to have chromedriver installed (which the chromedriver-helper gem will do for, although I would recommend using the webdrivers gem instead). If you don't want to use selenium/chromedriver then there are a couple of newer options which talk directly to Chrome, one of which is the appartion driver - https://github.com/twalpole/apparition



Related Topics



Leave a reply



Submit