├── .gitignore ├── Gemfile ├── todo-click-test.rb ├── firefox-with-profile.rb ├── driver-close.rb └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.lock 2 | .idea -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | # gem "rails" 6 | gem 'selenium-webdriver', '~> 4.38', '>= 4.38.0' 7 | -------------------------------------------------------------------------------- /todo-click-test.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'selenium-webdriver' 3 | 4 | # Input capabilities 5 | 6 | USERNAME = ENV["LT_USERNAME"] || "{username}" 7 | ACCESS_KEY = ENV["LT_ACCESS_KEY"] || "{accessToken}" 8 | 9 | options = Selenium::WebDriver::Options.chrome 10 | options.browser_version = "108.0" 11 | options.platform_name = "Windows 10" 12 | lt_options = {}; 13 | lt_options[:username] = "#{USERNAME}"; 14 | lt_options[:accessKey] = "#{ACCESS_KEY}"; 15 | lt_options[:project] = "Untitled"; 16 | lt_options[:sessionName] = "Ruby Test"; 17 | lt_options[:build] = "Ruby Job"; 18 | lt_options[:w3c] = true; 19 | lt_options[:plugin] = "ruby-ruby"; 20 | options.add_option('LT:Options', lt_options); 21 | 22 | driver = Selenium::WebDriver.for(:remote, 23 | :url => "https://hub.lambdatest.com/wd/hub", 24 | :capabilities => options) 25 | begin 26 | driver.navigate.to "https://lambdatest.github.io/sample-todo-app/" 27 | driver.find_element(:name, 'li1').click 28 | driver.find_element(:name, 'li2').click 29 | driver.find_element(:id, 'sampletodotext').send_keys("Yey, Let's add it to list") 30 | driver.find_element(:id, 'addbutton').click 31 | enteredText = driver.find_element(:xpath, '/html/body/div/div/div/ul/li[6]/span').text 32 | enteredText == "Yey, Let's add it to list" ? status = "passed" : status = "failed" 33 | driver.execute_script('lambda-status='+ status) 34 | end 35 | print("Execution Successful\n") 36 | driver.quit 37 | 38 | -------------------------------------------------------------------------------- /firefox-with-profile.rb: -------------------------------------------------------------------------------- 1 | require 'selenium-webdriver' 2 | require 'test/unit' 3 | 4 | class LtTest < Test::Unit::TestCase 5 | def setup 6 | username = ENV["LT_USERNAME"] || "{username}" 7 | access_key = ENV["LT_ACCESS_KEY"] || "{accessToken}" 8 | grid_url = "https://#{username}:#{access_key}@hub.lambdatest.com/wd/hub" 9 | 10 | # Firefox profile setup 11 | profile = Selenium::WebDriver::Firefox::Profile.new 12 | profile['browser.download.dir'] = 'C:\\Users\\ltuser\\Downloads' 13 | profile['browser.download.useDownloadDir'] = true 14 | profile['browser.helperApps.neverAsk.saveToDisk'] = 15 | "application/pdf,application/msword,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.wordprocessingml.document" 16 | profile['pdfjs.disabled'] = true 17 | 18 | # Firefox Options (Selenium 4 style) 19 | options = Selenium::WebDriver::Options.firefox 20 | options.browser_version = "latest" 21 | options.platform_name = "Windows 10" 22 | options.profile = profile 23 | 24 | # LambdaTest specific options 25 | lt_options = { 26 | "project" => "Ruby Firefox Profile", 27 | "build" => "firefox-profile-test", 28 | "name" => "Download PDF Test", 29 | "network" => true, 30 | "visual" => true, 31 | "video" => true, 32 | "console" => true, 33 | "selenium_version" => "4.38.0" 34 | } 35 | options.add_option('LT:Options', lt_options) 36 | 37 | # Start Remote WebDriver session 38 | @driver = Selenium::WebDriver.for(:remote, url: grid_url, capabilities: options) 39 | end 40 | 41 | def test_Login 42 | puts("Starting file download test...") 43 | @driver.navigate.to("http://www.pdf995.com/samples") 44 | 45 | # Mark test as passed for demonstration 46 | status = "passed" 47 | @driver.execute_script("lambda-status=#{status}") 48 | @driver.execute_script("lambda-status=#{status}") 49 | end 50 | 51 | def teardown 52 | @driver.quit 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /driver-close.rb: -------------------------------------------------------------------------------- 1 | require 'selenium-webdriver' 2 | require 'test/unit' 3 | 4 | class LtTest < Test::Unit::TestCase 5 | def setup 6 | username = ENV["LT_USERNAME"] || "{username}" 7 | access_key = ENV["LT_ACCESS_KEY"] || "{accessToken}" 8 | grid_url = "https://#{username}:#{access_key}@hub.lambdatest.com/wd/hub" 9 | 10 | # Chrome Options (Selenium 4 style) 11 | options = Selenium::WebDriver::Options.chrome 12 | options.browser_version = "latest" 13 | options.platform_name = "Windows 10" 14 | 15 | # LambdaTest options 16 | lt_options = { 17 | "project" => "Ruby Chrome Multi-Tab Test", 18 | "build" => "LambdaTest ruby google search build", 19 | "name" => "LambdaTest ruby google search name", 20 | "network" => false, 21 | "visual" => false, 22 | "video" => true, 23 | "console" => false 24 | } 25 | options.add_option('LT:Options', lt_options) 26 | 27 | # Start driver 28 | @driver = Selenium::WebDriver.for(:remote, url: grid_url, capabilities: options) 29 | end 30 | 31 | def test_Login 32 | puts("Opening multiple tabs test...") 33 | @driver.navigate.to("https://lambdatest.github.io/sample-todo-app/") 34 | @driver.execute_script("window.open('https://google.com/')") 35 | @driver.execute_script("window.open('http://www.pdf995.com/samples')") 36 | 37 | tabs = @driver.window_handles 38 | assert_equal(3, tabs.size, "Expected 3 tabs but found #{tabs.size}") 39 | sleep(1) 40 | 41 | # Close last tab 42 | @driver.switch_to.window(@driver.window_handles.last) 43 | @driver.close 44 | assert_equal(2, @driver.window_handles.size) 45 | 46 | # Close another tab 47 | @driver.switch_to.window(@driver.window_handles.last) 48 | @driver.close 49 | assert_equal(1, @driver.window_handles.size) 50 | 51 | # Back to main and perform actions 52 | @driver.switch_to.window(@driver.window_handles.last) 53 | elem1 = @driver.find_element(:name, 'li1') 54 | elem2 = @driver.find_element(:name, 'li2') 55 | elem1.click 56 | elem2.click 57 | puts("Test executed successfully.") 58 | @driver.execute_script('lambda-status=passed') 59 | rescue => e 60 | @driver.execute_script('lambda-status=failed') 61 | raise e 62 | end 63 | 64 | def teardown 65 | @driver.quit 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Run Selenium Tests With Capybara On LambdaTest 2 | 3 |  4 | 5 |
6 | Blog 7 | ⋅ 8 | Docs 9 | ⋅ 10 | Learning Hub 11 | ⋅ 12 | Newsletter 13 | ⋅ 14 | Certifications 15 | ⋅ 16 | YouTube 17 |
18 | 19 | 20 | 21 | 22 | *Learn how to use Ruby framework to configure and run your Java automation testing scripts on the LambdaTest platform* 23 | 24 | [
](https://accounts.lambdatest.com/register)
25 |
26 | ## Table Of Contents
27 |
28 | * [Pre-requisites](#pre-requisites)
29 | * [Run-Your-First-Test](#run-your-first-test)
30 | * [Executing-The-Test](#executing-the-test)
31 | * [Testing Locally Hosted or Privately Hosted Projects](#testing-locally-hosted-or-privately-hosted-projects)
32 |
33 | ## Pre-requisites
34 |
35 | Before you can start performing Ruby automation testing with Selenium, you would need to:
36 |
37 | * Install **Ruby** and **gem** on your local system. Follow these instructions to install on different operating systems.
38 |
39 | * For **Windows**, you can download from the [official website](https://rubyinstaller.org/downloads/).
40 | * For **Linux** or **Ubuntu**, you can run a simple apt command like below:
41 | ```bash
42 | sudo apt-get install ruby-full
43 | ```
44 | * For **macOS**, you can run a [Homebrew](https://brew.sh/) command like this:
45 | ```bash
46 | brew install ruby
47 | ```
48 | * To run tests in parallel you will require the [parallel_tests](https://github.com/grosser/parallel_tests) gem.
49 | * LambdaTest binary file for running tests on your locally hosted web pages.
50 |
51 | ### Installing Selenium Dependencies and Tutorial Repo
52 |
53 | Clone the LambdaTest’s [ruby-selenium-sample repository](https://github.com/LambdaTest/ruby-selenium-sample) and navigate to the code directory as shown below:
54 | ```bash
55 | git clone https://github.com/LambdaTest/ruby-selenium-sample.git
56 | cd ruby-selenium-sample
57 | ```
58 | Install selenium dependencies for Ruby automation testing.
59 | ```bash
60 | gem install bundler
61 | bundle install
62 | ```
63 | ### Setting up Your Authentication
64 | Make sure you have your LambdaTest credentials with you to run test automation scripts with Jest on LambdaTest Selenium Grid. You can obtain these credentials from the [LambdaTest Automation Dashboard](https://automation.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=ruby-selenium-sample) or through LambdaTest Profile.
65 |
66 | Set LambdaTest Username and Access Key in environment variables.
67 | * For Linux/macOS:
68 | `export LT_USERNAME="YOUR_USERNAME" export LT_ACCESS_KEY="YOUR ACCESS KEY"`
69 | * For Windows:
70 | `set LT_USERNAME="YOUR_USERNAME" set LT_ACCESS_KEY="YOUR ACCESS KEY"`
71 |
72 | ## Run Your First Test
73 |
74 | ### Sample Test with Ruby
75 |
76 | **Test Scenario:** The to-do list example mentioned in the [lambdatest.rb](https://github.com/LambdaTest/ruby-selenium-sample/blob/master/todo-click-test.rb) sample file would help you to execute your automation test using Ruby.
77 |
78 | ### Configuration of Your Test Capabilities
79 |
80 | In the test script, you need to update your test capabilities. In this code, we are passing browser, browser version, and operating system information, along with LambdaTest Selenium grid capabilities via capabilities object. The capabilities in the above code are defined as:
81 | ```ruby
82 | caps = {
83 | :browserName => "chrome",
84 | :version => "latest",
85 | :platform => "windows 10",
86 | :geoLocation => "US",
87 | :name => "LambdaTest ruby google search name",
88 | :build => "LambdaTest ruby google search build",
89 | :network => false,
90 | :visual => false,
91 | :video => true,
92 | :console => false
93 | }
94 | ```
95 | > You can generate capabilities for your test requirements with the help of our inbuilt **[Capabilities Generator tool](https://www.lambdatest.com/capabilities-generator/?utm_source=github&utm_medium=repo&utm_campaign=ruby-selenium-sample)**.
96 |
97 | ### Executing the Test
98 |
99 | To execute the test script, run the following script on terminal/cmd.
100 | ```bash
101 | bundle exec ruby todo-click-test.rb
102 | ```
103 | Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on [LambdaTest automation dashboard](https://automation.lambdatest.com/build/?utm_source=github&utm_medium=repo&utm_campaign=ruby-selenium-sample). LambdaTest Automation Dashboard will help you view all your text logs, screenshots and video recording for your entire automation tests.
104 |
105 | ## Testing Locally Hosted or Privately Hosted Projects
106 |
107 | You can test your locally hosted or privately hosted projects with [LambdaTest Selenium grid cloud](https://www.lambdatest.com/selenium-automation/?utm_source=github&utm_medium=repo&utm_campaign=ruby-selenium-sample) using LambdaTest Tunnel app. All you would have to do is set up an SSH tunnel using LambdaTest Tunnel app and pass toggle `tunnel = True` via desired capabilities. LambdaTest Tunnel establishes a secure SSH protocol based tunnel that allows you in testing your locally hosted or privately hosted pages, even before they are made live.
108 |
109 | >Refer our [LambdaTest Tunnel documentation](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) for more information.
110 |
111 | Here’s how you can establish LambdaTest Tunnel.
112 |
113 | >Download the binary file of:
114 | >* [LambdaTest Tunnel for Windows](https://downloads.lambdatest.com/tunnel/v3/windows/64bit/LT_Windows.zip)
115 | * [LambdaTest Tunnel for Mac](https://downloads.lambdatest.com/tunnel/v3/mac/64bit/LT_Mac.zip)
116 | * [LambdaTest Tunnel for Linux](https://downloads.lambdatest.com/tunnel/v3/linux/64bit/LT_Linux.zip)
117 |
118 | Open command prompt and navigate to the binary folder.
119 |
120 | Run the following command:
121 | ```bash
122 | LT -user {user’s login email} -key {user’s access key}
123 | ```
124 | So if your user name is lambdatest@example.com and key is 123456, the command would be:
125 | ```bash
126 | LT -user lambdatest@example.com -key 123456
127 | ```
128 | Once you are able to connect **LambdaTest Tunnel** successfully, you would just have to pass on tunnel capabilities in the code shown below :
129 |
130 | **Tunnel Capability**
131 | ```ruby
132 | caps = {
133 | ...
134 | :tunnel => true,
135 | ...
136 | }
137 | ```
138 | ## Additional Links
139 |
140 | * [Advanced Configuration for Capabilities](https://www.lambdatest.com/support/docs/selenium-automation-capabilities/)
141 | * [How to test locally hosted apps](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/)
142 | * [How to integrate LambdaTest with CI/CD](https://www.lambdatest.com/support/docs/integrations-with-ci-cd-tools/)
143 |
144 | ## Documentation & Resources :books:
145 |
146 |
147 | Visit the following links to learn more about LambdaTest's features, setup and tutorials around test automation, mobile app testing, responsive testing, and manual testing.
148 |
149 | * [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=ruby-selenium-sample)
150 | * [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=ruby-selenium-sample)
151 | * [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=ruby-selenium-sample)
152 |
153 | ## LambdaTest Community :busts_in_silhouette:
154 |
155 | The [LambdaTest Community](https://community.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=ruby-selenium-sample) allows people to interact with tech enthusiasts. Connect, ask questions, and learn from tech-savvy people. Discuss best practises in web development, testing, and DevOps with professionals from across the globe 🌎
156 |
157 | ## What's New At LambdaTest ❓
158 |
159 | To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/)
160 |
161 | ## About LambdaTest
162 |
163 | [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=ruby-selenium-sample) is a leading test execution and orchestration platform that is fast, reliable, scalable, and secure. It allows users to run both manual and automated testing of web and mobile apps across 3000+ different browsers, operating systems, and real device combinations. Using LambdaTest, businesses can ensure quicker developer feedback and hence achieve faster go to market. Over 500 enterprises and 1 Million + users across 130+ countries rely on LambdaTest for their testing needs.
164 |
165 | ### Features
166 |
167 | * Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments.
168 | * Real-time cross browser testing on 3000+ environments.
169 | * Test on Real device cloud
170 | * Blazing fast test automation with HyperExecute
171 | * Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale.
172 | * Smart Visual Regression Testing on cloud
173 | * 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more.
174 | * Automated Screenshot testing across multiple browsers in a single click.
175 | * Local testing of web and mobile apps.
176 | * Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems.
177 | * Geolocation testing of web and mobile apps across 53+ countries.
178 | * LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports
179 |
180 |
181 | [
](https://accounts.lambdatest.com/register)
182 |
183 |
184 | ## We are here to help you :headphones:
185 |
186 | * Got a query? we are available 24x7 to help. [Contact Us](support@lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=ruby-selenium-sample)
187 | * For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=Capybara-Cucumber-Ruby)
188 |
189 |
--------------------------------------------------------------------------------