Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With Capybara, how can I tell whether the driver currently being used supports JavaScript?

In my Rails application, I have a set of cucumber acceptance tests that test various pages of my application. With cucumber, tagging a specific test (scenario) with @javascript causes that scenario to run using a JavaScript driver instead of a simpler driver that does not support JavaScript.

Is there an easy way for my tests to determine whether they are currently being run with a driver that supports JavaScript or one that doesn't? I want this so that I can make my tests behave slightly differently if they are being run with JavaScript enabled.

like image 770
Ajedi32 Avatar asked Nov 06 '12 17:11

Ajedi32


People also ask

What is Capybara test?

Capybara is an acceptance test framework for web applications. It's a common choice for end-to-end, acceptance, or integration testing in Rails applications. It allows developers to simulate a user on a web page and make assertions based on the content and environment of the page.

Does Capybara use Selenium?

Capybara supports Selenium 3.5+ (Webdriver). In order to use Selenium, you'll need to install the selenium-webdriver gem, and add it to your Gemfile if you're using bundler.


1 Answers

In case anyone's interested, I took a look at the documentation for Capybara and found another possible solution:

if Capybara.current_driver == Capybara.javascript_driver
  # Supports JavaScript
else
  # Doesn't support JavaScript
end
like image 112
Ajedi32 Avatar answered Nov 11 '22 23:11

Ajedi32