<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Roselyne Makena</title>
    <description>The latest articles on DEV Community by Roselyne Makena (@roselynemakena).</description>
    <link>https://dev.to/roselynemakena</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F981942%2F378ac03f-4a25-490b-8530-aba8c2553244.png</url>
      <title>DEV Community: Roselyne Makena</title>
      <link>https://dev.to/roselynemakena</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/roselynemakena"/>
    <language>en</language>
    <item>
      <title>How To Use Waits In Selenium Ruby</title>
      <dc:creator>Roselyne Makena</dc:creator>
      <pubDate>Mon, 23 Jan 2023 14:08:29 +0000</pubDate>
      <link>https://dev.to/testmuai/how-to-use-waits-in-selenium-ruby-3cec</link>
      <guid>https://dev.to/testmuai/how-to-use-waits-in-selenium-ruby-3cec</guid>
      <description>&lt;p&gt;The wait command in Selenium Ruby is a powerful tool that allows for a high level of control over the &lt;a href="https://www.lambdatest.com/learning-hub/test-execution?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;test execution&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It is particularly useful for waiting for an element or simulating human behavior.&lt;/p&gt;

&lt;p&gt;Examples of this might be to trigger an action on a page, wait for an element to appear and then click it, wait for some content to appear before submitting a form, or even simply wait for data to load on the backend before running any sort of tests.&lt;/p&gt;

&lt;p&gt;This is very common when running AJAX requests, where you want to ensure the server returns the data before running the subsequent commands in the test. Using the right type and appropriate duration of waits could prevent your tests from breaking since &lt;a href="https://www.lambdatest.com/blog/types-of-waits-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;waits in Selenium&lt;/a&gt; is the best way to tackle test flakiness.&lt;/p&gt;

&lt;p&gt;I have been using waits in Selenium Ruby for many of my projects, which is why I have covered all the essential aspects of waits in Selenium Ruby as a part of this &lt;a href="https://www.lambdatest.com/blog/selenium-ruby/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Ruby tutorial&lt;/a&gt;. The learnings of this blog on waits in Selenium Ruby will help you develop test code that considers the AUT’s dynamic nature.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do you know? A &lt;a href="https://www.lambdatest.com/free-online-tools/credit-card-number-generator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;credit card number generator&lt;/a&gt; is a coding based tool to stimulate random credit card numbers that developers or testers can use to test the functionality of web pages without using real credit card details.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why are Waits used in Selenium?
&lt;/h2&gt;

&lt;p&gt;Wait allows the developer to write tests to simulate user behavior, such as pressing a button, clicking on a link, and more. What it does is it waits for the presence (or visibility) and/or clickability of a certain element present in the DOM.&lt;/p&gt;

&lt;p&gt;It also allows you to set up dependencies between two elements listed as targets in one statement.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You must know or guess when your target element will appear on the page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You will have to handle possible page refreshes (potentially resulting in test failures or test flakiness).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The wait command in &lt;a href="https://www.lambdatest.com/web-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;web testing&lt;/a&gt; can be used in the following ways listed below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbh3vroy64odr8y8f6z11.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbh3vroy64odr8y8f6z11.png" width="800" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do you know? &lt;a href="https://www.lambdatest.com/free-online-tools/crc32b-hash-calculator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;CRC32B hash generator&lt;/a&gt; lets you quickly generate the CRC32B checksum hash from a given string. In addition, you can generate CRC32B hashes via your web browser.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wait for the WebElement to be present
&lt;/h2&gt;

&lt;p&gt;By default, Selenium Ruby waits forever for elements to appear on the page. You can use a wait function to allow the page to load in scenarios where you want to wait for an element to be present. This is particularly important when testing for elements on the page.&lt;/p&gt;

&lt;p&gt;A scenario in which the wait command would be useful is in the &lt;a href="https://ecommerce-playground.lambdatest.io/" rel="noopener noreferrer"&gt;LambdaTest E-Commerce Playground&lt;/a&gt;. For example, when logging in, it is necessary to ensure that the username and password text box elements are present before entering the credentials. Using the wait command can confirm this before proceeding with the test.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wait for the WebElement to be visible
&lt;/h2&gt;

&lt;p&gt;This is useful when you want to trigger an action of some kind but only after a certain element has been loaded onto the DOM. In this case, the wait enables quick test execution since you can ascertain that the element is now visible for your tests to begin.&lt;/p&gt;

&lt;p&gt;To picture this in action, we can take an example of an eCommerce site that takes seconds to load the main title on the homepage. For our test to be successful, we would employ a wait to check for the visibility of that title and then proceed with the tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wait for the WebElement to be clickable
&lt;/h2&gt;

&lt;p&gt;Some elements need to be clickable before we can run our tests. For example, in our eCommerce example, we need to checkout but need the submit button to be visible before we can click on it.&lt;/p&gt;

&lt;p&gt;Such a case would require using one of the wait methods to achieve a successful test.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wait for the WebElement to complete its job
&lt;/h2&gt;

&lt;p&gt;For example when you need to wait for a progress bar to load or wait for an animation that needs to run before you can proceed with testing.&lt;/p&gt;

&lt;p&gt;To understand this better, we can take an example of an eCommerce site that takes some time to load all the items we picked onto our cart. In this case, we would use wait to ensure that the progress bar(which indicates fetching data) has been completed before we start our test assertions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do you know? The need to extract &lt;a href="https://www.lambdatest.com/free-online-tools/extract-text-from-xml?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;text from XML&lt;/a&gt; (eXtensible Markup Language) documents may arise for a number of reasons. One such justification is to run text analysis or natural language processing on the XML document’s content.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wait to ensure the element is not stale
&lt;/h2&gt;

&lt;p&gt;A wait method can be used to ensure that an element has not been modified and declared stale during the testing process.&lt;/p&gt;

&lt;p&gt;It is important to note that “stale” means that an element (or its state) might have changed (or updated) after the last time you visited it. A common reason for this is automatic page refreshes or AJAX calls (or dynamic page loads). As a general rule, test logic should be designed to handle stale elements.&lt;/p&gt;

&lt;p&gt;A scenario where the wait command would be necessary is when elements are deleted from the DOM, potentially causing a &lt;a href="https://www.lambdatest.com/blog/handling-stale-element-exceptions-in-selenium-java/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;stale element exception&lt;/a&gt;. For example, if the session on the page becomes invalid after logging in, the previously loaded elements may no longer be present. In this case, using the wait function can refresh the page or generate a new session, depending on the requirements of the test.&lt;/p&gt;

&lt;p&gt;Well, there are patterns you can use in Selenium Ruby to achieve this task based on the expected flow of the application under test and the expected test.&lt;/p&gt;

&lt;p&gt;We will explore some of the scenarios by creating tests that showcase the use of different wait types to achieve our goals. Now, the question is, what types of waits should be used in your Selenium Ruby test code?&lt;/p&gt;

&lt;p&gt;Akin to other &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt;-supported languages, Ruby (with Selenium) also supports popular wait mechanisms (i.e., Implicit wait, Explicit wait, and Fluent wait); let’s deep dive into each one of these (from a Selenium Ruby perspective).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implicit, Explicit, and Fluent Waits in Selenium Ruby&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implicit waits&lt;/strong&gt; are applied by default in Selenium. They apply to all elements on that page and are not selective on any particular element.&lt;/p&gt;

&lt;p&gt;However, for &lt;strong&gt;Explicit waits&lt;/strong&gt;, you must choose the element that the wait needs to be added onto and declare the required wait function before any action. Let’s glance at the main differences between implicit and explicit waits.&lt;/p&gt;

&lt;p&gt;Run Selenium Ruby tests on 3000+ browsers.&lt;a href="https://accounts.lambdatest.com/register?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=register" rel="noopener noreferrer"&gt;Try LambdaTest Now!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do you know? J&lt;a href="https://www.lambdatest.com/free-online-tools/extract-text-from-json?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;SON to Text Converter&lt;/a&gt; is a simple tool for converting JSON data to text. Convert, copy, and paste. It’s a handy tool for converting JavaScript Object Notation data to plain text for novice users or data analysts who don’t understand JSON.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Differences between Implicit and Explicit Waits in Selenium Ruby
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
    &lt;tr&gt;
        &lt;td&gt;IMPLICIT WAITS&lt;/td&gt;
        &lt;td&gt;EXPLICIT WAITS &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Implicit wait time is applied to all the elements in the script.&lt;/td&gt;
        &lt;td&gt;Explicit wait time is only applied to a specific element, and it is defined by the script. &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Implicit waits do not need a condition to be true for a wait to occur. When an implicit wait is executed, it will wait until the end of the data passes, no matter what is happening.&lt;/td&gt;
        &lt;td&gt;In an explicit wait, a condition must be true (or it times out) before it begins to execute. &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Implicit waits are used for generally faster loading elements, but their flexibility is limited.&lt;/td&gt;
        &lt;td&gt;Explicit waits are used for slower-loading elements where flexibility is necessary. &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Implicit waits are a better option when the load time of objects is not known.&lt;/td&gt;
        &lt;td&gt;Explicit waits can be applied to any object, and its load time is known.&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Here are the different types of waits that can be used in your Selenium Ruby test code. For demonstration, we would be using the &lt;a href="https://ecommerce-playground.lambdatest.io/" rel="noopener noreferrer"&gt;LambdaTest eCommerce&lt;/a&gt; website.&lt;/p&gt;

&lt;p&gt;We will look at the following test cases for the tests and discuss how Selenium Ruby handles each scenario while performing &lt;a href="https://www.lambdatest.com/ruby-automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Ruby automation testing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Scenarios for the code demonstration:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Demonstrate how an implicit wait is applied during our tests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Demonstrate how an explicit wait is applied to specific elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Demonstrate how an explicit wait is applied by adding a rescue block with a timeout.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Implicit Waits in Selenium Ruby
&lt;/h2&gt;

&lt;p&gt;In Ruby, an implicit wait controls a test instance’s behavior when a test method is executed. The implicit wait will time out after a given amount of time if the current web element is unavailable in the DOM before throwing a No Such Element Exception. You can learn more about it through this blog on &lt;a href="https://www.lambdatest.com/blog/49-common-selenium-exceptions-automation-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;common Selenium Exceptions&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Implicit wait functions are non-deterministic, which means they do not apply any specific logic or pattern to determine if the page has fully loaded. But on the other hand, explicit wait functions are deterministic. For example, in the snapshot below, we are explicitly calling the wait on our driver so we can have the title load before the test can proceed.&lt;/p&gt;

&lt;p&gt;An implicit wait is simple and may be used to perform any custom action during the waiting period. Any explicit wait command will override an implicit wait.&lt;/p&gt;

&lt;p&gt;Let’s examine a code demonstration of implementing implicit waits in Selenium Ruby.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;* I’m using Ruby 3.0.3 and SeleniumWebDriver 4.1.0. If you have an older version of Ruby or SeleniumWebDrive, you can check the Ruby version by opening the terminal and typing the following.*&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting elements from Inspect Tools for our tests
&lt;/h3&gt;

&lt;p&gt;Before we look at the code demonstration, let’s look at how we get the elements from the browser to get the element names.&lt;/p&gt;

&lt;p&gt;In the store, we will be looking at the search element, which in our tests, we have used the syntax below. You will notice that we used the :name “search.” But how did we get this name?&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;search_box = @my_driver.find_element(:name, “search”)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To get element names or identifiers, we use browser inspection tools. Most browsers have support for this.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the demo site &amp;gt; Right-click on the page and click inspect.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fecz1w6sgulp3l4vgs83u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fecz1w6sgulp3l4vgs83u.png" width="800" height="568"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2- With the element selected, you will notice that the element panel that appears — There are the attributes for that object. Check for a suitable element that is unique to that element. It’s always recommended to use IDs if they are available on the specific element, but if not — you can use the next best unique identifier.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjm2qll9dtf5fizq4po61.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjm2qll9dtf5fizq4po61.png" width="800" height="807"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3- Another example is getting an XPath to use in our tests. Similarly, following steps one and 2, we can right-click and get the XPath from the browser developer tools as shown.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feudchu7qt9us0s2ztt9y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feudchu7qt9us0s2ztt9y.png" width="800" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This mode of checking for elements will apply to all other elements in the testing process.&lt;/p&gt;

&lt;p&gt;Now that we have seen &lt;a href="https://www.lambdatest.com/software-testing-questions/how-to-inspect-elements?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;how to inspect elements&lt;/a&gt;. Let’s look at the code demo for the waits we have discussed above. You can also learn about more locator strategies through this tutorial on &lt;a href="https://www.lambdatest.com/learning-hub/selenium-locators?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;locators in Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax (Implicit Wait):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To employ an implicit wait, you need to know the amount of time you would like &lt;a href="https://www.lambdatest.com/learning-hub/webdriver?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt; to wait and then define it as a variable, as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    # Set an implicit wait time
       @my_driver.manage.timeouts.implicit_wait = 30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Demonstration: Implicit Waits in Selenium Ruby
&lt;/h3&gt;

&lt;p&gt;This is an example of implicit waits in Selenium Ruby, which shows how we use implicit waits in Selenium Ruby.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require 'Selenium-webdriver'
require 'test-unit'

