LambdaTest provides support with Selenium WebDriver for pacing the execution of your automation test scripts. LambdaTest is a cloud-based, cross browser testing tool, providing a Selenium grid of 2000+ browsers and browser versions running through real operating systems to speed up automation testing of your web-app or website. This topic will help you to automate your website testing using Selenium for CapyBara Ruby on LambdaTest.
This topic will be focusing on:
All the code samples in this documentation can be found in the Capybara-Ruby LambdaTest Repository on GitHub. You can either download or clone the repository to quickly run your tests.
First, you would have to install Ruby and gem on your local system. Installing these platforms is a little different in each operating system
1 |
$ sudo apt-get install ruby-full |
1 |
$ brew install ruby |
Be aware of your LambdaTest authentication credentials i.e. your LambdaTest username, access key and HubURL. You need to set them up as your environment variables. You can retrieve them from your LambdaTest automation dashboard by clicking on the key icon near the help button.
For Linux/Mac:
1 2 |
export LT_USERNAME=<LT-username> && export LT_APIKEY=<LT-access-key> |
For Windows:
1 2 |
set LT_USERNAME=<LT-username> && set LT_APIKEY=<LT-access-key> |
Once you have ruby and gem setup, you would now have to install Selenium dependencies. Use the below gem command for installing Selenium:
1 |
bundle install |
You need to clone our GitHub repository which demonstrates a sample of CapyBara Ruby.
After cloning, you need to navigate to the cloned directory and install project dependencies using the below command:
1 |
gem install selenium-webdriver |
The example mentioned below would help you to execute your automation test using CapyBara Ruby.
1 2 3 4 5 6 7 8 9 10 |
Feature: Add to Todo list functionality Background: Given I am on https://lambdatest.github.io/sample-todo-app/ Scenario: Add Todo List When I click on first item When I click on second item When I add new item "New item to the list" Then I should see new item in list "New item to the list" |
Now Create the support rb file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
require 'yaml' require 'selenium/webdriver' require 'capybara/cucumber' # monkey patch to avoid reset sessions class Capybara::Selenium::Driver < Capybara::Driver::Base def reset! if @browser @browser.navigate.to('about:blank') end end end TASK_ID = (ENV['TASK_ID'] || 0).to_i CONFIG_NAME = ENV['CONFIG_NAME'] || 'single' CONFIG = YAML.load(File.read(File.join(File.dirname(__FILE__), "../../config/#{CONFIG_NAME}.config.yml"))) CONFIG['user'] = ENV['LT_USERNAME'] || CONFIG['user'] CONFIG['key'] = ENV['LT_ACCESS_KEY'] || CONFIG['key'] Capybara.register_driver :lambdatest do |app| @caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID]) if (CONFIG_NAME=='jenkins') puts ENV['LT_GRID_URL'] lt_browser = ENV['LT_BROWSER_NAME'] lt_os = ENV['LT_PLATFORM'] lt_browser_version = ENV['LT_BROWSER_VERSION'] lt_res = ENV['LT_RESOLUTION'] @caps={"browserName"=>lt_browser, "version"=>lt_browser_version, "platform"=>lt_os, "resolution"=>lt_res, "build"=>"capybara-lambdatest", "name"=>"single-Test-Jenkins","video"=>true, "network"=>true, "console"=>true, "visual"=>true } Capybara::Selenium::Driver.new(app, :browser => :remote, :url => ENV['LT_GRID_URL'], :desired_capabilities => @caps ) else Capybara::Selenium::Driver.new(app, :browser => :remote, :url => "https://#{CONFIG['user']}:#{CONFIG['key']}@#{CONFIG['server']}/wd/hub", :desired_capabilities => @caps ) end end Capybara.default_driver = :lambdatest Capybara.run_server = false |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
require 'rake' require 'parallel' require 'cucumber/rake/task' Cucumber::Rake::Task.new(:single) do |task| ENV['CONFIG_NAME'] ||= "single" task.cucumber_opts = ['--format=pretty', 'features/single.feature'] end task :default => :single Cucumber::Rake::Task.new(:local) do |task| task.cucumber_opts = ['--format=pretty', 'features/local.feature', 'CONFIG_NAME=local'] end task :parallel do |t, args| @num_parallel = 4 Parallel.map([*1..@num_parallel], :in_processes => @num_parallel) do |task_id| ENV["TASK_ID"] = (task_id - 1).to_s ENV['name'] = "parallel_test" ENV['CONFIG_NAME'] = "parallel" Rake::Task["single"].invoke Rake::Task["single"].reenable end end Cucumber::Rake::Task.new(:jenkins) do |task| task.cucumber_opts = ['--format=pretty', 'features/single.feature', 'CONFIG_NAME=jenkins'] end task :test do |t, args| Rake::Task["single"].invoke Rake::Task["single"].reenable Rake::Task["local"].invoke Rake::Task["parallel"].invoke end |
Note: Update *.config.yml files inside the config/ directory with your [LambdaTest Username and Access Key].
Navigate to the directory where you cloned the sample of CapyBara Ruby and run the following command.
→ To run a single test.
1 |
bundle exec rake single |
To help you perform cross browser testing of your locally stored web pages, LambdaTest provides an SSH(Secure Shell) tunnel connection with the name Lambda Tunnel. With Lambda Tunnel, you can execute your tests using CapyBara Ruby to perform automated cross browser testing on browsers offered by online Selenium grid at LambdaTest. So you make sure how well your changes look, even before your customers. Curious to know more about Lambda Tunnel?
Follow our documentation on Lambda Tunnel to know it all. OS specific instructions to download and setup tunnel binary can be found at the following links.
Download the binary file of:
Use the below command for running a local test.
1 |
bundle exec rake local |
Parallel Testing is one of the most demanding features of LambdaTest Selenium Grid. By parallel testing, you can run more than one test case, simultaneously. This means that Parallel testing would allow you to execute numerous automation test cases altogether. So you execute a single test scenario across different browsers or could run different test scenarios across the same browser but with different browser versions. Wondering how many parallel test cases can you run? That depends entirely on the number of concurrent session under your opted plan.
1 |
bundle exec rake parallel |
Monitor and analyze your test result on the LambdaTest Automation Dashboard.
Deploy your code in a reliable manner at scale using CapyBara Ruby with LambdaTest Selenium Grid, and ensure it looks robust across every browser to provide a seamless user experience to all your visitors. Happy Testing!