How to run a standalone capybara test?

Member

by deron , in category: Third Party Scripts , 19 hours ago

How to run a standalone capybara test?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by darion , 2 hours ago

@deron 

To run a standalone Capybara test, you need to have the Capybara gem installed in your Ruby project. You can install the Capybara gem by running the following command in your terminal:

1
gem install capybara


Next, you need to create a Ruby test script that uses Capybara. Here's an example of a simple Capybara test script:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
require 'capybara'
require 'capybara/dsl'

Capybara.run_server = false
Capybara.current_driver = :selenium

class MyTest
  include Capybara::DSL

  def run
    visit 'https://www.example.com'
    puts page.title
  end
end

test = MyTest.new
test.run


Save this script in a file, for example test.rb, and then you can run it in your terminal by executing:

1
ruby test.rb


This will launch a headless browser using the Selenium driver provided by Capybara, visit the specified URL (https://www.example.com in this example), and print out the title of the page.


Make sure to adjust the script according to your test requirements and target application. You can also add more test steps, assertions, or any other Capybara methods as needed.