class EcommerceTests &amp;lt; Test::Unit::TestCase
 def setup
   username = "{LAMBDATEST_USERNAME}"
   accessToken = "{LAMBDATEST_ACCESS_KEY}"
   gridUrl = "hub.lambdatest.com/wd/hub"

   capabilities = {
     'LT:Options' =&amp;gt; {
       "user" =&amp;gt; username,
       "accessKey" =&amp;gt; accessToken,
       "build" =&amp;gt; "Ecommerce Wait Test v.1",
       "name" =&amp;gt; "Ecommerce Wait Tests",
       "platformName" =&amp;gt; "Windows 11"
     },
     "browserName" =&amp;gt; "Firefox",
     "browserVersion" =&amp;gt; "100.0",
   }

   @my_driver = Selenium::WebDriver.for(:remote,
                                        :url =&amp;gt; "https://" + username + ":" + accessToken + "@" + gridUrl,
                                        :desired_capabilities =&amp;gt; capabilities)

   @my_driver = Selenium::WebDriver.for :firefox
   @url = "https://ecommerce-playground.lambdatest.io/"

   @my_driver.get(@url)

   # Set an implicit wait time
   @my_driver.manage.timeouts.implicit_wait = 30

 end

 def test_title_should_be_your_store

   # The implicit time will apply by default. i.e 30 seconds
   assert_equal(@my_driver.title, "Your Store")
 end

 def teardown
   @my_driver.quit
 end
end

 def teardown
   @my_driver.quit
 end

end
          `
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s have a quick walkthrough on the code we have written above.&lt;/p&gt;

&lt;p&gt;We first set up our capabilities and have our WebDriver ready by including the below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgfzlg1nzjn9cp2euabxt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgfzlg1nzjn9cp2euabxt.png" width="800" height="486"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Export your Username and Access Key in environment variables by running the following commands on the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   For Linux/macOS: 
    export LAMDATEST_USERNAME="YOUR_USERNAME"
    export LAMDATEST_ACCESS_KEY="YOUR ACCESS KEY"

    For Windows: set LT_USERNAME="YOUR_USERNAME"
    set LT_ACCESS_KEY="YOUR ACCESS KEY"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will ensure that our variables are set up and ready for consumption by our script.&lt;/p&gt;

&lt;p&gt;Next, on line 35, we set our implicit time to 30 seconds, as seen below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwf2o0dd4hqgcn9f9zfa8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwf2o0dd4hqgcn9f9zfa8.png" width="800" height="229"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, we set an implicit wait using the manage.timeouts.implicit_wait = 30 method. Selenium will wait 30 seconds for any element to be present in the DOM before throwing a Timeout error.&lt;/p&gt;

&lt;p&gt;If the element is found before the 30 seconds are over, the test will continue as expected without any error and will not wait for the time to elapse.&lt;/p&gt;

&lt;p&gt;If the element is found before the 30 seconds are over, the test will continue as expected without any error and will not wait for the time to elapse.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6acal0vnusau8yia9210.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6acal0vnusau8yia9210.png" width="800" height="169"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, on our test, we assert without additional methods since, by default, the implicit wait will be applied, as shown above.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do you know? LambdaTest’s &lt;a href="https://www.lambdatest.com/free-online-tools/random-octal-generator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;Random Octal Generator&lt;/a&gt; is a free online generator to generate random octal numbers by choosing how many digits each octal number should have and how many octal numbers to generate.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Explicit Waits in Selenium Ruby
&lt;/h2&gt;

&lt;p&gt;An explicit wait will make the test do something before it times out. This is useful when you have a set time to perform your test, say, “let’s test this page for 15 seconds”. An explicit wait allows you to wait for the correct element before running a set action, like click or submit.&lt;/p&gt;

&lt;p&gt;It is distinct from other waits as its effects are immediate, meaning it does not stop the execution of the test method when a timeout occurs. This means that any action performed after waiting for an element will still take place.&lt;/p&gt;

&lt;p&gt;Explicit waits are very useful in testing for non-simplistic situations where you wish to define a response time to an element and enforce this response time as long as the provided condition is satisfied when it returns true.&lt;/p&gt;

&lt;p&gt;Some of these waits on conditions are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;driver.find_element(id: “myElement”).enabled? — A clickable element is enabled.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;driver.find_element(id: “myElement”).displayed? — An element is visible.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;driver.find_element(id: “myElement”).text.included? — An element has particular text.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;driver.switch_to.alert — An alert has been loaded.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;driver.find_element(:id, ‘CheckBox’).selected? — A checkbox has been selected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;driver.find_element(:id, ‘CheckBox’).click — A click has been made.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;driver.find_element(:id, ‘CheckBox’).clear — Deselect a checkbox.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Demonstration: Explicit Waits in Selenium Ruby
&lt;/h3&gt;

&lt;p&gt;Let’s look at the full code demonstrating explicit waits in Selenium Ruby.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    require 'selenium-webdriver'
    require 'test-unit'

    class EcommerceTests &amp;lt; Test::Unit::TestCase
     def setup
       username= "{LAMBDATEST_USERNAME}"
       accessToken= "{LAMBDATEST_ACCESS_KEY}"
       gridUrl = "hub.lambdatest.com/wd/hub"

       capabilities = {
         'LT:Options' =&amp;gt; {
           "user" =&amp;gt; username,
           "accessKey" =&amp;gt; accessToken,
           "build" =&amp;gt; "Ecommerce Wait Test v.1",
           "name" =&amp;gt; "Ecommerce Wait Tests",
           "platformName" =&amp;gt; "Windows 11"
         },
         "browserName" =&amp;gt; "Firefox",
         "browserVersion" =&amp;gt; "100.0",
       }


       @my_driver = Selenium::WebDriver.for(:remote,
                                         :url =&amp;gt; "https://"+username+":"+accessToken+"@"+gridUrl,
                                         :desired_capabilities =&amp;gt; capabilities)

       @my_driver = Selenium::WebDriver.for :firefox
       @url = "https://ecommerce-playground.lambdatest.io/"

       @my_driver.get(@url)

       # Set an implicit wait time
       @my_driver.manage.timeouts.implicit_wait = 30

       # Set the explicit wait time for a maximum wait of 60 seconds
       @wait = Selenium::WebDriver::Wait.new(:timeout =&amp;gt; 60)

     end

     def test_search_functionality_should_yield_results

       assert_equal(@my_driver.title, "Your Store")

       search_box = @my_driver.find_element(:name, "search")

       search_box.clear
       search_box.send_keys("phone")
       search_box.submit
       sleep(5)

       # Call the explicit wait time - Here, the waiting time will be set to 60s and not the 30s.
       search_title = @wait.until { @my_driver.find_element(:xpath, '//*[@id="entry_212456"]/h1') }

       # Second test assertion - title has loaded
       assert_equal("Search - phone", search_title.text)
     end

     def teardown
       @my_driver.quit
     end

    end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the explicit wait code, we use the defined, explicit function on our Selenium methods.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnqvm4j9q24brd2db3r0e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnqvm4j9q24brd2db3r0e.png" width="800" height="188"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We set our explicit function as a variable called @wait — which we call later in our test, as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F677yjwa4hyexqbq0ut5g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F677yjwa4hyexqbq0ut5g.png" width="800" height="131"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Fluent Waits in Selenium Ruby
&lt;/h3&gt;

&lt;p&gt;Fluent waits support an exponential wait time where the wait time is a function of the wait function. The exponential waiting allows for more control over how long to wait for elements — for example, in an eCommerce site, you may wish to test that an element can appear before being clicked before you proceed.&lt;/p&gt;

&lt;p&gt;The fluent wait will allow you to check frequently after a specified amount of time before increasing the wait time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax (Fluent Wait):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    @fluent_wait.until { @my_driver.find_element(:name, "search-box-doesnt-exist") 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Demonstration: Fluent Waits in Selenium Ruby
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    require 'selenium-webdriver'
    require 'test-unit'

    class EcommerceTests &amp;lt; Test::Unit::TestCase
     def setup
       username= "{LAMBDATEST_USERNAME}"
       accessToken= "{LAMBDATEST_ACCESS_KEY}"
       gridUrl = "hub.lambdatest.com/wd/hub"

       capabilities = {
         'LT:Options' =&amp;gt; {
           "user" =&amp;gt; username,
           "accessKey" =&amp;gt; accessToken,
           "build" =&amp;gt; "Ecommerce Wait Test v.1",
           "name" =&amp;gt; "Ecommerce Wait Tests",
           "platformName" =&amp;gt; "Windows 11"
         },
         "browserName" =&amp;gt; "Firefox",
         "browserVersion" =&amp;gt; "100.0",
       }


       @my_driver = Selenium::WebDriver.for(:remote,
                                         :url =&amp;gt; "https://"+username+":"+accessToken+"@"+gridUrl,
                                         :desired_capabilities =&amp;gt; capabilities)

       # @my_driver = Selenium::WebDriver.for :firefox
       @url = "https://ecommerce-playground.lambdatest.io/"

       @my_driver.get(@url)

       # We define the exception we expect
       exception = Selenium::WebDriver::Error::NoSuchElementError

       # Set a fluent wait time for a maximum wait of 45 seconds  - for use later in the tests
       # Here, the error NoSuchElementError is expected to be thrown, but we don't want to fail the test if it does, so we use the rescue block
       @fluent_wait = Selenium::WebDriver::Wait.new(timeout: 45, interval: 5, message: 'Timed out after 45 secs', ignore: exception)

     end

     def test_search_functionality_with_fluent_wait

       assert_equal(@my_driver.title, "Your Store")

       # Here we call an element that does not exist and check that the fluent wait works as expected, we
       # ignore the NoSuchElementError exception and rescue the TimeOutError exception to proceed with the test
       begin
         @fluent_wait.until { @my_driver.find_element(:name, "search-box-doesnt-exist") }
       rescue Selenium::WebDriver::Error::TimeoutError
         puts "Element not found"
       end

     end

     def teardown
       @my_driver.quit
     end

    end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s have a look at the fluent wait code walkthrough above, what just happened you might ask.&lt;/p&gt;

&lt;p&gt;Now that we know what the setup does from examples of implicit and explicit waits in previous sections, we will concentrate more on the test itself.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxqkmsodw247qgo7nz5pp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxqkmsodw247qgo7nz5pp.png" width="800" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We define the name of our exception that we intend to ignore in case of the fluent wait times out. This is a &lt;strong&gt;NoSuchElementError&lt;/strong&gt;, which is the exception Selenium throws when an element is not found on the DOM.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx0jvqn6w2bd4i6rt2ytw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx0jvqn6w2bd4i6rt2ytw.png" width="800" height="105"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will notice at the setup on line 39 we defined our fluent wait method and then declared our fluent wait method using the interval parameter of 5 seconds. This means that the fluent wait will wait for 5 seconds and then perform a check if the element is available.&lt;/p&gt;

&lt;p&gt;Thus before the test fails, the script will have tried to check for the element 9 times since our timeout is 45 seconds. We will confirm this from our test results below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   # Here we call an element that does not exist and check that the fluent wait works as expected, we
       # ignore the NoSuchElementError exception and rescue the TimeOutError exception to proceed with the test
       begin
         @fluent_wait.until { @my_driver.find_element(:name, "search-box-doesnt-exist") }
       rescue Selenium::WebDriver::Error::TimeoutError
         puts "Element not found"
       end

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;`We then call an element that does not exist and check that the fluent wait works as expected, we ignore the NoSuchElementError exception and rescue the TimeOutError exception to proceed with the test.&lt;/p&gt;

&lt;p&gt;Let’s discuss the usage of the rescue block in our tests.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are rescue blocks used for while testing in Ruby?
&lt;/h3&gt;

&lt;p&gt;Rescue blocks are similar to try..catch blocks in Java, where you can catch exceptions and choose to do another action in case of an exception. This is useful when you want to prevent a test from failing and do something else instead.&lt;/p&gt;

&lt;p&gt;When using rescue blocks in &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automated testing&lt;/a&gt;, we can include multiple types of errors by chaining the rescue blocks together. This is important when we must ignore multiple exceptions while waiting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do you know? You can convert &lt;a href="https://www.lambdatest.com/free-online-tools/markdown-to-html-converter?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;Markdown to HTML&lt;/a&gt; easily through this tool, just paste your markdown language in the input field &amp;amp; click convert to HTML.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to run Selenium Ruby tests on a cloud grid?
&lt;/h2&gt;

&lt;p&gt;To run Selenium Ruby tests on a cloud grid, you must set up a cloud-based &lt;a href="https://www.lambdatest.com/blog/selenium-grid-setup-tutorial/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Grid&lt;/a&gt;, such as LambdaTest. Once you have set up an account and configured your grid, you can use the Selenium WebDriver in your Ruby script to connect to the grid and execute your tests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/automation-testing-tool?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Automation testing tools&lt;/a&gt; like LambdaTest offer an extensive &lt;a href="https://www.lambdatest.com/online-browser-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;online device farm&lt;/a&gt; comprising over 3000 real devices with real operating systems for performing Selenium Ruby testing at scale. This allows for comprehensive &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt; using LambdaTest’s online Selenium Grid.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/WZlsHlReRww"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do you know? LambdaTest’s free online &lt;a href="https://www.lambdatest.com/free-online-tools/xml-prettify?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;XML Prettify&lt;/a&gt; tool can identify errors in your XML code by highlighting invalid elements, missing attributes, and other issues.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can also subscribe to the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?sub_confirmation=1" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around Selenium testing, &lt;a href="https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress E2E testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Login to access the &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=login" rel="noopener noreferrer"&gt;LambdaTest Dashboard&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check on the automate tab for your test run.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You should see results similar to the screenshot above, indicating that your tests have run successfully. You can watch the video to see how your test ran. On the right-hand side pane, you have a list showing the execution steps during the test process.&lt;/p&gt;

&lt;p&gt;On the cloud, we noticed a NoSuchElement Error thrown, but the tests all passed as we expected — thanks to our rescue method. If we wanted our tests to fail, we would remove the rescue method. These results show what we would expect to see on the LambdaTest dashboard.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frdden62knoc4l75i574e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frdden62knoc4l75i574e.png" width="800" height="402"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;*&lt;em&gt;On the section labeled A *&lt;/em&gt;— If you check the difference between the time stamps — you will notice it’s 5 seconds. — And this directly correlates to the 5 seconds interval parameter we specified on our fluent wait.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;*&lt;em&gt;On the section labeled B *&lt;/em&gt;— You will see the NO SUCH ELEMENT defined as the reason the test was unsuccessful. However, you will note that the tests will not be marked as failed because we used a rescue block.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Viewing the dashboard for essential metrics that can help troubleshoot your tests is important. For example, at the top right corner, you can see the browser, operating system, resolution, and the duration taken to run your test — These options can be changed on the capabilities file that we passed earlier to match what you desire to test for.&lt;/p&gt;

&lt;p&gt;More information can be obtained by clicking the metadata button, which will give more information about your tests that looks like below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiuop8vjkx04715l445ly.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiuop8vjkx04715l445ly.png" width="800" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LambdaTest is a platform that allows you to streamline your test execution process by centralizing all of your test data in one place. This makes it easy for you to access and analyze your test results, so you can make informed decisions about your software development process.&lt;/p&gt;

&lt;p&gt;With &lt;a href="https://www.lambdatest.com/test-analytics?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest Test Analytics&lt;/a&gt;, you can quickly and easily view test results, compare different test runs, and identify areas where your tests may fail or improve. This can help you to optimize your testing process and improve the overall quality of your software. LambdaTest also provides an easy way to debug and fix issues by providing detailed error logs, screenshots, and video recordings of tests, which can be really useful for developers and testers to troubleshoot issues.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyoj7wq9upnmrxiq6797o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyoj7wq9upnmrxiq6797o.png" width="800" height="516"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuyip62gxn62k68o5krld.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuyip62gxn62k68o5krld.png" width="800" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are a developer or tester looking to improve your Ruby skills, the Selenium Ruby 101 certification from LambdaTest may be a valuable resource for you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do you know? Use this free online &lt;a href="https://www.lambdatest.com/free-online-tools/css-prettify?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jan23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;CSS prettify&lt;/a&gt; formatter to clean up your minified or disorganized CSS code. Your code will be considerably simpler to read and edit if you use this tool.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Waits in Selenium Ruby control which test is executed and when. The implicit wait allows you to specify a wait time for any given test method to run before returning. The explicit wait allows you to perform actions within the specified time before waiting for the element to be found. The fluent wait supports an exponential wait based on certain conditions being true before it executes.&lt;/p&gt;

&lt;p&gt;All these wait methods are very important in Selenium. They help you achieve test reliability and reduce the number of tests that might have failed because of a timeout or another error you might want to catch.&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>discord</category>
      <category>community</category>
      <category>feedback</category>
    </item>
    <item>
      <title>How To Maximize Browser In Selenium Ruby</title>
      <dc:creator>Roselyne Makena</dc:creator>
      <pubDate>Fri, 02 Dec 2022 15:06:44 +0000</pubDate>
      <link>https://dev.to/testmuai/how-to-maximize-browser-in-selenium-ruby-5152</link>
      <guid>https://dev.to/testmuai/how-to-maximize-browser-in-selenium-ruby-5152</guid>
      <description>&lt;p&gt;As testers, we’ve probably all encountered bugs that occur when a browser is resized. Although many browsers nowadays have improved the quality of their resizable windows, I am sure every tester should know how to create a resizable window on purpose while performing &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automation testing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For example, how can you make the browser window smaller to accommodate certain elements? Conversely, can you maximize the browser? This entire blog delves into how you can minimize and maximize browser in Selenium Ruby.&lt;/p&gt;

&lt;p&gt;Selenium is a great &lt;a href="https://www.lambdatest.com/automation-testing-tool?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automation testing tool&lt;/a&gt;, but it works best with Ruby to create a powerful automation solution. Ruby offers clean syntax and enhanced library support, making it an ideal choice for &lt;a href="https://www.lambdatest.com/automated-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automated browser testing&lt;/a&gt; of web applications.&lt;/p&gt;

&lt;p&gt;This Selenium Ruby tutorial will teach you how to maximize browser in Selenium Ruby and minimize and resize it to different sizes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do we need to maximize the browser window?
&lt;/h2&gt;

&lt;p&gt;A browser window is a limited storage space used to display web pages. The browser window size and position may change depending upon the size of your monitor display and the operating system you are using. For example, if you are using a large screen monitor, your window size will be larger than that of a small screen like a mobile phone or a tablet.&lt;/p&gt;

&lt;p&gt;If you are wondering how to check whether your website is responsive across different screen sizes, you can try this free &lt;a href="https://www.lambdatest.com/responsive-checker?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;responsive checker&lt;/a&gt; by LambdaTest.&lt;/p&gt;

&lt;p&gt;Depending on the operating system, the browser window may not fill up your whole screen. If a browser window is not maximized, the user can only see a portion of the window, reducing your site’s visibility and consequently affecting the testing process.&lt;/p&gt;

&lt;p&gt;It’s always good to incorporate &lt;a href="https://www.lambdatest.com/blog/selenium-best-practices-for-web-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium best practices&lt;/a&gt; and maximize your browser when running automation tests because it is much easier to test many different elements on your page. It is also the default behavior for most users when viewing your webpage.&lt;/p&gt;

&lt;p&gt;There are very many screen sizes available in the market today. The different sizes are determined between the designers of a website and the developer of a browser. While working, many people do not want to see only a small portion of the web page. They need to see what is being displayed at that particular moment.&lt;/p&gt;

&lt;p&gt;At any given time, users would use their choice of the device when accessing your website or the web app. This fragmentation in using devices, smartphones, tablets, and laptops creates a need to ensure that your automation tests cover those possible scenarios.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2488%2F0%2AYKaTwkvteddsNKxF.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2488%2F0%2AYKaTwkvteddsNKxF.png" width="800" height="575"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If a certain browser is only tested with just one browser window size, it might not work as expected if users use different browser window sizes. Therefore it is important to test your application using multiple browsers and viewport sizes to ensure that it works as expected on any screen size.&lt;/p&gt;

&lt;p&gt;Having said that, if you are testing your application, it is important to see the full web page to ensure that everything is being displayed as expected so that you can test all possible scenarios. To achieve this, you need to maximize your browser window. Maximizing the browser window simply means that it fills up the screen, and you can see more of your site.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AgIwwRZrRERzSV5fm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AgIwwRZrRERzSV5fm.png" width="800" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Viewing a link or element outside the browser window
&lt;/h2&gt;

&lt;p&gt;What happens when you click on a link that loads a web page outside your browser window?&lt;/p&gt;

&lt;p&gt;To view a link or element outside the browser window, you can approach this in different ways. We may need to scroll the page to find that element in scrollable web pages. However, if your window is maximized and the element is in view, you can click on the link and navigate to the new page.&lt;/p&gt;

&lt;p&gt;In our test demo code, we will look at the following test scenarios to see the different screen sizes in which a browser can be minimized during &lt;a href="https://www.lambdatest.com/web-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;web testing&lt;/a&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Load our test page and &lt;strong&gt;maximize&lt;/strong&gt; the browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Minimize&lt;/strong&gt; our browser to the tab.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Resize&lt;/strong&gt; our browser to a defined size.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What is minimizing the browser?
&lt;/h2&gt;

&lt;p&gt;Minimizing refers to docking the browser to the taskbar so it is not visible on the screen. This is common when using other applications while you want to access the browser at some later stage.&lt;/p&gt;

&lt;p&gt;Most browsers have three buttons at the top bar to handle this by default. One button will maximize the browser, the other will minimize it, and another will close the browser — as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AYxRRMs2xXYMeyTHh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AYxRRMs2xXYMeyTHh.png" width="542" height="272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Button used to close the browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Button used to minimize the browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Button used to maximize the browser.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note that different operating systems and browsers may present this in a different order or design, but the basic concept remains the same.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: &lt;a href="https://www.lambdatest.com/learning-hub/smoke-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Smoke Testing&lt;/a&gt; Tutorial - A Comprehensive Guide With Examples And Best Practices&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is browser resizing?
&lt;/h2&gt;

&lt;p&gt;Resizing refers to changing the browser window’s size to a specified size. A user resizes a browser window by clicking one of the edges of the browser window and dragging it to a different size. The default buttons for resizing are the two hands of a window, as shown above in the picture.&lt;/p&gt;

&lt;p&gt;During resizing while writing our Selenium Ruby demo code, we will provide a height and a width for the browser window. We will then be able to use the height and width to change the size of our browser window by using the WebDriver API.&lt;/p&gt;

&lt;p&gt;Run your Selenium Ruby test scripts across 3000+ real browsers and OS. &lt;a href="https://accounts.lambdatest.com/register?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=register" rel="noopener noreferrer"&gt;Try LambdaTest Now!&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Scenarios where you need to resize or minimize the browser when testing
&lt;/h2&gt;

&lt;p&gt;When designing a website, it’s important to consider what happens when your design is viewed on various platforms, browsers, and screen sizes. While you may be able to design a site that works perfectly fine on your computer with its 1920×1080 resolution and Retina display, other devices and settings may affect how your design looks.&lt;/p&gt;

&lt;p&gt;With the wide variety of platforms and browsers available today, it’s essential to test your designs on all of these settings before you launch them to the public, whether you’re launching a new website or just making adjustments to an existing one. To do this type of testing effectively, you need to know how to resize your browser so that it matches the size of other devices and adjust each browser’s default zoom.&lt;/p&gt;

&lt;p&gt;Below are some scenarios where you’ll want to resize or minimize the browser:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When you cannot see the element you are trying to test, you can maximize the browser window and scroll down to find that element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you want to ensure that the tested element is visible on the page for a maximized/minimized window size, then resize your browser window to the size being tested for.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can zoom in and out of a web page when you rotate the view of a web page or a map using the mouse. Therefore we need to resize our browser window for this purpose.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensure that the page fits into your browser window when simulating a view on a mobile device.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Your web page may have scroll bars, and you need to scroll down at a certain browser size to view what is showing in that view (or window).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When you resize your browser, some websites automatically fit the webpage (to reduce white spaces). Padding sizes change when browsers change sizes and might affect the visibility of content. In addition to padding-top and padding-bottom, there are several other CSS properties for positioning siblings. You can refer to this &lt;a href="https://www.lambdatest.com/learning-hub/css-cheat-sheet?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;CSS Cheat Sheet&lt;/a&gt; to learn more about those properties.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that not all browsers conform to the standard. For example, Opera and Webkit do not implement margin auto, or the four sides of a box have different effects depending on the implementation. Therefore, the precise behavior of margins may be different in a browser’s implementation, thus the need to test this for different browser window sizes.&lt;/p&gt;

&lt;p&gt;For example, a maximized vs. a minimized window size clearly shows that different elements are shown by displaying more spaces in the minimized window size.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2676%2F0%2AeyvyNMoVaVmSDNj_.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2676%2F0%2AeyvyNMoVaVmSDNj_.png" width="800" height="923"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Minimized browser windows showing white spacing and less content in the viewport.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3998%2F0%2Aly6OpgVdnUHPkboT.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3998%2F0%2Aly6OpgVdnUHPkboT.png" width="800" height="429"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Maximized browser windows showing less white spacing and more content in the viewport.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to maximize browser in Selenium Ruby with code examples?
&lt;/h2&gt;

&lt;p&gt;In this section of this blog on how to maximize browser in Selenium Ruby, we will learn about the prerequisites and see the implementation with code examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-requisites
&lt;/h2&gt;

&lt;p&gt;Here are some prerequisites before we see how to maximize browser in Selenium Ruby on the cloud.&lt;/p&gt;

&lt;h3&gt;
  
  
  IDE
&lt;/h3&gt;

&lt;p&gt;We will be using Visual Studio Code, but you could use the IDE of your choice. Other popular Text editors include RubyMine, Sublime, Atom, etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  Selenium Cloud Grid
&lt;/h3&gt;

&lt;p&gt;Selenium cloud grid is a hosted &lt;a href="https://www.lambdatest.com/blog/selenium-ruby/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Grid&lt;/a&gt; solution. This system provides an easy way to run your tests on multiple platforms without running all browsers on your desktop.&lt;/p&gt;

&lt;p&gt;It allows you to perform &lt;a href="https://www.lambdatest.com/blog/what-is-parallel-testing-and-why-to-adopt-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing&lt;/a&gt; distributed over multiple cloud providers. If you have a team of testers running &lt;a href="https://www.lambdatest.com/selenium-ide-cloud?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium IDE tests&lt;/a&gt; for multiple projects, you can now utilize the cloud to scale up your testing capacity. You can also speed up your development cycle by running the same test against different environments with different browsers. For this blog on how to maximize browser in Selenium Ruby, we will run our test on LambdaTest’s &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cloud Selenium Grid&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Cloud-based &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cross browser testing &lt;/a&gt;platforms like LambdaTest provide you with an &lt;a href="https://www.lambdatest.com/online-browser-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;online browser farm&lt;/a&gt; of 3000+ browsers and operating systems to perform &lt;a href="https://www.lambdatest.com/blog/selenium-ruby/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Ruby automation testing&lt;/a&gt; at scale. Here’s a glimpse of LambdaTest grid for &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium automation&lt;/a&gt; testing.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/WZlsHlReRww"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can also subscribe to the LambdaTest YouTube Channel and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress E2E testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;p&gt;In order to maximize browser in Selenium Ruby on the cloud grid, we would need to define capabilities and replace our driver with a remote webdriver by having a cloud grid remote webdriver configured.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;We will write our tests, and instead of using the local &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt;, we will directly use the Selenium Cloud Grid to maximize browser in Selenium Ruby and view the test result on the dashboard.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require 'selenium-webdriver'
require 'test-unit'

class BrowserWindowTests &amp;lt; Test::Unit::TestCase
 def setup
   username = "#{ENV['LAMBDATEST_USERNAME']}"
   access_token = "#{ENV['LAMBDATEST_ACCESS_KEY']}"
   grid_url = "hub.lambdatest.com/wd/hub"

   capabilities = {
     'LT:Options' =&amp;gt; {
       "user" =&amp;gt; username,
       "accessKey" =&amp;gt; access_token,
       "build" =&amp;gt; "Browser Maximizing Test v.1",
       "name" =&amp;gt; "Browser Maximizing Tests",
       "platformName" =&amp;gt; "Windows 11"
     },
     "browserName" =&amp;gt; "Firefox",
     "browserVersion" =&amp;gt; "100.0",
   }


   @my_driver = Selenium::WebDriver.for(:remote,
                                        :url =&amp;gt; "https://"+username+":"+access_token+"@"+grid_url,
                                        :capabilities =&amp;gt; capabilities)


   @url = "https://ecommerce-playground.lambdatest.io/"

   #get url
   @my_driver.get(@url)
   @wait = Selenium::WebDriver::Wait.new(:timeout =&amp;gt; 30)
 end

 def test_page_resizing
   # Assert that title is loaded
   @wait.until { @my_driver.title.include? "Your Store" }
   sleep(2)

   # We maximize the window to occupy the full page
   @my_driver.manage.window.maximize

   # Here we minimize the browser window to the taskbar
   @my_driver.manage.window.minimize
   sleep(2)

   # Here we resize the browser window to a width and height of 500(width) by 1000(height)
   @my_driver.manage.window.resize_to(500, 1000)
   sleep(2)

   # We maximize the browser window again to occupy the full page
   @my_driver.manage.window.maximize

   # Here we resize the browser window to a width and height that's bigger than a normal screen size
   @my_driver.manage.window.resize_to(6000, 6000)
   sleep(2)


 end

 def teardown
   @my_driver.quit
 end

end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Remember to replace your &lt;strong&gt;LAMBDATEST_USERNAME&lt;/strong&gt; and &lt;strong&gt;LAMBDATEST_ACCESS_KEY&lt;/strong&gt; with the ones you obtained after signing up on LambdaTest. You can get these details from the &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=login" rel="noopener noreferrer"&gt;LambdaTest Profile Section&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Export your variables to your environment:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Linux/macOS:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export LAMDATEST_USERNAME="YOUR_USERNAME"
export LAMDATEST_ACCESS_KEY="YOUR ACCESS KEY"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;For Windows:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;set LT_USERNAME="YOUR_USERNAME"
set LT_ACCESS_KEY="YOUR ACCESS KEY"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: &lt;a href="https://www.lambdatest.com/learning-hub/system-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;System Testing&lt;/a&gt; Tutorial- A Comprehensive Guide With Examples and Best Practices&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Code Walkthrough
&lt;/h2&gt;

&lt;p&gt;The manage() method gives us an instance of browser menu methods from the Selenium WebDriver that we will use to control our browser window.&lt;/p&gt;

&lt;p&gt;After the browser loads, we use the Selenium maximize method to maximize the browser window, as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A5QS3etLGakRjCkRG.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A5QS3etLGakRjCkRG.png" width="800" height="195"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To minimize the browser, we call the minimize method, and on running the test, the browser will be minimized and hidden from view.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A1uzA-QBT7ALNX_1m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A1uzA-QBT7ALNX_1m.png" width="800" height="180"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we want to resize the browser window, we will call the &lt;strong&gt;resize_to&lt;/strong&gt; method with the width and height of our browser. The height and width values that we specify in the arguments are then used by the **resize_to **method to change our browser window to a different size when resizing is required. The first argument is the width, and the second is the height of the browser window.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2828%2F0%2A8SlaouYGm_LsWEQs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2828%2F0%2A8SlaouYGm_LsWEQs.png" width="800" height="117"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Calling maximizes on the browser instance will resize it to its full size that occupies the entire width and height.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2076%2F0%2Agdr9ROnFQQBtA7DF.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2076%2F0%2Agdr9ROnFQQBtA7DF.png" width="800" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What happens if we resize a browser to a larger height and width than our actual screen size?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To demonstrate this, let us resize the height to 6000px and the width to 6000px. Run the test, and you will notice that the browser window will adjust the height and width to the maximum size without showing any warning.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3116%2F0%2ALkAuyog_CHe8paS7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3116%2F0%2ALkAuyog_CHe8paS7.png" width="800" height="125"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Determining the current size of your browser window&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To determine the current height and width of your browser window in Selenium Ruby, you could use the following method.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;puts @my_driver.manage.window.size
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This would give you results similar to the below, which shows the width and height at the time that method ran. This can be useful in cases where you want to ensure that you are resizing your browser window to a certain size before running a full-screen test.&lt;/p&gt;

&lt;p&gt;For some browsers — In cases where you try to resize your browser window while running a test and it doesn’t work, ensure that you are using appropriate values in the &lt;strong&gt;resize_to&lt;/strong&gt; method.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2868%2F0%2AXXlgfUdC4HUIY-uJ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2868%2F0%2AXXlgfUdC4HUIY-uJ.png" width="800" height="172"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Checking our tests on LambdaTest&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Login to LambdaTest to access the &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=login" rel="noopener noreferrer"&gt;LambdaTest Dashboard&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check on the Automate tab for your test run.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You should see results similar to the screenshot below, indicating that your tests have run successfully. You have the option to watch the video to see how your test ran. In addition, you have a list showing the execution steps during the test process on the right-hand side pane.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F0%2AEcGzYTLHkq-enyjm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F0%2AEcGzYTLHkq-enyjm.png" width="800" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Checking Analytics on LambdaTest&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To view the test overview and get a summary of all the tests recorded on LambdaTest, click &lt;strong&gt;Automation &amp;gt; Analytics&lt;/strong&gt; on the left side menu. The &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=login" rel="noopener noreferrer"&gt;LambdaTest Analytics Dashboard&lt;/a&gt; will provide a summary of all builds and test runs that you have submitted.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F0%2AGzDFtEf_mgLEoZ6O.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F0%2AGzDFtEf_mgLEoZ6O.png" width="800" height="581"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will see results similar to the below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F0%2A7fLg32l1rV3yLrrL.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F0%2A7fLg32l1rV3yLrrL.png" width="800" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For any developer or tester looking to start, or advance their career in the technology industry, then you need to look no further. This Selenium Ruby 101 certification will set you apart from the rest of your peers and get you an edge at any job.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A7Yd_BhwgPPvElp_5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A7Yd_BhwgPPvElp_5.png" width="800" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the Selenium Ruby 101 certification from LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/u9vyiYL0I0M"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: &lt;a href="https://www.lambdatest.com/learning-hub/black-box-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec02_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Blackbox Testing&lt;/a&gt; Tutorial - A Comprehensive Guide With Examples and Best Practices&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Having the convenience to modify a browser size to the size that suits your testing needs is crucial to accurately test your application for the real world since it allows you to test your application in its entirety.&lt;/p&gt;

&lt;p&gt;Most of the time, using a browser with a width and height of 500px or less will allow you to see what is being shown on the page on smaller screens. This can help you understand how our web application will look at scale — especially on mobile devices.&lt;/p&gt;

&lt;p&gt;You can resize, minimize, or even maximize browser in Selenium Ruby using different methods while testing. This ensures that your application will function properly or even give you insights into what the application will look like on various browser sizes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AmUs2VJm1Kg77UoDc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AmUs2VJm1Kg77UoDc.png" width="800" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>testing</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How To Implement Data Tables In Cucumber Using Selenium Ruby</title>
      <dc:creator>Roselyne Makena</dc:creator>
      <pubDate>Thu, 01 Dec 2022 14:24:42 +0000</pubDate>
      <link>https://dev.to/testmuai/how-to-implement-data-tables-in-cucumber-using-selenium-ruby-1168</link>
      <guid>https://dev.to/testmuai/how-to-implement-data-tables-in-cucumber-using-selenium-ruby-1168</guid>
      <description>&lt;p&gt;Data tables can be used when you have data in a range of cells and want to iterate over the cells in order. Data tables generally have a header row that includes column headers and then rows of data.&lt;/p&gt;

&lt;p&gt;There are many reasons to use a data table when testing.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Data tables make it easier to see how the calculation is structured for each cell.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Data tables significantly reduce repetition by storing the data that will be used repeatedly in only one place.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This &lt;a href="https://www.lambdatest.com/learning-hub/selenium-cucumber?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Cucumber Selenium tutorial&lt;/a&gt; is about implementing data tables in Cucumber using Ruby as the scripting language. The Ruby language encourages the use of &lt;a href="https://www.lambdatest.com/blog/behaviour-driven-development-by-selenium-testing-with-gherkin/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Behavior Driven Development (BDD)&lt;/a&gt;, a form of Test Driven Development (TDD) that encourages collaboration between developers and non-developers, such as product owners.&lt;/p&gt;

&lt;p&gt;Using Selenium Ruby, you can write tests before the code is tested, and then you write the code from the point at which the tests fail. Using a simple example, I’ll show you how to create data tables in Cucumber while performing &lt;a href="https://www.lambdatest.com/ruby-automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Ruby automation testing&lt;/a&gt; and run the tests to ensure that our tests pass as expected.&lt;/p&gt;

&lt;p&gt;So, let’s get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of Behavior Driven Development
&lt;/h2&gt;

&lt;p&gt;Before we deep dive into the essentials of Cucumber, let us recap the major advantages of Behavior Driven Development. The learnings from it will set the context for data tables in Cucumber Ruby — this blog’s primary focal point.&lt;/p&gt;

&lt;p&gt;Major advantages of BDD are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Behaviour Driven Development (BDD) makes it easy to write acceptance tests. These tests will be more readable and look more like a natural language document, making them easier to share with business stakeholders.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The BDD approach forces you to consider how your application might be used before you start writing any code. This gives you a better understanding of your domain and leads to better-designed software.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It reduces the need for lots of integration testing because many of the requirements have already been tested during the development process by writing automated acceptance tests using Cucumber.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Writing your scenarios using a standard format means you can run them across different development tools, and they’ll all work the same way.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Agile teams can benefit from Cucumber because running your scenarios will give you early feedback on whether you’re building the right software or need to change track and deliver something different. This can be invaluable in an iterative development process where small changes are made frequently.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Maintaining and expanding your system is easier because other team members can understand how it works by reading acceptance tests written at the start of the project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Failure to write your Cucumber tests correctly is a common problem, but it’s easy to spot because they look like natural language. You’ll always know what needs to be changed or added to improve the quality of your tests.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is Cucumber?
&lt;/h2&gt;

&lt;p&gt;Cucumber is used in many languages, including Java, Python, and Ruby. It is very popular with frameworks because it is easy to test methods with assertions covering most use cases.&lt;/p&gt;

&lt;p&gt;It is a popular tool for running automated acceptance tests. In short, you create a plain text file (Feature file) that contains descriptions of the scenarios (i.e., different ways a user might interact with your application). You could run Cucumber using Ruby to execute the scenarios and generate a concise report of whether each scenario passes or fails.&lt;/p&gt;

&lt;p&gt;Cucumber embraces Behavior Driven Development, which means you write your scenarios in a natural language, speaking to the application as a user would. Cucumber utilizes Gherkin — a lightweight programming language that looks like English.&lt;/p&gt;

&lt;p&gt;Gherkin is a Domain Specific Language (DSL), meaning that you have different keywords for different steps in your scenarios compared to standard programming languages such as Ruby, Python, and Java.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AFyVhznThZwHH1FvI.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AFyVhznThZwHH1FvI.png" width="800" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Cucumber support for other frameworks and tools
&lt;/h2&gt;

&lt;p&gt;Most Cucumber users use it with Ruby, but it can also be used to test applications written in other languages. For example, you could write your scenarios using JavaScript as a scripting language, and your steps could interact with a web browser rather than a web application.&lt;/p&gt;

&lt;p&gt;Cucumber provides support for Capybara in the form of a Capybara driver. Once installed in your test suite, Capybara will launch a browser window before each scenario and navigate to the specified URL and the text in the title bar.&lt;/p&gt;

&lt;p&gt;Cucumber also supports Ruby on Rails (ROR), Watir, and Spring framework, among others.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cucumber syntax
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt; — A feature in the software world is generally a small section of functionality you would like to test. In Cucumber terminology, a feature is an expectation that must be true to pass any scenario. For instance, imagine you want to test if a user can log in with a username and password combination. I will refer to this as the scenario “User can log in”.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scenarios&lt;/strong&gt; — A scenario is how the features are connected. A scenario generally describes what the user should do next, or in other words, what behavior your application should have during that particular flow step. This way, users can see if they have done everything they need and if they still need to proceed forward.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Description&lt;/strong&gt; — The description is a narrative description of the behavior that the user should have. It should be written in a natural language and not repeat any information contained in the feature or step definitions. Let’s say a scenario is “User can login”. The description for this scenario will be “The user should see a screen where he can enter his username, and then see another screen where he can enter his password.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Given&lt;/strong&gt; — This is a statement that states what the system should be like at the time of running this scenario (pre-requisites). This allows us to describe the state of reality we need to have for our application to work as expected and pass any subsequent test scenarios. In other words, if no errors are occurring, then we should be able to proceed to the next steps indicating that everything is working as expected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;When&lt;/strong&gt; — this is an “if” statement stating what you want the application to do when you run your scenario. Let’s say if a scenario is “User can log in”, then we would write, “When one or more users try to log in they should see a page outlining what they need to do next.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;And&lt;/strong&gt; — the “and” is the “and then” statement which connects the steps together. It’s like an “if-then” statement, but with two conditions instead of just one. In Cucumber, you write one at the end of every step as it marks the beginning of a new scenario.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Then&lt;/strong&gt; — this part is where we check whether our application did what we expected it to do when running our scenario. The Cucumber framework will automatically check that all your “then” steps are true before continuing to the next step in your scenario&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Steps definitions&lt;/strong&gt; — these are the steps where you specify what should happen in each scenario. They are written in Ruby, and you must specify what the application should do when you run a specific step.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cucumber hooks&lt;/strong&gt; — hooks are a particular type of &lt;a href="https://www.lambdatest.com/blog/cucumber-annotations-hooks-tutorial/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cucumber annotation&lt;/a&gt; that allows you to use specific code in your steps that you may have written elsewhere. This helps to avoid repetition and errors in your code.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some examples of Cucumber hooks are :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Before hook: runs before every scenario.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After hook: runs after every scenario.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Setup hook: runs before any scenario.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Teardown hook: runs after any scenario.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Step definition hook: runs when the step is about to be executed or has just been executed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s important to note that we can have tagged hooks — Which are used for step definition hooks.&lt;/p&gt;

&lt;p&gt;The Cucumber Ruby gem comes with a few additional pieces of functionality that are not related to the Cucumber framework itself. Pieces of functionality such as report generation, database-driven steps, and database-driven reporting are all built into the cucumber gem.&lt;/p&gt;

&lt;p&gt;While I’m not going to be covering any of these as it is outside of the scope of this blog on data tables in Cucumber, it is something that you may want to look into if your system has a lot of complicated interactions and requirements for every scenario you have defined.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to run Cucumber?
&lt;/h2&gt;

&lt;p&gt;Here are some ways to run Cucumber:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The first is using a &lt;strong&gt;&lt;em&gt;DSL (Domain Specific Language)&lt;/em&gt;&lt;/strong&gt;. A DSL is a programming language that you write yourself to create the equivalent of English descriptions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The second way is using the &lt;strong&gt;&lt;em&gt;built-in Rails features&lt;/em&gt;&lt;/strong&gt;, which might be easier for certain programmers to implement if they’re unfamiliar with writing DSLs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Thirdly, we can also use &lt;strong&gt;&lt;em&gt;actual Ruby code&lt;/em&gt;&lt;/strong&gt; (which is probably more common) — and this is how we will use it to run our tests.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Having gone through the basic functionality of Cucumber syntax, let’s look at data tables in Cucumber.&lt;/p&gt;

&lt;p&gt;For developers or testers looking to elevate their skills, you need to look no further. This Selenium Ruby 101 certification can get you in the door at any organization and ready to climb your way to the top.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Aaa2kh9QaZE9kNmto.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Aaa2kh9QaZE9kNmto.png" width="800" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the Selenium Ruby 101 certification from LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/u9vyiYL0I0M"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: How To Debug Websites Using &lt;a href="https://www.lambdatest.com/blog/debug-websites-using-safari-developer-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;dev tools in Safari&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What are data tables in Cucumber?
&lt;/h2&gt;

&lt;p&gt;A data table (or data matrix) is a special type of table that allows us to compare a set of numerical values simultaneously easily. It’s great for displaying data that you would like people to understand at a glance.&lt;/p&gt;

&lt;p&gt;Data tables are most useful when working with data that is numerical. Data tables can be found in almost every business, from insurance to airlines.&lt;/p&gt;

&lt;p&gt;They are used for displaying numbers and statistics. Still, they can also be used as a simple way of providing information about a range of choices and doing multiple tests for a particular scenario, as we will use today.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing data tables in Cucumber
&lt;/h2&gt;

&lt;p&gt;To implement a data table in Cucumber, you need to create one or more files named after your feature. Let’s look at the breakdown below to understand this.&lt;/p&gt;

&lt;p&gt;To create a data table, you first need to create a file named after your feature containing your scenario. Then you add some text starting with “Given” to describe the data that the system should have before your schemas (in this case, a table) is displayed.&lt;/p&gt;

&lt;p&gt;Let’s look at a coding example to help us understand data tables in Cucumber better.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: &lt;a href="https://www.lambdatest.com/blog/emulator-vs-simulator-vs-real-device/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Emulator vs Simulator&lt;/a&gt; vs Real Device Testing - Key Differences&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to implement data tables in Cucumber using Ruby?
&lt;/h2&gt;

&lt;p&gt;We will be testing that different users can log in successfully to our test website and use data tables in Cucumber to make it easy to track our results. The data table structure will help us write the test case once and then re-use it with sample data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites for implementing data tables in Cucumber
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Ruby&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Make sure you have Ruby installed on your system. To confirm the version of Ruby you are running, type the below command in your terminal.&lt;/p&gt;

&lt;p&gt;ruby -v&lt;/p&gt;

&lt;p&gt;To learn more about installing Ruby, you can go through my earlier blog on Selenium automation testing with Ruby. You should see results below, based on the version of Ruby you have on your system.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A3hM8zEpnToCnolmo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A3hM8zEpnToCnolmo.png" width="800" height="187"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Cucumber and Watir gem&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To run Cucumber tests, we must install the gem cucumber, and we do this by running the below commands on your terminal:&lt;/p&gt;

&lt;p&gt;gem install cucumber&lt;br&gt;
gem install watir&lt;/p&gt;

&lt;p&gt;You would expect a successful installation, which you can confirm by using the list command below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A4PlwCDEygVQYriqV.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A4PlwCDEygVQYriqV.jpg" width="668" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: &lt;em&gt;For watir — you need watir, and you do not need to have watir-webdriver listed.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AmWnKFNhhTmpnV6ml.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AmWnKFNhhTmpnV6ml.jpg" width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When writing this blog, the latest version of Cucumber was 8.0.0. This version might vary based on the latest version of Cucumber available then.&lt;/p&gt;
&lt;h2&gt;
  
  
  Implementing Cucumber data tables
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Let’s start by creating the Cucumber folders necessary for this project. Navigate to the folder where you will run your tests and run the following in your terminal.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;cucumber — init&lt;/p&gt;

&lt;p&gt;We expect to see a couple of folders created that are similar to the ones below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2004%2F0%2Aw7kIuJcVipJ3z8SJ.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2004%2F0%2Aw7kIuJcVipJ3z8SJ.jpg" width="800" height="198"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2- To successfully run our tests, we will create four files. We shall go through each one in detail afterward.&lt;/p&gt;

&lt;p&gt;3- First, let’s create a features_files directory. To do this, type the following into your terminal.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir features_files
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;4- Inside the features_files folder, create a file called the login_tests.feature. We can then type in the code below.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#/features_files/login_tests.rb
Feature: Ecommerce login Feature
 Scenario: Verify ecommerce webpage loads and user can sign in
   Given Ecommerce webpage Login Page loads
   And Ecommerce Login Link is present loaded
   Then Correct Username and Password Should Login Successfully &amp;lt;username&amp;gt; &amp;lt;password&amp;gt;
   And My Account page should display after login
 Examples:
   | username                       | password      |
   | kankanaadds@gmail.com          | LambdaTest123 |
   | swapnilbiswas012@gmail.com     | LambdaTest123 |
   | himanshi.jainn@rediffmail.com  | LambdaTest123 |
   | saumya.saran01@gmail.com       | LambdaTest123 |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Then create another directory inside features called page_object, create a file called &lt;em&gt;login_page.rb.&lt;/em&gt; This will be where we shall write our page object functions and use them in our tests. To learn more about Page Object Model, go through our earlier blog on &lt;a href="https://www.lambdatest.com/blog/page-object-model-tutorial-selenium-csharp/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Page Object Model in Selenium&lt;/a&gt;.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#/page_object/login_page.rb
class LoginPage
 def username_link
   $browser.link(text: "Forgotten Password")
 end

 def username_textbox
   $browser.input(id: "input-email")
 end

 def password_textbox
   $browser.input(id: "input-password")
 end

 def login_button
   $browser.button(value: "Login")
 end

 def account_header
   $browser.link(text: "Edit Account")
 end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Run your Cucumber test scripts across 3000+ real browsers and OS. &lt;a href="https://accounts.lambdatest.com/register?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=register" rel="noopener noreferrer"&gt;Try LambdaTest Now!&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What are Page Objects in Cucumber?
&lt;/h2&gt;

&lt;p&gt;Page objects are a way of creating test objects specific to your application. In Cucumber, they are used to create and manage page objects so that we can interact with third-party code and databases.&lt;/p&gt;

&lt;p&gt;They come in handy when the object you’re writing must not be directly dependent on Rails’ usual classes, models, or collection structures.&lt;/p&gt;

&lt;p&gt;Think of page objects as ‘functions’ for creating object instances — except they don’t just create objects based on classes or named collections — they instead create instances based on whatever values you input them in the text you supply them with.&lt;/p&gt;
&lt;h2&gt;
  
  
  When do you use page objects?
&lt;/h2&gt;

&lt;p&gt;The page object is the simplest way to separate locators from the rest of the application. A new class can easily be added to a page object that concentrates all locators used on that page. Therefore, it is best to separate these locators so they do not interfere with testing. To learn more about locators, go through our earlier article on &lt;a href="https://www.lambdatest.com/blog/locators-in-selenium-webdriver-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;locators in Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the next section of this article on implementing data tables in Cucumber, we will look at some of the benefits of using page objects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: Online &lt;a href="https://www.lambdatest.com/safari-browser-for-windows?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Safari Browser Testing For Windows&lt;/a&gt; - Say No To Safari VM! Perform Cross Browser Compatibility Testing On All Safari Browser Versions Across Real Browsers And Operating Systems.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What are the benefits of using page objects?
&lt;/h2&gt;

&lt;p&gt;Using page objects helps us separate locators from functional code by defining them as properties on a ‘page object’ class definition.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Ability to define locators on multiple user interface pages without duplicating locator definitions or coding.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Immediate integration with existing &lt;a href="https://www.lambdatest.com/blog/best-test-automation-frameworks-2021/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation frameworks&lt;/a&gt; with minimum code changes required by the automation team.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Elimination of the need for test automation frameworks to support session-level locators when viewing multiple pages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The ability to specify a relative path for each page object.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When creating a page object, it is generally required to define properties that describe the page containing the page object.&lt;/p&gt;

&lt;p&gt;It’s important to note that we do not have to link each locator’s definition of a test automation framework with each page object. During testing, the recommended approach for an automation team is to reference a single class definition file rather than hundreds of locator definitions in each test script or have separate locator definitions grouped in a specific order and valid naming conventions. This makes it easier to find a page object.&lt;/p&gt;

&lt;p&gt;For the third file, we shall create a file under step_definitions(a folder that already exists) and create a file called ecommerce_steps.rb.&lt;/p&gt;

&lt;p&gt;Here, we will have all our step definitions for our Cucumber test. For example, we will have a function for navigating to the login page that we will use in the login scenario.&lt;/p&gt;

&lt;p&gt;When creating a page object, it is generally required to define properties that describe the page containing the page object.&lt;/p&gt;

&lt;p&gt;It’s important to note that we do not have to link each locator’s definition of a test automation framework with each page object. During testing, the recommended approach for an automation team is to reference a single class definition file rather than hundreds of locator definitions in each test script or have separate locator definitions grouped in a specific order and valid naming conventions. This makes it easier to find a page object.&lt;/p&gt;

&lt;p&gt;For the third file, we shall create a file under step_definitions(a folder that already exists) and create a file called ecommerce_steps.rb.&lt;/p&gt;

&lt;p&gt;Here, we will have all our step definitions for our Cucumber test. For example, we will have a function for navigating to the login page that we will use in the login scenario.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#/step_definistions/ecommerce_steps.rb
Given(/^Ecommerce webpage Login Page loads$/) do
 $browser.goto "https://ecommerce-playground.lambdatest.io/index.php?route=account/login"
 $user_session = LoginPage.new
end

Then(/^Ecommerce Login Link is present loaded$/) do
 assert($user_session.username_textbox.name, "email")
 assert($user_session.password_textbox.name, "password")
end

Then(/^Correct Username and Password Should Login Successfully (.*) (.*)$/) do |username, password|
 puts "------"
 puts username
 $user_session.username_textbox.send_keys(username)
 sleep(3)
 $user_session.password_textbox.send_keys(password)
 sleep(3)
 $user_session.login_button.click
end

And(/^My Account page should display after login$/) do
 assert($user_session.account_header.name, "My Account")
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Lastly, we will edit our env.rb file, which is under the support to have the following details.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#/support/env.rb
require 'rubygems'
require 'watir'

Before do |scenario|
 $browser = Watir::Browser.new :firefox
 $browser.driver.manage.window.maximize
end

After do |scenario|
 $browser.close
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: Most Comprehensive &lt;a href="https://www.lambdatest.com/blog/selenium-ide-what-is-it-why-is-it-must-for-every-qa/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium IDE&lt;/a&gt; Tutorial&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is Watir?
&lt;/h2&gt;

&lt;p&gt;Watir is an abbreviation that stands for &lt;a href="https://www.lambdatest.com/web-application-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Web Application Testing&lt;/a&gt; In Ruby. It is a much-improved descendant of WebInspector. It’s written in Ruby and provides the same functionality for testing web applications. It has a test runner called Watir-webdriver and a page object for the browser interface.&lt;/p&gt;

&lt;p&gt;Watir is packaged in a Ruby gem. It comprises a set of Ruby scripts that relate to the Browser Object Model (BOM). The BOM is the JavaScript API used by the web browser to interact with a web application.&lt;/p&gt;

&lt;p&gt;After copying the files we discussed above, you should have an output similar to the one below — and you can confirm by using the ls command to list the content of a given directory (in this case, the tables directory). From our IDE, we should see the following.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A8QtUJzzf-q92d1Hs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A8QtUJzzf-q92d1Hs.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s take a deeper look at the different files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Filename: features_files/login_tests.rb&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2796%2F0%2A7sGk1J4Xw7jpGpyA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2796%2F0%2A7sGk1J4Xw7jpGpyA.png" width="800" height="345"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This file defines a Scenario and has a name in the format of Given, When, and Then. Given is where we define our scenario, when is where we specify the step definitions for the scenario, and then is where we can write the assertions for that step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Every feature has at least one scenario.&lt;/strong&gt; A scenario describes a specific event that should happen to fulfil one or more business requirements in your application.&lt;/p&gt;

&lt;p&gt;A scenario follows a pattern of steps and context described in user interaction with the system, e.g., verifying a user can log in to a particular web page.&lt;/p&gt;

&lt;p&gt;Note that the example at the end gives access to a data table that provides different usernames and passwords for the test. Data tables in Cucumber are kept around so that the same scenario can be repeated with different data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Filename: page_object/login_page.rb&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Az7BOB-16BIcSjNT6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Az7BOB-16BIcSjNT6.png" width="800" height="921"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The page object is responsible for creating the objects that your scenario needs to interact with. The object that the page object creates is instantiated when you run the scenario. This is an instance of a page object, which provides a given page. In this case, it’s our login page.&lt;/p&gt;

&lt;p&gt;The page object is usually defined for you as part of Cucumber, but there are some cases where you need to customize the object or create your own. You can define just about any CRUD, static or dynamic web page in Ruby as your real-world implementation by working with the methods in your Page object.&lt;/p&gt;

&lt;p&gt;For example, if we want to specify the user’s name when we log in and then check that data, we can add those variables to our env.rb file and pass them into our step definitions as needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Filename: step_definistions/ecommerce_steps.rb&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3172%2F0%2ArP24Rq0cCgF6we5t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3172%2F0%2ArP24Rq0cCgF6we5t.png" width="800" height="486"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These are the step definitions that show the real meat of your scenario! This is where we define our step definitions, which are executed one after the other and at the end. We have an assertion that verifies whether the expected outcome happened or not.&lt;/p&gt;

&lt;p&gt;We can then add variables to our step definition file in Ruby and pass those variables from our data table to our scenario. This is how we can check for particular values when a page loads or clicks a button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Filename: support/env.rb&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AW2sGNCXEsinn73S3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AW2sGNCXEsinn73S3.png" width="734" height="604"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we mentioned earlier, the env.rb file usually contains general information that can be reused across the different steps of your test or used across multiple features in the same project. In our case, we have included Cucumber hooks such as Before and After.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Before&lt;/strong&gt; method here will run once before each scenario and will simply create a browser session and maximize the browser.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;After&lt;/strong&gt; method will quit the browser after each scenario has run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Execution:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To run the test, we need to open our terminal at the root of the folder where we created the Cucumber file and run the following command.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cucumber
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This just runs all the feature files, but if you need to specify which one you want to test, you can run the following from your terminal.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cucumber features/features_files/login_tests.feature
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;That’s it! We have successfully written and run a feature using cucumber. Let’s take a closer look at some of the files we created in our Cucumber project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What happens if the test fails?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You must open your terminal and change some values in your login_tests.feature file if an error occurs. You could do this by changing the username or password.&lt;/p&gt;

&lt;p&gt;We will see error messages on the console log when running the tests.&lt;/p&gt;

&lt;p&gt;The error messages displayed are very helpful for debugging or understanding what the test is getting wrong. As you can see, they display a specific line number that failed and then gives you a message about what exactly failed.&lt;/p&gt;

&lt;p&gt;The great thing with data tables in Cucumber is that other tests continue to run even if there is a failing test. This means that it will not give you false results when there is an error, and you can always debug the problem by changing some values in an invalid way and see the test result.&lt;/p&gt;

&lt;p&gt;You’ll notice that when there are multiple tests, Cucumber will display all of them and give a summary of failed or passed tests along with the steps taken.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AmiRgBY9rgoWfQGcK.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AmiRgBY9rgoWfQGcK.png" width="734" height="604"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By now, you should better understand how Cucumber works and how it helps you write your tests for your application’s business logic code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now let’s run our feature files and ensure everything works as expected.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the folders created, it’s important to note that the env.rb file under the support folder runs first when the test begins, and then the files in the step_definitions follow.&lt;/p&gt;

&lt;p&gt;env.rb contains configurations for your system, e.g., database connections, etc. This is where we define all our data tables in Cucumber, and we’ll create one for every feature. In more complex testing where you would need to add database connection parameters, you would add them in this file.&lt;/p&gt;

&lt;p&gt;Every time you run Cucumber, it will check if the env.rb file is present; if not, it will generate one for you with all the necessary values required to execute your test.&lt;/p&gt;

&lt;p&gt;After running the tests, we should get the following information in our terminal. As you can see, all the four scenarios from the data tables in Cucumber ran subsequently.&lt;/p&gt;

&lt;p&gt;You should expect to see something similar to the below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F0%2A-B63cHi8nJZM75Np.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F0%2A-B63cHi8nJZM75Np.png" width="800" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we run the tests, it does a pre-pass first, executes the test, and finally prints out the results.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to implement data tables in Cucumber on cloud grid?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/selenium-grid-setup-tutorial/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Grid&lt;/a&gt; is a tool for distributing the load across multiple browsers. Selenium Grid can be used to run tests on different operating systems and browser configurations simultaneously. The grid configuration will control which browsers run the tests and how many of them at a time.&lt;/p&gt;

&lt;p&gt;To run this on the cloud grid like LambdaTest, you would need to replace the local webdriver with the &lt;a href="https://www.lambdatest.com/blog/selenium-remotewebdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;remote webdriver.&lt;/a&gt; Cloud-based &lt;a href="https://www.lambdatest.com/online-browser-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platforms like LambdaTest provide you with an &lt;a href="https://www.lambdatest.com/online-browser-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;online browser farm &lt;/a&gt;of 3000+ browsers and operating systems to perform Selenium Ruby testing at scale. Here’s a glimpse of LambdaTest &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;online Selenium Grid:&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/WZlsHlReRww"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: Automated &lt;a href="https://www.lambdatest.com/blog/automated-functional-testing-what-it-is-how-it-helps/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Functional Testing-&lt;/a&gt; What it is &amp;amp; How it Helps?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can also subscribe to the LambdaTest YouTube Channel and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress E2E testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;p&gt;Replace the following code on the file&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/support/env.rb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;On local Selenium Grid:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#/support/env.rb
require 'rubygems'
require 'watir'

Before do |scenario|
 browser = Watir::Browser.new :firefox
 $browser = browser
 $browser.driver.manage.window.maximize
end
After do |scenario|
 $browser.close 
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;On cloud Selenium Grid:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#/support/env.rb
require 'rubygems'
require 'watir'

Before do |scenario|
 username= "#{LAMBDATEST_USERNAME}"
 accessToken= "#{LAMBDATEST_ACCESS_KEY}"
 gridUrl = "hub.lambdatest.com/wd/hub"

 capabilities = Selenium::WebDriver::Remote::Capabilities.new

 capabilities['platform'] = 'Windows 11'
 capabilities['name'] = 'Cucumber Login Tests'
 capabilities['build'] = 'Cucumber Test v.1'
 capabilities['browserName'] = 'Firefox'
 capabilities['browserVersion'] = '100.0'

 $browser = Watir::Browser.new(
   :remote,
   :url =&amp;gt; "https://"+username+":"+accessToken+"@"+gridUrl, :desired_capabilities=&amp;gt;capabilities)

 $browser.driver.manage.window.maximize
end

After do |scenario|
 $browser.close
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Remember to export your Username and Access Key in environment variables via your terminal with the commands below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Linux/macOS:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;export LAMDATEST_USERNAME="YOUR_USERNAME"&lt;br&gt;
export LAMDATEST_ACCESS_KEY="YOUR ACCESS KEY"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Windows:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;set LT_USERNAME="YOUR_USERNAME"&lt;br&gt;
set LT_ACCESS_KEY="YOUR ACCESS KEY"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Checking results on LambdaTest:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You should see the tests fire up on the &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=login" rel="noopener noreferrer"&gt;Automation Dashboard&lt;/a&gt; and the results displayed on the right as shown.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F0%2A8cRMqp4JJdvHoTqB.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F0%2A8cRMqp4JJdvHoTqB.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will notice that the number of rows on the data tables is equivalent to the number of tests that are run, which is precisely what we expect, and this also highlights why data tables in Cucumber are essential.&lt;/p&gt;

&lt;p&gt;You can view your test results and overall performance on the &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=login" rel="noopener noreferrer"&gt;LambdaTest Analytics Dashboard&lt;/a&gt;. From the Test Summary section, you can easily see which tests failed and which passed, as well as how many. You can also navigate to the Test Overview page, where you can see a breakdown of all test runs, including individual test performance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AHvPBhpjIxDvvaGJH.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AHvPBhpjIxDvvaGJH.gif" width="600" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cut down test execution by more than 10X. &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=login" rel="noopener noreferrer"&gt;Try LambdaTest Now!&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  More debugging tips while implementing data tables in Cucumber
&lt;/h2&gt;

&lt;p&gt;If you are getting errors on Cucumber and want to know where the error exactly is happening, then we need to take one step back. Even though Cucumber tries to create a test for all your features, it doesn’t always do so due to duplicate scenarios or missing data tables in Cucumber.&lt;/p&gt;

&lt;p&gt;To fix this, you need to navigate the tests and change the test itself. If you still have issues, you can dive deeper into your code using a debugger.&lt;/p&gt;

&lt;p&gt;A debugger is a tool that allows you to step into your code, change things like variables and rerun the same scenario. The debugger enables you to see what’s happening as you run your tests step by step.&lt;/p&gt;

&lt;p&gt;Once we have what is causing the error, we can look at the failing scenarios and fix them. Remember that some features might not work in a certain environment or browser. So what works for me might not work for you. So don’t be afraid to change these scenarios and add more complex ones.&lt;/p&gt;

&lt;p&gt;We can use a gem called Ruby-debugger that gives us the lines in our code that are failing by following these steps.&lt;/p&gt;

&lt;p&gt;Try &lt;a href="https://www.lambdatest.com/lt-debug?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LT Debug Chrome Extension&lt;/a&gt; for debugging websites!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out as well: &lt;a href="https://www.lambdatest.com/learning-hub/usability-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Usability Testing&lt;/a&gt; - A Comprehensive Guide With Examples And Best Practices&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Ruby and Cucumber provide a powerful toolset for creating automated tests, which can be used to drive the development of complex applications. It lets you focus on the code that matters and let Cucumber do the heavy lifting of automation.&lt;/p&gt;

&lt;p&gt;Cucumber is structured for reusability. This means we can easily use the same step definitions in future scenarios by following &lt;a href="https://www.lambdatest.com/blog/cucumber-best-practices/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cucumber’s best practices&lt;/a&gt;. They can be used to enable the system to run tests multiple times without changing any of the logic implemented in the steps and thus is a good tool of choice when it comes to repetitive testing.&lt;/p&gt;

&lt;p&gt;More advanced &lt;a href="https://www.lambdatest.com/blog/24-testing-scenarios-you-should-not-automate-using-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing scenarios&lt;/a&gt; such as &lt;a href="https://www.lambdatest.com/automated-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec01_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automated browser testing&lt;/a&gt; are possible with Cucumber and Watir but would require more complex step definitions and a significant amount of setup time.&lt;/p&gt;

&lt;p&gt;This goes a long way in keeping your codebase bug-free while allowing you to write more complex tests requiring lots of manual interaction. It’s not uncommon for developers to write lots of tests, often manually, but it still costs them time and effort when they’re not particularly complicated.&lt;/p&gt;

</description>
      <category>testing</category>
    </item>
    <item>
      <title>Getting Started With Automation Testing Using Selenium Ruby</title>
      <dc:creator>Roselyne Makena</dc:creator>
      <pubDate>Wed, 30 Nov 2022 15:36:22 +0000</pubDate>
      <link>https://dev.to/testmuai/getting-started-with-automation-testing-using-selenium-ruby-526g</link>
      <guid>https://dev.to/testmuai/getting-started-with-automation-testing-using-selenium-ruby-526g</guid>
      <description>&lt;p&gt;Ruby is a programming language which is well suitable for web automation. Ruby makes an excellent choice because of its clean syntax, focus on built-in library integrations, and an active community. Another benefit of Ruby is that it also allows other programming languages like Java, Python, etc. to be used in order to automate applications written in any other frameworks. Therefore you can use Selenium Ruby to automate any sort of application in your system and test the results in any type of testing environment&lt;/p&gt;

&lt;p&gt;In this Selenium Ruby tutorial, we’ll take a look at how we can use Selenium Ruby for automated testing with some sample code that demonstrates this technique. By the end of this post, you should have a good understanding of how Selenium Ruby works and what it does. In addition, you will also learn where to get started writing your own tests with Selenium-based frameworks and how to run the tests on a cloud Selenium Grid.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Selenium?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; is a browser-based test framework that allows one to automate user actions and interactions with web applications. You can use Selenium WebDriver APIs to devise test code using Selenium-supported languages like Ruby, Java, JavaScript, C#, and Python.&lt;/p&gt;

&lt;p&gt;Selenium and Ruby can be used together, and one of the best ways to do it is through using a gem called selenium-webdriver. With this gem, you can easily automate your test cases using other Ruby-supported frameworks — which we shall introduce below. We will be using Ruby on Selenium in our example, but you can also use your preferred language for automation with Selenium.&lt;/p&gt;

&lt;p&gt;Selenium is a powerful tool as it has support for most major web browsers and supports almost all OS platforms- Windows, Linux, and Mac. Selenium can be used to build both automated and manual test cases.&lt;/p&gt;

&lt;p&gt;So, let’s get started with &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automation testing&lt;/a&gt; with Selenium Ruby.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does Selenium WebDriver in Ruby work?
&lt;/h2&gt;

&lt;p&gt;Selenium WebDriver is a Gem that wraps the WebDriver server and makes it easier to drive a browser. WebDriver is a program that can control a web browser.&lt;/p&gt;

&lt;p&gt;Selenium WebDriver is used to drive the browser and perform actions on web pages. This tool is bundled with the selenium-webdriver project, and it consists of a Ruby Gem to ensure it can be easily consumed by Ruby. It also consists of code that drives any kind of browser supported by Selenium, such as Firefox, Chrome, Safari, Opera, and Internet Explorer.&lt;/p&gt;

&lt;p&gt;If you want to learn more about selenium Selenium WebDriver, you could read this &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt; tutorial.&lt;/p&gt;

&lt;p&gt;There are several other Ruby Gems for &lt;a href="https://www.lambdatest.com/ruby-automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Ruby automation testing&lt;/a&gt;, such as Capybara, which runs on top of Selenium; however we’ll be discussing Selenium in this blog.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8oafkaddf0t72px16r30.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8oafkaddf0t72px16r30.png" width="800" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: &lt;a href="https://www.lambdatest.com/blog/playwright-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Playwright Automation&lt;/a&gt; Tutorial- Getting Started With Playwright Framework&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Selenium WebDriver
&lt;/h2&gt;

&lt;p&gt;You could install Selenium WebDriver in two common ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using the Gemfile&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since it is available as a Gem, you could also install it using a Gemfile by including it as shown below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem 'selenium-webdriver', '&amp;gt;= 3.142.7'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And then run the bundle install on your terminal.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Installing via Gem&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also install it by running it as a command on the terminal. Simply run:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem install selenium-webdriver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  How to use Selenium with Ruby?
&lt;/h2&gt;

&lt;p&gt;In Ruby, you can create an instance of the WebDriver class by either instantiating an object or by starting a session. The instantiated object returns a session object of the WebDriver.&lt;/p&gt;

&lt;p&gt;To instantiate a driver with the session object, we would need to do the following&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@my_driver = Selenium::WebDriver.for :firefox
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;em&gt;@my_driver&lt;/em&gt; has an instance of Firefox at this point. With the session object, we can now execute certain commands. Let’s try some:&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Selenium Ruby methods
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Selecting elements&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;@my_driver.find_element(:name, “elementName”) — Selects an element by its name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;@my_driver.find_element(:id, “textBox1”) — Selected element has an ID of textBox1.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2- Checkboxes&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;@my_driver.get(1).is_checked? — Returns true if the checkbox is checked. Otherwise false.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3- Radio buttons&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;@my_driver.find_element(:name, “radio2”).click&lt;/strong&gt; — Selects a radio button and then clicks it in order to select it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4- Dropdowns&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;*&lt;em&gt;@my_driver.find_element(:name, “dropdown1”).click *&lt;/em&gt;— Selects a dropdown and then clicks it in order to select it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5- Submit buttons&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;@my_driver.find_element(:name, “submit”).click&lt;/strong&gt; — Selects a submit button and then clicks it in order to select it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;6- Form Elements&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;text_box = @my_driver.find_element(:name, “textBox1”)&lt;/strong&gt; — Selects element “textBox1” by its name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;*&lt;em&gt;text_box.send_keys(“hello”) *&lt;/em&gt;— Type in the word “hello”.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;7- Windows&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;@my_driver.execute_script(‘window.open()’)&lt;/strong&gt; — This will open a new window.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;@my_driver.quit_now&lt;/strong&gt; — Closes the current browser window immediately.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;8- Timeouts&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;@my_driver.implicitly_wait(0)&lt;/strong&gt; — This is to wait for the element without specifying the time in seconds.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;@my_driver.implicitly_wait(30)&lt;/strong&gt; — This is to wait for 30 seconds to load an element, e.g., window/frame, etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;@my_driver.implicitly_wait(10, TimeUnit::SECONDS)&lt;/strong&gt; — This is to wait for elements within 10 seconds, and TimeUnit::SECONDS is a class that comes with Ruby.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are just a few. There are many more methods and arguments that you can use to develop your automated tests using Selenium Ruby. I would cover those in the further blogs of this Selenium Ruby tutorial series.&lt;/p&gt;

&lt;p&gt;You can easily program Selenium Ruby tests using any Selenium compatible library. We will implement a simple Selenium automation test in Ruby using the &lt;a href="https://www.lambdatest.com/selenium-automation-testing-with-testunit-framework?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Test::Unit framework&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For developers or testers looking to elevate their Ruby skills to the next level, this Selenium Ruby 101 certification from LambdaTest can be just what you need.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4jd18426wth8k2z48n5o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4jd18426wth8k2z48n5o.png" width="800" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the Selenium Ruby 101 certification from LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/u9vyiYL0I0M"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: &lt;a href="https://www.lambdatest.com/blog/playwright-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Playwright automated testing&lt;/a&gt; Tutorial- Getting Started With Playwright Framework&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to run the Selenium test using Test::Unit?
&lt;/h2&gt;

&lt;p&gt;In this section of this article on Selenium Ruby, we will learn how to run the Selenium test using one of the most popular Ruby frameworks, Test::Unit. Let’s understand more about the Test::Unit framework before getting started.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Test::Unit?
&lt;/h2&gt;

&lt;p&gt;Test::Unit is a basic unit testing framework for Ruby. Test::Unit was initially designed to test the Ruby Standard Library and has since expanded to cover almost all of the standard Ruby classes and modules.&lt;/p&gt;

&lt;p&gt;Test::Unit uses subclassing for tests so that you can use inheritance for your test classes. The most basic skeleton for a Test class is shown below:&lt;/p&gt;

&lt;p&gt;A Selenium script is a Ruby class that inherits the code from the Ruby library ‘Builder’ and contains methods that implement your test plans.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-requisites
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Ruby&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I’m using Ruby 3.0.3 and Selenium WebDriver 4.1.0. If you have an older version of Ruby or Selenium WebDriver, you can check the Ruby version by opening the terminal and typing the following.&lt;/p&gt;

&lt;p&gt;ruby -v&lt;/p&gt;

&lt;p&gt;You should expect to see results similar to or close to the following. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyi68atqlvcmoy65z8smx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyi68atqlvcmoy65z8smx.png" width="800" height="223"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;**&lt;em&gt;Note: **If you do not have Ruby installed, you can download Ruby from the Ruby official documentation. You could use an older version of Selenium and Ruby — however, there might be some minor changes to watch out for.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;2- Selenium WebDriver&lt;/p&gt;

&lt;p&gt;First, check whether you have Selenium WebDriver installed by typing the following in your terminal:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;gem list selenium-webdriver&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In my case, you can see I have Selenium WebDriver (4.1.0) locally installed already.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx5w8ekywvcqx7jr3trdl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx5w8ekywvcqx7jr3trdl.png" width="800" height="139"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3- Browser&lt;/p&gt;

&lt;p&gt;We will be using Firefox for this example. Other browsers supported and available for tests include Chrome, Microsoft Edge, and Opera.&lt;/p&gt;

&lt;p&gt;4- IDE&lt;/p&gt;

&lt;p&gt;We will be using Visual Studio Code, but you could use the IDE of your choice. Other popular Text editors include RubyMine, Sublime, Atom, etc&lt;/p&gt;

&lt;p&gt;Run Selenium Ruby tests on 3000+ browsers. &lt;a href="https://accounts.lambdatest.com/register?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=register" rel="noopener noreferrer"&gt;Try LambdaTest Now!&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Demonstration: Automation Testing with Selenium Ruby
&lt;/h2&gt;

&lt;p&gt;Let’s say you have an eCommerce website where we have a set of tests for demonstration purposes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem Scenario&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We start by defining the test cases that we want to cover. A test case is basically a definition of a set of expected behavior, along with the expected output that we expect to test against.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Cases&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
    &lt;tr&gt;
        &lt;td&gt;TEST DESCRIPTION&lt;/td&gt;
        &lt;td&gt;TEST STEPS&lt;/td&gt;
        &lt;td&gt;EXPECTED RESULTS&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Test that you can reach the homepage.&lt;/td&gt;
        &lt;td&gt;Visit the base page and assert that the homepage has been loaded.&lt;/td&gt;
        &lt;td&gt;The homepage should load the page.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Test that you can filter for an item on the filter box.&lt;/td&gt;
        &lt;td&gt;Visit the base page, search for an item in the search box and assert that the search filter page has been loaded.&lt;/td&gt;
        &lt;td&gt;The expected search filter page should load.&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require 'selenium-webdriver'
require 'test-unit'


class  EcommerceTests &amp;lt; Test::Unit::TestCase
 def setup
   @my_driver = Selenium::WebDriver.for :firefox
   @url = "https://ecommerce-playground.lambdatest.io/"

   #get url
   @my_driver.get(@url)
   @my_driver.manage.timeouts.implicit_wait = 30

   @wait = wait = Selenium::WebDriver::Wait.new(:timeout =&amp;gt; 7)

 end

 def test_search_functionality_should_yield_results

   @wait.until{@my_driver.title.include? "Your Store"}

   search_box = @my_driver.find_element(:name, "search")
   # First test assertion - title has loaded
   assert_equal("Your Store", @my_driver.title.to_s)

   search_box.clear
   search_box.send_keys("phone")
   search_box.submit
   sleep(5)
   search_title = @my_driver.find_element(:xpath, '//*[@id="entry_212456"]/h1').text

   # Second test assertion - title has loaded
   assert_equal("Search - phone", search_title)
 end

 def teardown
   @my_driver.quit
 end

end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At the top of our class, we define the test case name. We then define a variable used to override a method of WebDriver (The driver). This is where we create an instance of WebDriver and pass it to the Selenium class, which we inherit from Test::Unit::TestCase.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmentiqwiow5viqlyoi6t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmentiqwiow5viqlyoi6t.png" width="720" height="208"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, you need to set up the &lt;a href="https://www.lambdatest.com/blog/selenium-standalone-server-and-selenium-server/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium server&lt;/a&gt;. This step is similar to other testing frameworks and involves installing a Selenium server. It can be done by including the Selenium Gem.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuchprn0qfbfpr5cthnlw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuchprn0qfbfpr5cthnlw.png" width="776" height="172"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the EcommerceTests class we start by defining a new blank test case that inherits from the Test::Unit::TestCase class.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj2nn4n50gvopyg3ayioa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj2nn4n50gvopyg3ayioa.png" width="800" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we initialize our variables in which we define what URL to visit and what to expect.&lt;/p&gt;

&lt;p&gt;This is where we create an instance of Selenium::WebDriver and pass it to our class using the name @my_driver.&lt;/p&gt;

&lt;p&gt;We then use the &lt;a href="https://www.lambdatest.com/automation-testing-advisor/ruby/methods/Selenium.WebDriver.get?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;get method of Selenium::WebDriver &lt;/a&gt;to call the baseUrl method that returns a URL, which in this case is &lt;a href="https://ecommerce-playground.lambdatest.com" rel="noopener noreferrer"&gt;https://ecommerce-playground.lambdatest.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft2y59icu8lbpdgnk1qdi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft2y59icu8lbpdgnk1qdi.png" width="800" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After the page has loaded fully, we search for the search box element by its name and make our first test using an assertion.&lt;/p&gt;

&lt;p&gt;This also applies to the second assertion, where we add the assert_equal for the filtered item element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ending the browser session&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The teardown method is a method that Selenium WebDriver implements to terminate the browser session or run methods that need to be completed at the end of the test run. This is important because the number of browser sessions is limited by the driver implementation.&lt;/p&gt;

&lt;p&gt;A teardown method will be discarded if invoked before the teardown method for all old sessions has been executed. If two or more teardown methods are invoked simultaneously, only one will be executed, and the others will be discarded.&lt;/p&gt;

&lt;p&gt;In this method, we invoke @my_driver.quit in order to terminate the browser session.&lt;/p&gt;

&lt;p&gt;Here we are terminating three browser sessions. This can be shown in line 57: of closed browser sessions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foekoeir0swcr65s3t7z5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foekoeir0swcr65s3t7z5.png" width="702" height="244"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Execution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After running the script, we should observe the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkp6alyj0txg49qvpg5m1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkp6alyj0txg49qvpg5m1.png" width="800" height="175"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see we have our two assertions passing, with 0 errors and 0 failures.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Assertions in Selenium Ruby?
&lt;/h2&gt;

&lt;p&gt;A test assertion is a point of critical code that we can test. Usually, assertions are used to verify some conditions, but they can also be used to verify certain values.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;assert_true&lt;/strong&gt; is used to test that a condition is true, and an assert_match is used to verify a value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;assert_match&lt;/strong&gt; is used to verify a value. For example, we can assign an integer value to a variable, increment it by one, and then use the assert_match assertion to verify whether its value is equal to that of the initial state.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;assert_not_find&lt;/strong&gt; is used to verify that a find operation did not find anything. It is especially useful to test that the find operation works correctly, but we cannot test for it, as it might fail for certain values.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;assert_exception&lt;/strong&gt; method is used to authenticate a failure in a test case. If a failure occurs, the Exception object will be thrown with the message given in the assertion. When checking this method, we should also make sure that all expected exception classes are present.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;assert_not_send&lt;/strong&gt; is used to query that a function call did not launch. In this assertion, we check that the function invoked is not sent as a parameter. Once the find operation is performed and does not find anything, an exception will be thrown. To check if expected exceptions are present, we can use the expect_exception method.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;assert_no_error&lt;/strong&gt; specifies that a specified number of errors should be presented or none should be generated in your test case. Once an error is displayed in your Selenium WebDriver test case, that exception will be ignored by the assert no error conditions when it occurs again in another instance of the same test case.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;**assert_raise **is used to assert that a specific exception will be raised by the code.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are just a few assertions that we can use in Ruby Test::Unit, but there are many more that you can check out.&lt;/p&gt;

&lt;p&gt;Watch this video to learn about some exciting features offered by Playwright, like recording tests, taking screenshots of tests, auto-wait mechanism, and much more.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/1INdYpaXqLE"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: Cross Browser Testing Cloud - Browser &amp;amp; app testing cloud to perform both exploratory and automated &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;testing web&lt;/a&gt; across 3000+ different browsers, real devices and operating systems.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What happens when the test fails?
&lt;/h2&gt;

&lt;p&gt;If our assertion fails, we get a very descriptive error message that tells us exactly what went wrong. It will even point out the exact line where this occurred in our test file.&lt;/p&gt;

&lt;p&gt;Furthermore, failures also tell us what went wrong and whether anything else worked as expected. It will also provide a stack trace of all methods called since the beginning of the test run so we can find out which method failed by looking at their call stacks.&lt;/p&gt;

&lt;p&gt;Let’s have a look at an example of a failure below:&lt;/p&gt;

&lt;p&gt;As an example, let’s change one assertion in our example above to have a different value so that we expect a failure.&lt;/p&gt;

&lt;p&gt;**&lt;em&gt;Note: **At line 22, Our new assert now reads “Nothing Here” and not “Your Store” — thus, we are setting up our test to fail.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0wfi4bin2duhuoavrl7o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0wfi4bin2duhuoavrl7o.png" width="800" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On running this, we get the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4hso7gne5srjodaqz6wz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4hso7gne5srjodaqz6wz.png" width="800" height="521"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Interpreting the failure
&lt;/h2&gt;

&lt;p&gt;As we can see on line 23: there’s a failure indicated by the bright red color, and below it, we see that it’s the mismatch between the expected string and the actual string.&lt;/p&gt;

&lt;p&gt;We can further see the summary of the failure at the end of the script.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running Selenium Ruby Tests on Cloud Grid
&lt;/h2&gt;

&lt;p&gt;Many Selenium cloud Grid services are provided. However, it is not easy for the users to choose the best one. Here is a list of some of the main things that people should consider before choosing any particular service.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Supports cross-browser testing&lt;/strong&gt; — For &lt;a href="https://www.lambdatest.com/automation-testing-advisor/ruby/methods/Selenium.WebDriver.get?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt;, you need to have a grid that can be used with any of the latest and legacy browsers. You should also check the list of browsers and browser versions that are supported by any particular cloud solution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Assures quality&lt;/strong&gt; — The users should check the reviews and ratings of the cloud solution in order to know whether they work well or not. To assure quality, they should also check whether they are working with experienced staff or not because experienced people can ensure quality testing better than inexperienced ones.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Supports parallel test execution&lt;/strong&gt; — To do &lt;a href="https://www.lambdatest.com/blog/what-is-parallel-testing-and-why-to-adopt-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing&lt;/a&gt;, the users should be able to select any number of browsers that they can run at the same time. In the case of cloud grid solution, you will get many options like setting a parallel number of instances or choosing a particular cloud that can create instances that quickly. You can set as many parallels as you want to test your product with multiple browsers simultaneously.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Run in a distributed environment&lt;/strong&gt; — In order to run such kind of work in a distributed environment, the users should have the ability to choose any number of servers which will be used for running tests on that particular server. They should be able to deploy their scripts on multiple servers in order to do distributed testing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Easy to use and not complicated&lt;/strong&gt; — Use a solution that is simple and easy. Any user should be able to use the solution without any difficulty. They should avoid selecting any service that is complicated because it can create a lot of problems for them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Logging&lt;/strong&gt; — should be easily visible and readable by the user. It should also store a large number of users’ logs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;*&lt;em&gt;Reporting *&lt;/em&gt;— The users should make automated reports in order to follow them. They should be able to make the reports automatic. The users should be able to see a lot of information about their work by making them automatic&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability&lt;/strong&gt; — Their cloud grid should have many instances that you can add and delete as per your requirement. The number of instances should also be scalable by which you can add more capacity to your grid if required and shut down the instance if it is not required anymore.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;*&lt;em&gt;Security and efficiency *&lt;/em&gt;— A good cloud solution provider will have a solid security system set up for the protection of their users’ data. This may include secure logins, firewalls, encrypted data storage, and secure transactions using SSL and similar protocols. A full-time security team will be assigned to monitor any sign of hacking or misuse of data.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cloud based &lt;a href="https://www.lambdatest.com/automated-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automated browser testing&lt;/a&gt; platforms like LambdaTest allows you to run your scripts using different testing frameworks for example — Selenium, Cypress, Playwright, Puppeteer, Appium, etc., and execute them in multiple browsers at the same time — using a variety of devices on demand.&lt;/p&gt;

&lt;p&gt;Playwright is an open-source, cross-browser automation framework that provides e2e testing without the need for any third-party tools. Learn what it is, how to install it, and how we can execute tests using Playwright.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/06HIhFcpBDo"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/automation-testing-tool?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Automation testing tools&lt;/a&gt; like LambdaTest provides an &lt;a href="https://www.lambdatest.com/online-browser-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;online device farm&lt;/a&gt; of over 3000+ real devices running real operating systems to perform Selenium Ruby testing at scale. Here’s the glimpse of LambdaTest &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;online Selenium Grid.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/WZlsHlReRww"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: How To Debug Websites Using &lt;a href="https://www.lambdatest.com/blog/debug-websites-using-safari-developer-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;developer tools for Safari&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can also subscribe to the LambdaTest YouTube Channel and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress E2E testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to run Selenium Ruby Tests on LambdaTest?
&lt;/h2&gt;

&lt;p&gt;Running your Selenium Ruby test on LambdaTest is very quick and easy. Follow the below mentioned steps to get started:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=login" rel="noopener noreferrer"&gt;Login/Register at LambdaTest&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Obtain your LambdaTest credentials by choosing the &lt;strong&gt;Automation&lt;/strong&gt; option and checking the top right corner by clicking Access Key.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4xoo5wqxml102txto94r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4xoo5wqxml102txto94r.png" width="800" height="654"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3- Generate the desired capabilities using the &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest Desired Capabilities Generator.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Be sure to select Ruby as we are using Ruby for this example. We will use the basic configurations selected for now and discuss the other settings in another tutorial.&lt;/p&gt;

&lt;p&gt;4- Export your Username and Access Key in environment variables.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;For Linux/macOS: 
export LAMDATEST_USERNAME="YOUR_USERNAME"
export LAMDATEST_ACCESS_KEY="YOUR ACCESS KEY"

For Windows: set LT_USERNAME="YOUR_USERNAME"
set LT_ACCESS_KEY="YOUR ACCESS KEY"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Code Changes to run tests on LambdaTest
&lt;/h2&gt;

&lt;p&gt;In order to run your tests on LambdaTest, you would need to substitute your remote local webdriver with a &lt;a href="https://www.lambdatest.com/blog/selenium-remotewebdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;RemoteWebdriver&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thus our new changes should be as defined in the code below.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require 'selenium-webdriver'
require 'test-unit'

class EcommerceTests &amp;lt; Test::Unit::TestCase
 def setup
   username= "{LAMBDATEST_USERNAME}"
   accessToken= "{LAMBDATEST_ACCESS_KEY}"
   gridUrl = "hub.lambdatest.com/wd/hub"

   capabilities = {
     'LT:Options' =&amp;gt; {
       "user" =&amp;gt; username,
       "accessKey" =&amp;gt; accessToken,
       "build" =&amp;gt; "Ecommerce Test v.1",
       "name" =&amp;gt; "Ecommerce Tests",
       "platformName" =&amp;gt; "Windows 11"
     },
     "browserName" =&amp;gt; "Firefox",
     "browserVersion" =&amp;gt; "100.0",
   }


   @my_driver = Selenium::WebDriver.for(:remote,
                                     :url =&amp;gt; "https://"+username+":"+accessToken+"@"+gridUrl,
                                     :desired_capabilities =&amp;gt; capabilities)
   @url = "https://ecommerce-playground.lambdatest.io/"
   @wait = Selenium::WebDriver::Wait.new(:timeout =&amp;gt; 30)

   #get url
   @my_driver.get(@url)

   @my_driver.manage.timeouts.implicit_wait = 30

 end

 def test_search_functionality_should_yield_results

   @wait.until{@my_driver.title.include? "Your Store"}

   search_box = @my_driver.find_element(:name, "search")
   # First test assertion - title has loaded
   assert_equal("Your Store", @my_driver.title.to_s)

   search_box.clear
   search_box.send_keys("phone")
   search_box.submit
   sleep(5)
   search_title = @my_driver.find_element(:xpath, '//*[@id="entry_212456"]/h1').text

   # Second test assertion - title has loaded
   assert_equal("Search - phone", search_title)
 end

 def teardown
   @my_driver.quit
 end

end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;**&lt;em&gt;Note: **Remember to replace your **LAMBDATEST_USERNAME **and **LAMBDATEST_ACCESS_KEY **with the ones you obtained after signing up on LambdaTest.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Test Results on LambdaTest
&lt;/h2&gt;

&lt;p&gt;As you can see, the results run on the left tab and will be the most recent run at the top as can be seen below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu9fi2bf619e6bae4sjap.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu9fi2bf619e6bae4sjap.png" width="800" height="456"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We now click the latest version of the Build and we now see the test results for this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: &lt;a href="https://www.lambdatest.com/blog/playwright-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Playwright browser testing&lt;/a&gt; Tutorial- Getting Started With Playwright Framework&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Evaluating the results run on the LambdaTest Dashboard
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqcdu5v00vrikk7n1gycm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqcdu5v00vrikk7n1gycm.png" width="800" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, you can see a video on the left — that shows the test results ran in the LambdaTest dashboard.&lt;/p&gt;

&lt;p&gt;In this view, you can check whether your script passed all the executions or not, and you can also check some more parameters related to your test instances such as — Execution Status , Browser View, Browser Version, Device Type, Device Capabilities etc.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;All Commands Tab&lt;/strong&gt; — This shows all the commands that the test script has executed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Selenium Logs Tab&lt;/strong&gt; — This shows the logs of the WebDriver — such as configuration, capabilities, etc and would appear as shown below.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw9wl5bjc8k4w7r0jejtq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw9wl5bjc8k4w7r0jejtq.png" width="800" height="610"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will also see some views and tabs in the Selenium Ruby dashboard that show more details about your test scripts’ full execution overtime process.&lt;/p&gt;

&lt;p&gt;You can navigate to the &lt;a href="https://analytics.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest Analytics Dashboard&lt;/a&gt; to see performance of your tests. From the Test Summary section you can see the total number of tests passed or failed and from the Test Overview section, you can see the snapshot of consistent tests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5v1x62vvwxukukolcunj.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5v1x62vvwxukukolcunj.gif" width="600" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will also note that there are options to run parallel tests — this will help you save time by running your tests in parallel and using different configurations in the process, which is something that can be covered in a separate article.&lt;/p&gt;

&lt;p&gt;Watch this video to learn how to write a basic script with Playwright using functions &amp;amp; selectors and then launch the browser to execute the test.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/UWeXnulWfJs"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov30_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress test Automation&lt;/a&gt; Tutorial- E2E Testing with Cypress&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Like Java and Python, Ruby is a general-purpose programming language; however, it focuses on simplicity, precision, and productivity. Ruby being an array-based language, is very powerful for specific uses and works particularly well with ordered datasets. Moreover, since Ruby has a shorter learning curve and serves the purpose of a specialized tool for what you need for test automation, it is a preferred choice of many developers.&lt;/p&gt;

&lt;p&gt;In this Selenium Ruby tutorial, we have seen how Selenium Ruby can be used for automation testing with code examples. By now, you must be comfortable writing your own Selenium Ruby tests and running them on a cloud Selenium Grid like LambdaTest.&lt;/p&gt;

</description>
      <category>career</category>
      <category>softwaredevelopment</category>
      <category>devops</category>
      <category>technology</category>
    </item>
  </channel>
</rss>
