<?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>Forem: Ramit Dhamija</title>
    <description>The latest articles on Forem by Ramit Dhamija (@ramitdhamija).</description>
    <link>https://forem.com/ramitdhamija</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%2F924763%2F8fbe4d0b-1cb8-404a-8e0e-7e74f283d44b.png</url>
      <title>Forem: Ramit Dhamija</title>
      <link>https://forem.com/ramitdhamija</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ramitdhamija"/>
    <language>en</language>
    <item>
      <title>How WebdriverIO Uses Selenium Locators in a Unique Way - A WebdriverIO Tutorial With Examples</title>
      <dc:creator>Ramit Dhamija</dc:creator>
      <pubDate>Fri, 23 Sep 2022 09:32:56 +0000</pubDate>
      <link>https://forem.com/testmuai/how-webdriverio-uses-selenium-locators-in-a-unique-way-a-webdriverio-tutorial-with-examples-m47</link>
      <guid>https://forem.com/testmuai/how-webdriverio-uses-selenium-locators-in-a-unique-way-a-webdriverio-tutorial-with-examples-m47</guid>
      <description>&lt;p&gt;In any automation testing framework, finding elements is the most fundamental activity. We have to choose web elements very carefully so that automation script execution can handle static and dynamic elements for stable test results. WebDriverIO has many advanced &lt;a href="https://www.lambdatest.com/learning-hub/selenium-locators?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep23_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium locators&lt;/a&gt;/ selector strategies compared to other automation testing frameworks. Traditionally, each locator has a specific &lt;strong&gt;By method&lt;/strong&gt; which identifies the locators during runtime. However, WebdriverIO has simplified these &lt;strong&gt;By methods&lt;/strong&gt; and now we do not have to specify them explicitly. Webdriver Tutorial has the intelligence to identify which locator has been passed. By the end of this &lt;a href="https://www.lambdatest.com/learning-hub/webdriver?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep23_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Webdriver tutorial&lt;/a&gt;, you will learn how WebDriverIO is transforming the way of Selenium locator strategy and how easy to remember and write it.&lt;/p&gt;

&lt;p&gt;Note: If you refer to the official documentation of the WebdriverIO framework, you will notice that they have referred to Locators as Selectors. You need not get confused if you are familiar with some other test automation framework in Selenium. For example, if you have worked with Selenium Locators in Java, then those locators in WebdriverIO are addressed as Selectors.&lt;/p&gt;

&lt;p&gt;For the ease of understanding, I will refer to them as Selenium locators in this WebdriverIO tutorial. As it is a more standardized and familiar term around &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep23_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;New to CSS Selectors? Check out this &lt;a href="https://www.lambdatest.com/blog/css-selectors-cheat-sheet/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep23_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Ultimate CSS Selector cheat sheet&lt;/a&gt; to boost your web designing career.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Selenium Locators In WebdriverIO?
&lt;/h2&gt;

&lt;p&gt;Before we start off this WebdriverIO tutorial for Selenium locators/selectors, let us quickly understand what they are used for. Selenium locators are utilized to find elements on a web page through a &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=sep23_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt; when a test automation script is executed. The Selector is a command in Selenium. Selenium library reads this command from the script, convert into an HTTP request and interact with Web browsers lastly, perform actions based on the command.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Automate &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep23_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress cloud&lt;/a&gt; testing and perform browser automation testing with LambdaTest. Our cloud infrastructure has 3000+ desktop &amp;amp; mobile environments. Try for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Selenium Locator Strategies
&lt;/h2&gt;

&lt;p&gt;When you get hands-on Selenium automation testing using WebdriverIO, you should be aware of the correct strategy that works for locating unique elements on a web page. Finding elements by ID, Name and relative XPath would be the first choice to find a unique element from the website. If you could not find any of these ways then it is advisable to choose other types of the Selenium locators/ selector.&lt;/p&gt;

&lt;p&gt;If you have performed Selenium automation testing with Java, you may have used findElement() and findElements() method to find the selector from DOM. However, WebdriverIO offers a unique way of Selenium testing with WebDriverIO. With WebdriverIO, you don’t have to mention the Selenium locator’s strategy as it will automatically understand which types of locator strategy should be used. We will look into each Selenium Locator in this WebdriverIO tutorial. Before we jump into practical demonstration, make sure to note down the below methods for finding elements in WebDriverIO:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;$():&lt;/strong&gt; Single dollar sign used to find single web element&lt;br&gt;
&lt;strong&gt;$$():&lt;/strong&gt; Double dollar sign used to find multiple web elements&lt;/p&gt;

&lt;p&gt;Apart from these two methods, WebDriverIO Support other methods which are,&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;custom$():&lt;/strong&gt; used to find a custom strategy for a single web element&lt;br&gt;
&lt;strong&gt;custom$():&lt;/strong&gt; used to find a custom strategy for multiples web elements&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;react$():&lt;/strong&gt; used to find single React component by their given name and it gets filter by props and state&lt;br&gt;
&lt;strong&gt;react$$():&lt;/strong&gt; used to find multiples React components by their given name and it gets filter by props and state&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; react$ and react$$ command only works with applications using React v16.x&lt;/p&gt;

&lt;p&gt;You can take this certification as proof of expertise in the field of test automation with JavaScript to empower yourself and boost your career.&lt;/p&gt;

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

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

&lt;h2&gt;
  
  
  How To Find A Web Element In Browser?
&lt;/h2&gt;

&lt;p&gt;To find a web element in the browser, User has to go to the browser’s developer tools by pressing F12 in windows and option+command+i in Mac Operating System or right-clicking on a website and select inspect option.&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%2ABNwDEq-FE0nL9k8W.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%2ABNwDEq-FE0nL9k8W.png" width="800" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Browser Developer Tools&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you open the developer tool, you can see HTML tags under the “Elements” tab. This HTML tab calls DOM elements. To find particular Web Elements, select the selector icon( before the Elements tab) and hover over the element you wish to find in 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%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F0%2AFY_KQ-C_W9yZSOCq.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%2AFY_KQ-C_W9yZSOCq.png" width="800" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  List Of Selenium Locators In WebDriverIO
&lt;/h2&gt;

&lt;p&gt;Now that you have a good understanding of Selenium Locators, let us see the different types of Selenium Locators in this WebdriverIO tutorial. The following are the supported selectors by the WebdriverIO.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;CSS Query Selector&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Link Text&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Partial Link Text&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Element with certain text&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tag Name&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Name&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;xPath&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ID&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JS Function&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Chain Selectors&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;React Selectors&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Custom Selector&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Now,&lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep23_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress test Automation&lt;/a&gt; and perform browser automation testing with LambdaTest.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS Query Selector
&lt;/h2&gt;

&lt;p&gt;The first locator in this WebdriverIO tutorial for Selenium automation testing is the CSS Query selector, which is used to find the element from DOM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How can you find CSS Query?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Go to developer tools and find the element and right click on Selected element in the DOM and copy CSS selector option.&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%2F3170%2F0%2AdJzWDwpCgYV-HYYU.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%2F3170%2F0%2AdJzWDwpCgYV-HYYU.png" width="800" height="807"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt; $(‘CSS Query’);&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const assert = require("assert");

describe("Selector Example", function() {
   it("CSS Query Selector", function() {
       driver.url("https://lambdatest.github.io/sample-todo-app/");
       $("body &amp;gt; div.ng-scope &amp;gt; div &amp;gt; div &amp;gt; ul").click();     
   });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;When you run the above script, you can find the console log and observed that WebdriverIO converted into findElement method with CSS selector strategy.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[0-0] 2019-12-24T10:34:19.689Z INFO webdriver: COMMAND findElement("css selector", "body &amp;gt; div.ng-scope &amp;gt; div &amp;gt; div &amp;gt; ul")
[0-0] 2019-12-24T10:34:19.689Z INFO webdriver: [POST] http://127.0.0.1:4444/session/839505649081eaf3bef60a252593f2f9/element
[0-0] 2019-12-24T10:34:19.689Z INFO webdriver: DATA { using: 'css selector',
 value: 'body &amp;gt; div.ng-scope &amp;gt; div &amp;gt; div &amp;gt; ul' }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep23_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt; tutorial that will help you learn the benefits of Cypress automation, and how to install Cypress and execute Cypress automation testing.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Remember, Sometimes using CSS query selector could result in locating multiple elements as a CSS sheet used for the whole website. Now, let us head to the next Selenium locator in this WebdriverIO tutorial.&lt;/p&gt;

&lt;h2&gt;
  
  
  Link Text
&lt;/h2&gt;

&lt;p&gt;A website is made up of different types of components e.g textbox, links, drop-down, etc. Even a single web page can have numerous links over it. Selecting a particular link for your Selenium automation testing script could become challenging. This is where Link Text as a Selenium Locators for WebdriverIO comes into play. If you want to find any hyperlink then use this link text selector strategy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt; $(‘=anchorText’);&lt;/p&gt;

&lt;p&gt;Here, = equal to sign is used to find anchor element with ‘specific text’.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const assert = require("assert");
describe("Selector Example", function() {
   it("Open URL", function() { 
       driver.url("https://www.lambdatest.com/");     
   });
   it("Link Text Example", function() {
       $("=Automation").click();
   });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;When you run the above automation testing script, you can find the console log. If you notice the logs you will observe that WebdriverIO has automatically detected the findElement method with link text strategy.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0-0] 2019-12-24T10:58:56.640Z INFO webdriver: COMMAND findElement("link text", "Automation")
[0-0] 2019-12-24T10:58:56.640Z INFO webdriver: [POST] http://127.0.0.1:4444/session/0a34df231b0b77c5e0e4d687a14829a2/element
[0-0] 2019-12-24T10:58:56.640Z INFO webdriver: DATA { using: 'link text', value: 'Automation' }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Element With Certain Text
&lt;/h2&gt;

&lt;p&gt;In HTML every tag is known as an element and few elements have the direct text and few elements wrapped around other tags. If you want to find the element which has a certain or partial text then this selector is preferred to use.&lt;/p&gt;

&lt;p&gt;While Selenium automation testing using Java, you would use XPath with normalize-space() method to find text along with HTML tag if you want to find HTML tag with some text but WebdriverIO uses the method below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$(‘elementTag=certain text’); used for fixed text
$(‘elementTag*=partial text’); used for partial text
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This selector takes help from = (equal to) and *= (start equal to) sign.&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%2F2196%2F0%2A5XnCeUrBXHn2kacd.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%2F2196%2F0%2A5XnCeUrBXHn2kacd.png" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For instance, to find &lt;strong&gt;Cross Browser Testing Cloud&lt;/strong&gt; from below H1 tag, using this command &lt;strong&gt;$(“h1=Cross Browser Testing Cloud”)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&amp;lt; h1 class=”big_title text_shadow_black &lt;strong&gt;web-inspector-hide-shortcut&lt;/strong&gt;”&amp;gt;Cross Browser Testing Cloud&amp;lt; /h1&amp;gt;&lt;/p&gt;

&lt;p&gt;The same thing will work for class and ID attribute of the elements. For example:&lt;/p&gt;

&lt;p&gt;$(‘#id=certain text’); used for fixed text&lt;br&gt;
$(‘#id*=certain text’); used for partial text&lt;br&gt;
$(‘.classname=certain text’); used for fixed text&lt;br&gt;
$(‘.classname*=partial text’); used for partial text&lt;/p&gt;

&lt;p&gt;Here, # is used when you want to find elements by ID and . (dot) used for the class name.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const assert = require("assert");

describe("Selector Example", function() {
   it("Open URL", function() {
       driver.url("https://www.lambdatest.com/");
   });
   it("Element with certain text Example", function() {
       $("h1=Cross Browser Testing Cloud").click();
   });
   it("Element with Partial text Example", function() {
       $("h1*=Cross Browser Testing").click();
   });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;When you run the above script, you can find the console log and observe that WebdriverIO converted into findElement method with “normalize-space()” and “contains()”.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[0-0] 2019-12-24T11:39:33.082Z INFO webdriver: COMMAND findElement("xpath", ".//h1[normalize-space() = "Cross Browser Testing Cloud"]")
[0-0] 2019-12-24T11:39:33.082Z INFO webdriver: [POST] http://127.0.0.1:4444/session/423097da27eadf53b1fac0f11655e9be/element
[0-0] 2019-12-24T11:39:33.083Z INFO webdriver: DATA { using: 'xpath',
 value: './/h1[normalize-space() = "Cross Browser Testing Cloud"]' }
[0-0] 2019-12-24T11:39:33.099Z INFO webdriver: RESULT { 'element-6066-11e4-a52e-4f735466cecf': '03328283-f372-423c-8218-48759ac98631' }
[0-0] 2019-12-24T11:39:33.104Z INFO webdriver: COMMAND elementClick("03328283-f372-423c-8218-48759ac98631")
[0-0] 2019-12-24T11:39:33.105Z INFO webdriver: [POST] http://127.0.0.1:4444/session/423097da27eadf53b1fac0f11655e9be/element/03328283-f372-423c-8218-48759ac98631/click
[0-0] 2019-12-24T11:39:33.151Z INFO webdriver: COMMAND findElement("xpath", ".//h1[contains(., "Cross Browser Testing")]")
[0-0] 2019-12-24T11:39:33.151Z INFO webdriver: [POST] http://127.0.0.1:4444/session/423097da27eadf53b1fac0f11655e9be/element
[0-0] 2019-12-24T11:39:33.151Z INFO webdriver: DATA { using: 'xpath',
 value: './/h1[contains(., "Cross Browser Testing")]' }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, let us have a look at the Tag Name locator in this WebdriverIO tutorial for Selenium automation testing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tag Name
&lt;/h2&gt;

&lt;p&gt;We use the tag name selector to find the element using any HTML tag. This is a very rarely used Selenium locator. However, this is very important if you are dealing with tables or calendar elements. While Selenium automation testing, you can pass the Tag Name as either of &amp;lt; tag &amp;gt; or &amp;lt; tag /&amp;gt;.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$(‘&amp;lt;tag&amp;gt;’);
$(‘&amp;lt;tag /&amp;gt;’);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const assert = require("assert");
describe("Selector Example", function() {
   it("Open URL", function() {
       driver.url("https://www.lambdatest.com/");
   });
   it("Tag Name Example", function() {
       $("&amp;lt;h1&amp;gt;").getText();
   });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is the output when the above Selenium automation testing script is executed in WebdriverIO.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[0-0] 2019-12-26T10:07:37.804Z INFO webdriver: COMMAND findElement("tag name", "h1")
[0-0] 2019-12-26T10:07:37.804Z INFO webdriver: [POST] http://127.0.0.1:4444/session/d67eadf284b85ecd1e641855c194937b/element
2019-12-26T10:07:37.804Z INFO webdriver: DATA { using: 'tag name', value: 'h1' }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Name
&lt;/h2&gt;

&lt;p&gt;This Selenium locator is similar to the ID Locator in Selenium. Sometimes a web developer gives a name to the HTML node. If a node has a name attribute then it is preferred to incorporate the Name locator in Selenium automation testing. The name selector has to be within square brackets with the name attribute.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$(‘[&amp;lt;name attribute&amp;gt;]’)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const assert = require("assert");

describe("Selector Example", function() {
   it("Open URL", function() {
       driver.url("https://www.facebook.com/");
   });
   it("Name Example", function() {
       $("[name = 'email']").setValue("123");
   });

});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[0-0] 2019-12-26T10:15:08.208Z INFO webdriver: COMMAND findElement("css selector", "[name = 'email']")
[0-0] 2019-12-26T10:15:08.208Z INFO webdriver: [POST] http://127.0.0.1:4444/session/aee87e328f63eb11678a49adce17df4b/element
[0-0] 2019-12-26T10:15:08.208Z INFO webdriver: DATA { using: 'css selector', value: '[name = \'email\']' }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  XPath
&lt;/h2&gt;

&lt;p&gt;An extremely pivotal Selenium locator of this WebdriverIO tutorial. In WebDriverIO also, you can write absolute XPath and relative XPath. Absolute XPath starts with / slash and relative starts with // slash. This is a very strong and frequently used selector/ locator for identifying elements through Selenium automation testing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Following special characters are used while writing XPath.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;. — Dot means selection starts from the current node&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;— Star means select any node
/ — Single slash means starts with the root node and used for absolute XPath
// — Double slash means to search the node using relative XPath
[ ] — square bracket used for index and also used for searching XPath by passing attribute and it’s value
@ — used for identify for HTML attribute in XPath&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Syntax for Absolute XPath:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$(‘&amp;lt;starts with /body&amp;gt;’);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Syntax for Relative XPath:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$(‘&amp;lt;starts with .//&amp;gt;’);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const assert = require("assert");

describe("Selector Example", function() {
   it("Open URL", function() {
       driver.url("https://www.lambdatest.com/");
   });

   it("Xpath - Absolute Example", function() {
       $("/html/body/div[2]/section[1]/div/div/h1").getText();
   });

   it("Xpath - Relative Example", function() {
       $(".//h1[@class='big_title text_shadow_black']").getText();
   });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;When you run the above script, you can find the console log. Observe that WebdriverIO converted into findElement method with “XPath”.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[0-0] 2019-12-25T17:54:37.674Z INFO webdriver: COMMAND findElement("xpath", "/html/body/div[2]/section[1]/div/div/h1")
[0-0] 2019-12-25T17:54:37.675Z INFO webdriver: [POST] http://127.0.0.1:4444/session/5f6efebb541063139a91dec5d13c32f6/element
2019-12-25T17:54:37.675Z INFO webdriver: DATA { using: 'xpath',
 value: '/html/body/div[2]/section[1]/div/div/h1' }
[0-0] 2019-12-25T17:54:37.688Z INFO webdriver: RESULT { 'element-6066-11e4-a52e-4f735466cecf': 'bc244c90-ed18-4d94-9b7a-d026ba7d70d4' }
[0-0] 2019-12-25T17:54:37.694Z INFO webdriver: COMMAND getElementText("bc244c90-ed18-4d94-9b7a-d026ba7d70d4")
[0-0] 2019-12-25T17:54:37.694Z INFO webdriver: [GET] http://127.0.0.1:4444/session/5f6efebb541063139a91dec5d13c32f6/element/bc244c90-ed18-4d94-9b7a-d026ba7d70d4/text
[0-0] 2019-12-25T17:54:37.709Z INFO webdriver: RESULT Cross Browser Testing Cloud
[0-0] 2019-12-25T17:54:37.710Z INFO webdriver: COMMAND findElement("xpath", ".//h1[@class='big_title text_shadow_black']")
[0-0] 2019-12-25T17:54:37.710Z INFO webdriver: [POST] http://127.0.0.1:4444/session/5f6efebb541063139a91dec5d13c32f6/element
[0-0] 2019-12-25T17:54:37.710Z INFO webdriver: DATA { using: 'xpath',
 value: './/h1[@class=\'big_title text_shadow_black\']' }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  ID
&lt;/h2&gt;

&lt;p&gt;Another crucial Selenium Locator of this WebdriverIO tutorial. The ID is an extremely powerful selector to find an element from DOM. This is always a unique element in the DOM. One more important thing is that, if you want to speed up your automation execution then this is a must use Locator for Selenium automation testing. The ID directly gets a search from DOM whereas XPath scan the documents based on a relative or absolute path which is a time-consuming method.&lt;/p&gt;
&lt;h1&gt;
  
  
  sign used to find elements using ID.
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$(#&amp;lt;idname&amp;gt;);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const assert = require("assert");

describe("Selector Example", function() {
   it("Open URL", function() {
       driver.url("https://www.facebook.com/");
   });
   it("ID Example", function() {
       $("#email").setValue("123");
   });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, here you should observe this output log. When you run the above script, you can see ID selector internally converted into css selector and finding the element.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[0-0] 2019-12-25T18:29:26.359Z INFO webdriver: COMMAND findElement("css selector", "#email")
[0-0] 2019-12-25T18:29:26.360Z INFO webdriver: [POST] http://127.0.0.1:4444/session/52e465fa0b2d0dacaf976994dd1edc60/element
2019-12-25T18:29:26.360Z INFO webdriver: DATA { using: 'css selector', value: '#email' }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, we have covered the usual Selenium locators in WebdriverIO. Next, we look at the advanced Selenium Locators/ Selectors in this WebdriverIO tutorial.&lt;/p&gt;

&lt;h2&gt;
  
  
  Chain Selectors
&lt;/h2&gt;

&lt;p&gt;Sometimes it gets difficult to find an element that has no ID, name and tables rows and cells, in such a case, this chain selector helps you to get your unique element. There is no specific symbol given for this but you just call $().$() until you find the desired element by period (.) sign.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Chain Selector/Locator uses the parent-child concept. So the Next chain element should fall under the parent chain selector.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$(selector).$(selector).$(selector)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const assert = require("assert");

describe("Selector Example", function() {

   it("Open URL", function() {
       driver.url("https://www.facebook.com/");
   });

   it("Chain - Selector Example", function() {
       $("#login_form")
           .$(".//table[@role='presentation']")
           .$("#email")
           .setValue("123");
   });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;When the script gets executed, each element starts finding element one by one until it reaches the final element. Firstly it uses findElement() and then calls findElementFromElement().&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0-0] 2019-12-26T06:14:22.748Z INFO webdriver: COMMAND findElement("css selector", "#login_form")
[0-0] 2019-12-26T06:14:22.748Z INFO webdriver: [POST] http://127.0.0.1:4444/session/3f354aaa54fb0ffee1fdf547ad3d9b04/element
[0-0] 2019-12-26T06:14:22.748Z INFO webdriver: DATA { using: 'css selector', value: '#login_form' }
[0-0] 2019-12-26T06:14:22.760Z INFO webdriver: RESULT { 'element-6066-11e4-a52e-4f735466cecf': 'f0736c61-735d-4cc8-82e1-1fd1e0f47b39' }
[0-0] 2019-12-26T06:14:22.766Z INFO webdriver: COMMAND findElementFromElement("f0736c61-735d-4cc8-82e1-1fd1e0f47b39", "xpath", ".//table[@role='presentation']")
[0-0] 2019-12-26T06:14:22.766Z INFO webdriver: [POST] http://127.0.0.1:4444/session/3f354aaa54fb0ffee1fdf547ad3d9b04/element/f0736c61-735d-4cc8-82e1-1fd1e0f47b39/element
[0-0] 2019-12-26T06:14:22.766Z INFO webdriver: DATA { using: 'xpath', value: './/table[@role=\'presentation\']' }
[0-0] 2019-12-26T06:14:22.778Z INFO webdriver: RESULT { 'element-6066-11e4-a52e-4f735466cecf': 'ab53a7ad-fc8d-4081-810d-745b001fad02' }
[0-0] 2019-12-26T06:14:22.779Z INFO webdriver: COMMAND findElementFromElement("ab53a7ad-fc8d-4081-810d-745b001fad02", "css selector", "#email")
[0-0] 2019-12-26T06:14:22.780Z INFO webdriver: [POST] http://127.0.0.1:4444/session/3f354aaa54fb0ffee1fdf547ad3d9b04/element/ab53a7ad-fc8d-4081-810d-745b001fad02/element
[0-0] 2019-12-26T06:14:22.780Z INFO webdriver: DATA { using: 'css selector', value: '#email' }
[0-0] 2019-12-26T06:14:22.789Z INFO webdriver: RESULT { 'element-6066-11e4-a52e-4f735466cecf': '090696e4-585f-442c-a39d-dfe98f4d5d78' }
[0-0] 2019-12-26T06:14:22.791Z INFO webdriver: COMMAND elementClear("090696e4-585f-442c-a39d-dfe98f4d5d78")
[0-0] 2019-12-26T06:14:22.791Z INFO webdriver: [POST] http://127.0.0.1:4444/session/3f354aaa54fb0ffee1fdf547ad3d9b04/element/090696e4-585f-442c-a39d-dfe98f4d5d78/clear
[0-0] 2019-12-26T06:14:22.817Z INFO webdriver: COMMAND elementSendKeys("090696e4-585f-442c-a39d-dfe98f4d5d78", "123")
[0-0] 2019-12-26T06:14:22.817Z INFO webdriver: [POST] http://127.0.0.1:4444/session/3f354aaa54fb0ffee1fdf547ad3d9b04/element/090696e4-585f-442c-a39d-dfe98f4d5d78/value
[0-0] 2019-12-26T06:14:22.817Z INFO webdriver: DATA { text: '123' }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  JS Function
&lt;/h2&gt;

&lt;p&gt;WebdriverIO supports JS selector/locator to find the elements using a JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$(function() {return &amp;lt;JS script&amp;gt;})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const assert = require("assert");

describe("Selector Example", function() {
   it("Open URL", function() {
       driver.url("https://www.lambdatest.com/");
   });

   it("JS Function Example", function() {
       const elem = $("//*[@id='navbarSupportedContent']/ul/li[1]");
       console.log(
           elem
               .$(function() {
                   return this.nextSibling.nextSibling;
               })
               .getText()
       );
   });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Web Elements stored in the variable and then JS functions call with help if $(). It converted internally executeScript().&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[0-0] 2019-12-25T18:49:26.477Z INFO webdriver: COMMAND executeScript(&amp;lt;fn&amp;gt;, &amp;lt;object&amp;gt;)
[0-0] 2019-12-25T18:49:26.477Z INFO webdriver: [POST] http://127.0.0.1:4444/session/7ad49103a958fbdf72f36aa974c04f39/execute/sync
[0-0] 2019-12-25T18:49:26.477Z INFO webdriver: DATA { script: 'return (function (elem) {\n    return (function () {\n\t\t\t\t\treturn this.nextSibling.nextSibling;\n\t\t\t\t}).call(elem);\n  }).apply(null, arguments)',
 args:
  [ { 'element-6066-11e4-a52e-4f735466cecf': 'b6cb6661-b048-418f-b1f8-58ed3f9836fe',
      ELEMENT: 'b6cb6661-b048-418f-b1f8-58ed3f9836fe' } ] }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  React Selector
&lt;/h2&gt;

&lt;p&gt;React is another one of the advanced locators in WebdriverIO which has been provided to create custom react components for mobile apps. WebDriverIO has provided a feature that you can directly find an element using the react$() method.&lt;/p&gt;

&lt;p&gt;react$$() method helps to find an array of WebDriverIO elements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;react$(‘ReactComponent’);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Let’s understand by below React Native Example:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import ReactDOM from 'react-dom'

function RootComponent() {
   return (
       &amp;lt;div&amp;gt;
           RootComponent
       &amp;lt;/div&amp;gt;
   )
}
function App() {
   return (&amp;lt;RootComponent /&amp;gt;)
}
ReactDOM.render(&amp;lt;App /&amp;gt;, document.querySelector('#root'))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the above example, ‘&lt;strong&gt;RootComponent&lt;/strong&gt;’ is a react component and when it renders within HTML element with id=’root’.&lt;/p&gt;

&lt;p&gt;This RootComponent can be found by react$() and below is the example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const rootComponent = browser.react$(‘RootComponent’);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Custom Selector
&lt;/h2&gt;

&lt;p&gt;One of the most convenient Selenium locators/ selectors in WebdriverIO which comes handy when facing complex scenarios for Selenium automation testing. The Custom selector allows you to use a customized strategy declared by using browser.addLocatorStrategy.&lt;/p&gt;

&lt;p&gt;custom$$() method helps to find an array of WebDriverIO elements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;browser.custom$(strategyName, strategyArguments)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const assert = require("assert");
describe("Selector Example", function() {

   it("Open URL", function() {
       driver.url("https://www.facebook.com/");
   });

   it("Custom Selector Example - ", () =&amp;gt; {
       browser.addLocatorStrategy("emailById", selector =&amp;gt; {
           return document.querySelectorAll(selector);
       });
       const emailID = browser.custom$("emailById", "#email");
emailID.setValue("abc@test.com");
   });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;With the help of addLocatorStrategy(), we have created ‘&lt;strong&gt;emailById&lt;/strong&gt;’ custom selector for the email ID field and we can use &lt;strong&gt;emailById&lt;/strong&gt; selector using the custom$() method. Internally, WebDriverIO converts custom$() into executeScript() and finds the element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In this WebdriverIO tutorial, we have discussed single $() which helps to deal with a single element. All these selectors can be used with $$() for the array of WebDriverIO.&lt;/p&gt;

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

&lt;p&gt;WebDriverIO is one of the top JavaScript testing frameworks and when you look at the variety it offers for you to locate elements in a web page, you would be sure to make a note of it for your upcoming projects. It has a very unique selector choice including react$ and custom$ selectors. WebDriverIO has single way to find the element but has different signs for selector e.g * , *=, .(period) and # different. I am sure that this WebdriverIO tutorial will help you to take your knowledge on test automation to the next step. Happy testing! 🙂&lt;/p&gt;

</description>
      <category>webdriver</category>
      <category>tutorial</category>
      <category>selenium</category>
      <category>locator</category>
    </item>
    <item>
      <title>Desired Capabilities in Selenium Webdriver</title>
      <dc:creator>Ramit Dhamija</dc:creator>
      <pubDate>Wed, 21 Sep 2022 09:59:04 +0000</pubDate>
      <link>https://forem.com/testmuai/desired-capabilities-in-selenium-webdriver-b8</link>
      <guid>https://forem.com/testmuai/desired-capabilities-in-selenium-webdriver-b8</guid>
      <description>&lt;p&gt;Desired Capabilities is a class used to declare a set of basic requirements such as combinations of browsers, operating systems, browser versions, etc. to perform automated cross browser testing of a web application.&lt;/p&gt;

&lt;p&gt;When we try to automate our test scripts through &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium automation testing&lt;/a&gt;, we need to consider these combinations to declare a specific test environment over which our website or web application should render seamlessly.&lt;/p&gt;

&lt;p&gt;These environments can be mobile devices, mobile browsers, desktop devices, desktop browsers, screen resolutions, etc. To declare these environments in our Selenium automation testing script, we make use of the &lt;a href="https://www.lambdatest.com/support/docs/selenium-automation-capabilities/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Desired Capabilities in Selenium&lt;/a&gt; testing or Appium testing and this is exactly what we will be discussing in this article.&lt;/p&gt;

&lt;p&gt;I will help you become familiar with the Desired Capabilities in Selenium testing and Desired Capabilities for Appium too. I will show you what they are, how they are used for Selenium automation testing and Appium testing with examples. Without further ado, let’s get started.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Also, If you wish to perform browser &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=hashnode&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;test automation cloud&lt;/a&gt; on the most powerful cloud infrastructure. Leverage LambdaTest automation testing for faster, reliable, and scalable experience on cloud.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What Are Desired Capabilities?
&lt;/h2&gt;

&lt;p&gt;Desired Capabilities class is a component of the org.openqa.selenium.remote.DesiredCapabilities package. It helps &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=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt; set the properties for the browsers. So using different capabilities from Desired Capabilities class we can set the properties of browsers. For example, the name of the browser, the version of the browser, etc. We use these capabilities as key-value pairs to set them for browsers.&lt;/p&gt;

&lt;p&gt;You can refer to the github library for the Desired Capabilities for all the detailed methods and etc.&lt;/p&gt;

&lt;p&gt;While working with Selenium automation testing, we always have different requirements while execution specifically about which browser to execute, which operating system and version to use for test execution, this where Desired Capabilities helps us a lot on Selenium Grid.&lt;/p&gt;

&lt;p&gt;To declare Desired Capabilities in Selenium automation testing using Grid, we can use the &lt;strong&gt;setCapability method&lt;/strong&gt; from the DesiredCapabilities class to set the different types of capabilities of the browser (Ex. Chrome, IE, Firefox, Edge) platform name (Ex. Windows, macOS, etc.).&lt;/p&gt;

&lt;p&gt;Desired Capabilities in Appium is useful in the case of mobile application automation, where we have to &lt;a href="https://www.lambdatest.com/blog/all-you-need-to-know-about-automation-testing-life-cycle/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;execute test automation&lt;/a&gt; on different browser properties and device properties, which we can set using Desired Capabilities class. To &lt;a href="https://www.lambdatest.com/blog/17-key-benefits-of-automation-testing-for-a-successful-release/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;leverage automation testing&lt;/a&gt; for different types of mobile devices, the different kinds of mobile platforms like iOS, Android, etc. Also, there can be different platform (operating system) versions like for Android 9.x, 10.x and for iOS 12.x, 13.x, etc, we can set these properties using Desired Capabilities in Appium for Android or iOS as per our requirement.&lt;/p&gt;

&lt;p&gt;This certification is ideal for testing professionals who want to acquire advanced, hands-on knowledge in Selenium automation testing.&lt;/p&gt;

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

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

&lt;h2&gt;
  
  
  There Is More To Desired Capabilities In Selenium And Appium
&lt;/h2&gt;

&lt;p&gt;Using Desired Capabilities class, we instruct the WebDriver about the environment like browser name, browser version, platform, etc. over which we perform &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automated browser testing&lt;/a&gt; using our automation scripts. But that is not all we can do using the Desired Capabilities class. We can also configure browser-specific preferences such as enabling chrome options, firefox options, testing with incognito mode or even disabling javascript, etc.&lt;/p&gt;

&lt;p&gt;If you are using a cloud-based &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online Selenium grid&lt;/a&gt;, then the Desired Capabilities class can also be used to perform &lt;a href="https://www.lambdatest.com/blog/speed-up-automated-parallel-testing-in-selenium-with-testng/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing with Selenium&lt;/a&gt; or Appium, &lt;a href="https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;testing locally hosted web applications with Selenium&lt;/a&gt;, generating command-by-command screenshots, or even a video recording of the entire test automation execution over different browsers + OS configurations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Try an online &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;selenium testing&lt;/a&gt; to run your browser automation testing scripts. Our cloud infrastructure has 3000+ desktop &amp;amp; mobile environments.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Types Of Desired Capabilities Methods
&lt;/h2&gt;

&lt;p&gt;Now, let us discuss the different methods available in Desired Capabilities class to set the different properties in test automation.&lt;/p&gt;

&lt;h3&gt;
  
  
  getCapability()
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public java.lang.Object getCapability(java.lang.String capabilityName)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This method &lt;strong&gt;getCapability()&lt;/strong&gt; from the class Desired Capabilities, which can be used to get the capabilities of the current system which we are using.&lt;/p&gt;

&lt;h3&gt;
  
  
  setCapability()
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public java.lang.Object setCapability(java.lang.String capabilityName)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This method &lt;strong&gt;setCapability()&lt;/strong&gt; from the class Desired Capabilities, can be used to set the name of device, name of platform, version of platform, absolute path of the application which is under test, application activity (in Mobile automation), application Package (in Java) and etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  getBrowserName():
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public java.lang.String getBrowserName()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This method &lt;strong&gt;getBrowserName()&lt;/strong&gt; from the class Desired Capabilities, can be used to get the name of the Browser.&lt;/p&gt;

&lt;h3&gt;
  
  
  setBrowserName()
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void setBrowserName(java.lang.String browserName)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This method &lt;strong&gt;setBrowserName()&lt;/strong&gt; from the class Desired Capabilities, can be used to set the name of the Browser.&lt;/p&gt;

&lt;h3&gt;
  
  
  getVersion()
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public java.lang.String getVersion()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This method &lt;strong&gt;getVersion()&lt;/strong&gt; from the class Desired Capabilities, can be used to get the version of the browser or platform.&lt;/p&gt;

&lt;h3&gt;
  
  
  setVersion()
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void setVersion(java.lang.String version)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This method &lt;strong&gt;setVersion()&lt;/strong&gt; from the class Desired Capabilities, can be used to set the version of the browser or platform.&lt;/p&gt;

&lt;h3&gt;
  
  
  getPlatform()
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public Platform getPlatform()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This method &lt;strong&gt;getPlatform()&lt;/strong&gt; from the class Desired Capabilities, can be used to get the details of the platform.&lt;/p&gt;

&lt;h3&gt;
  
  
  setPlatform()
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public Platform setPlatform()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This method &lt;strong&gt;setPlatform()&lt;/strong&gt; from the class Desired Capabilities, can be used to set the details of the platform.&lt;/p&gt;

&lt;p&gt;For more information, you can refer to Selenium documentation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Desired Capabilities In Selenium Testing For Different Browsers
&lt;/h2&gt;

&lt;p&gt;In the above section, we have seen different methods of Desired Capabilities class. Now, let us discuss how we can set different capabilities for different browsers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Desired Capabilities in Selenium WebDriver for Chrome
&lt;/h2&gt;

&lt;p&gt;When we want to customize and configure the Desired Capabilities in Selenium WebDriver for Chrome, we need to invoke the ChromeDriver session to leverage these capabilities. So let us discuss capabilities that are supported by ChromeDriver and how we can use them to set those desired capabilities in Selenium Webdriver for Chrome.&lt;/p&gt;

&lt;p&gt;There are two ways to set the capabilities for ChromeDriver.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;ChromeOptions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Desired Capabilities&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;ChromeOptions is another class that can be used in conjunction with Desired Capabilities in Selenium WebDriver for Chrome to customize or manipulate the various properties of Chrome browser.&lt;br&gt;
Following are the commonly used arguments from ChromeOptions class&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disable-infobars:&lt;/strong&gt; It is used to prevent chrome browser from displaying notifications like “Chrome is being controlled by automated software”.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Make-default-browser:&lt;/strong&gt; It is used to make the chrome browser as default browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disable-popup-blocking:&lt;/strong&gt; It is used to disable the pop-ups which are displayed on chrome browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Incognito:&lt;/strong&gt; It opens chrome browser in incognito mode&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;start -maximized:&lt;/strong&gt; It opens chrome browser in maximized mode&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Headless:&lt;/strong&gt; It is used to open the chrome browser in headless mode.&lt;/p&gt;

&lt;p&gt;Now, let us discuss an example of an ad blocker where Chrome Option is used in conjunction with Desired Capabilities class. We will use an adblocker extension for this purpose.&lt;br&gt;
Prerequisite for that a &lt;strong&gt;crx file&lt;/strong&gt; of the extension should be downloaded.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Setting up capabilities to run our test script
ChromeOptions opt = new ChromeOptions();

opt.addExtensions(new File(“path for crx file of the extension”));

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(ChromeOptions.CAPABILITY, options);

ChromeDriver driver = new ChromeDriver(capabilities);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Desired Capabilities in Selenium WebDriver for Firefox
&lt;/h2&gt;

&lt;p&gt;Like we have seen in the case of the Chrome browser, there are also ways to customize the Desired Capabilities in Selenium WebDriver for Firefox browsers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;moz:firefoxOptions&lt;/strong&gt; capability is available specifically for Firefox browser. We can use &lt;strong&gt;moz:firefoxOptions&lt;/strong&gt; to customize or manipulate different properties of the Firefox browser, which helps us to control the behavior of the Firefox browser. It is usually invoked as a member in either of the two, one is from &lt;strong&gt;alwaysMatch&lt;/strong&gt; and the other is from &lt;strong&gt;firstMatch&lt;/strong&gt; entries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;moz:firefoxOptions&lt;/strong&gt; can contain the following things that can control how Firefox browser starts or runs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a) binary(String):&lt;/strong&gt; We provide absolute path for the custom Firefox binary to use. Normally, GeckoDriver which is driver that we use for Firefox tries to find the location of Firefox on the current system if it is not defined.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;b) args(array of strings):&lt;/strong&gt; This argument is used to pass the command line arguments to the Firefox binary. While using this syntax should contain, hyphen/dash like [“-profile”].&lt;br&gt;
So to pick up the existing profile by GeckoDriver, we should use syntax like&lt;br&gt;
[“-profile”, “path to the profile”]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;c) profile(string):&lt;/strong&gt; We can provide the path for the directory so that Firefox instance can be used. For installing some firefox extensions or some custom certificates, we can use this. While it is recommended to use prefs while we want to set the custom preferences, instead of directly passing the profile. You can find the example of prefs below along with others.&lt;/p&gt;

&lt;p&gt;Here is an example of declaring Desired Capabilities in Selenium WebDriver for Firefox.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
      "capabilities": {
        "alwaysMatch": {
          "moz:firefoxOptions": {
            "binary": "/usr/local/firefox/bin/firefox",
            "args": ["-headless", "-profile", "/path/to/my/profile"],
            "prefs": {
              "dom.ipc.processCount": 9,
              "javascript.options.showInConsole": true
            },
            "log": {"level": "trace"}
          }
        }
      }
    }
if(driverParameter == null || driverParameter.equalsIgnoreCase(FIREFOX))
{
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    FirefoxOptions options = new FirefoxOptions();
    options.setHeadless(headless);
    capabilities.merge(options);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Desired Capabilities in Selenium WebDriver for IE(Internet Explorer)
&lt;/h2&gt;

&lt;p&gt;Now, let us proceed with Desired Capabilities in Selenium WebDriver for IE(Internet Explorer). For IE, we make use of &lt;strong&gt;InternetExplorerOptions&lt;/strong&gt; with &lt;strong&gt;Desired Capabilities in Selenium WebDriver&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here is an example of declaring Desired Capabilities in Selenium WebDriver for IE.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(driverParameter == null || driverParameter.equalsIgnoreCase(IE))
{
    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
    capabilities.setCapability("requireWindowFocus", true);
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;There are few Internet Explorer specific capabilities which we can use, let us discuss some of them one by one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a) ignoreZoomSetting(boolean):&lt;/strong&gt; This capability can be used to ignore checking of the browser’s zoom level to 100%. By default, it is set as false. It takes a boolean value as input.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;b) initialBrowserUrl(string):&lt;/strong&gt; Using this capability we can decide initial URL, website to which it should redirect while internet explorer browser starts. It takes a string as input.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;c) enableElementCacheCleanup(boolean):&lt;/strong&gt; This capability provides a check over the obsolete elements from element cache. If they are found then the capability instructs the WebDriver to clean up. It takes a boolean value as input.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;d) requireWindowFocus(boolean):&lt;/strong&gt; This capability is used for instructing the driver to check that the internet explorer window has the focus before performing any operations like a mouse or keyboard events etc. It takes a boolean value as input and by default, it is set as false.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;e) ignoreProtectedModeSettings(boolean):&lt;/strong&gt; If you wish to skip past the protected mode check while performing Selenium automation testing then you can leverage this capability. It takes a boolean value as input.&lt;/p&gt;

&lt;p&gt;So these are some of the Internet Explorer specific capabilities which we can use.&lt;/p&gt;
&lt;h2&gt;
  
  
  Examples Of Desired Capabilities In Selenium Testing With Different Languages
&lt;/h2&gt;

&lt;p&gt;Now, I will demonstrate to you how to leverage Desired Capabilities in Selenium testing with different languages. As you may already know, Selenium automation testing is supported by multiple programming languages. It offers bindings for every major programming language i.e. JavaScript, C#, Python, Java, Ruby, PHP. To give you a gist of how you can leverage the desired capabilities in Selenium testing, I will be giving examples for Java, C#, and Python.&lt;/p&gt;
&lt;h2&gt;
  
  
  Desired Capabilities in Selenium WebDriver for Java
&lt;/h2&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Setting up capabilities to run our test script
    @BeforeClass
        public void setUp() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", "chrome");
        capabilities.setCapability("version", "77.0");
        capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get any available one
        capabilities.setCapability("build", "LambdaTestSampleApp");
        capabilities.setCapability("name", "LambdaTestJavaSample");
        capabilities.setCapability("network", true); // To enable network logs
        capabilities.setCapability("visual", true); // To enable step by step screenshot
        capabilities.setCapability("video", true); // To enable video recording
        capabilities.setCapability("console", true); // To capture console logs

 capabilities.setCapability("selenium_version","4.0.0-alpha-2");
         capabilities.setCapability("timezone","UTC+05:30");
         capabilities.setCapability("geoLocation","IN");
         capabilities.setCapability("chrome.driver","78.0");
        try {
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
        } catch (MalformedURLException e) {
            System.out.println("Invalid grid URL");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Desired Capabilities in Selenium WebDriver for C
&lt;/h2&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Accept all certificates Chrome 
DesiredCapabilities capability = DesiredCapabilities.Chrome();
Environment.SetEnvironmentVariable("webdriver.chrome.driver", "Path to ChromeDriver.exe");
capability.SetCapability(CapabilityType.AcceptSslCertificates, true);
IWebDriver driver = new RemoteWebDriver(capability);

//Set Chrome options.
ChromeOptions options = new ChromeOptions();
DesiredCapabilities dc = DesiredCapabilities.Chrome();
dc.SetCapability(ChromeOptions.Capability, options);
IWebDriver driver = new RemoteWebDriver(dc);

//Turn off the JavaScript Firefox
FirefoxProfileManager profileManager = new FirefoxProfileManager();
FirefoxProfile profile = profileManager.GetProfile("TestProfile");
profile.SetPreference("javascript.enabled", false);
IWebDriver driver = new FirefoxDriver(profile);

//Set the default page load timeout
driver.Manage().Timeouts().SetPageLoadTimeout(new TimeSpan(10));

//Start Firefox with plugins
FirefoxProfile prof = new FirefoxProfile();
profile.AddExtension(@"C:Location of extension.xpi");
IWebDriver driver = new FirefoxDriver(prof);

//Start Chrome with an unpacked extension
ChromeOptions options = new ChromeOptions();
options.AddArguments("load-extension=/pathTo/extension");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability(ChromeOptions.Capability, options);
DesiredCapabilities dc = DesiredCapabilities.Chrome();
dc.SetCapability(ChromeOptions.Capability, options);
IWebDriver driver = new RemoteWebDriver(dc);

//Start Chrome with a packed extension
ChromeOptions options = new ChromeOptions();
options.AddExtension(Path.GetFullPath("localpathto/extension.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability(ChromeOptions.Capability, options);
DesiredCapabilities dc = DesiredCapabilities.Chrome();
dc.SetCapability(ChromeOptions.Capability, options);
IWebDriver driver = new RemoteWebDriver(dc);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Desired Capabilities in Selenium WebDriver for Python
&lt;/h2&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def _get_desired_capabilities():
    """
    """
    platform = _TEST_SETTINGS['PLATFORM']
    browser = _TEST_SETTINGS['BROWSER']
    version = _TEST_SETTINGS['VERSION']

    if platform and browser:
        capabilities = {
            'platform': platform,
            'browserName': browser,
            'version': version,
        }
    elif browser.lower() == 'firefox':
        capabilities = DesiredCapabilities.FIREFOX
    else:
        capabilities = DesiredCapabilities.CHROME

    return _add_travis_info(capabilities)


def run_browser(self,os_name,os_version,browser,browser_version):

        USERNAME = ‘test.lambdatest@gmail.com’
        PASSWORD = ‘Test123’
        if browser.lower() == 'ff' or browser.lower() == 'firefox':
            desired_capabilities = DesiredCapabilities.FIREFOX            
        elif browser.lower() == 'ie':
            desired_capabilities = DesiredCapabilities.INTERNETEXPLORER
        elif browser.lower() == 'chrome':
            desired_capabilities = DesiredCapabilities.CHROME            
        elif browser.lower() == 'opera':
            desired_capabilities = DesiredCapabilities.OPERA        
        elif browser.lower() == 'safari':
            desired_capabilities = DesiredCapabilities.SAFARI

        desired_capabilities['os'] = os_name
        desired_capabilities['os_version'] = os_version
        desired_capabilities['browser_version'] = browser_version

     return webdriver.Remote(RemoteConnection("http://%s:%s@hub-cloud.browser.com/wd/hub"%(USERNAME,PASSWORD),resolve_ip= False),
            desired_capabilities=desired_capabilities)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Setting Selenium Capabilities with LambdaTest Capabilities Generator
&lt;/h2&gt;

&lt;p&gt;Lambdatest is a cloud-based cross browser testing tool, which allows you to execute Selenium automation testing on an online Selenium Grid of 2000+ real browsers. All the languages and frameworks supported by Selenium are compatible with LambdaTest.&lt;/p&gt;

&lt;p&gt;Being an online Selenium Grid as a Service provider we understand the importance of DesiredCapabilities in your Selenium automation testing experience. We also understand that it can take a considerable amount of time to write down your Desired Capabilities every time to run your tests on hundreds of browsers + OS combinations. This is why we have come up with an online &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Desired Capabilities Generator&lt;/a&gt; which provides you the DesiredCapabilities class for multiple programming languages based upon your point-and-click selection.&lt;/p&gt;

&lt;p&gt;So, when we navigate to the capabilities generator from LambdaTest using the above URL you can see a screen as 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%2An5RKQOoIxv4D8AVZ.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%2An5RKQOoIxv4D8AVZ.png" width="800" height="426"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see in the above screenshot, we can select the properties which we want to use in our test script and after selecting the required information it generates respective desired capabilities.&lt;br&gt;
The following screen shows the generated capabilities which we can directly use in our test script.&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%2Fdqfvg1vc4hcwl15biaor.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%2Fdqfvg1vc4hcwl15biaor.png" width="800" height="312"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Did you notice that we used the Desired Capabilities in Selenium 4? If you look at the above image you will find that the point-and-click selections from drop-downs are made under the tab for Selenium 4.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check out this online &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium automation&lt;/a&gt; Grid to run your browser automation testing scripts. Try for free now!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Selenium 4 Desired Capabilities On LambdaTest Capabilities Generator
&lt;/h2&gt;

&lt;p&gt;That is another great benefit of using LambdaTest as an online Selenium Grid. You get the latest browsers, browser versions, operating systems pre-installed on machines hosted on our cloud servers. That is not all! You also get the latest Selenium 4 desired capabilities all ready to fire up in your automated browser testing scripts.&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%2F2706%2F0%2AsNG7YZLKo4qJ5JdM.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%2F2706%2F0%2AsNG7YZLKo4qJ5JdM.png" width="800" height="309"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Example Script Incorporating Desired Capabilities In Selenium Testing
&lt;/h2&gt;

&lt;p&gt;Now, let’s take a quick example to demonstrate how to fit in these desired capabilities in Selenium automation testing scripts. So as we are ready with generating desired capabilities that we want, we have used that in the following test script which we can execute on multiple browsers to perform cross browser testing on 2000+ real browsers using Selenium Grid offered by LambdaTest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example automation script:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.lambdatest;


//TestNG Todo : Sample App
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.testng.asserts.Assertion;

import com.beust.jcommander.Parameter;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;
import java.util.concurrent.TimeUnit;

public class Test2{

    public String username = "Your_LambdaTest_Username";
    public String accesskey = "Your_LambdaTest_Access_Key";
    public static RemoteWebDriver driver = null;
    public String gridURL = "@hub.lambdatest.com/wd/hub";
    boolean status = false;


    //Setting up capabilities to run our test script
    @Parameters(value= {"browser","version"})
    @BeforeClass
    public void setUp(String browser, String version) throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", browser);
        capabilities.setCapability("version", version);
        capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
        capabilities.setCapability("build", "LambdaTestSampleApp");
        capabilities.setCapability("name", "LambdaTestJavaSample");
        capabilities.setCapability("network", true); // To enable network logs
        capabilities.setCapability("visual", true); // To enable step by step screenshot
        capabilities.setCapability("video", true); // To enable video recording
        capabilities.setCapability("console", true); // To capture console logs

         capabilities.setCapability("selenium_version","4.0.0-alpha-2");
         capabilities.setCapability("timezone","UTC+05:30");
         capabilities.setCapability("geoLocation","IN");
         capabilities.setCapability("chrome.driver","78.0");


        try {
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
        } catch (MalformedURLException e) {
            System.out.println("Invalid grid URL");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }

    //Opening browser with the given URL and navigate to Registration Page
    @BeforeMethod
    public void openBrowser()
    {
 //     driver.manage().deleteAllCookies();

        driver.get("https://www.lambdatest.com/");

        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);

        WebElement signUpButton = driver.findElement(By.xpath("//a[contains(text(),'Start Free Testing')]"));
        signUpButton.click(); 

    }

    //Verifying elements on Registration page
    @Test
    public void verifyElementsOnPageTest()
    {
        WebElement lambdaTestLogo = driver.findElement(By.xpath("//p[@class='signup-titel']"));
        lambdaTestLogo.isDisplayed();

        WebElement signUpTitle = driver.findElement(By.xpath("//p[@class='signup-titel']"));
        signUpTitle.isDisplayed();

        WebElement termsText = driver.findElement(By.xpath("//label[@class='woo']"));
        termsText.isDisplayed();

        WebElement loginLinkText = driver.findElement(By.xpath("//p[@class='login-in-link test-left']"));
        loginLinkText.isDisplayed();

    }  

    // Closing the browser session after completing each test case
    @AfterClass
    public void tearDown() throws Exception {
       if (driver != null) {
            ((JavascriptExecutor) driver).executeScript("lambda-status=" + status);
            driver.quit();
        }
    }
}



&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd"&amp;gt;
&amp;lt;suite thread-count="3" name="LambaTestSuite" parallel="tests"&amp;gt;

  &amp;lt;test name="ChromeTest"&amp;gt;
  &amp;lt;parameter name="browser" value="chrome"/&amp;gt;
  &amp;lt;parameter name="version" value="77.0"/&amp;gt;
    &amp;lt;classes&amp;gt;
      &amp;lt;class name="com.lambdatest.Test2"/&amp;gt;
    &amp;lt;/classes&amp;gt;
  &amp;lt;/test&amp;gt; &amp;lt;!-- Test --&amp;gt;


&amp;lt;/suite&amp;gt; &amp;lt;!-- Suite --&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Output On The LambdaTest Automation Dashboard&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After executing the above script on the online Selenium Grid of LambdaTest, we get the below automation logs over the automation dashboard at LambdaTest. You get different types of logs under the automation dashboard i.e. Network logs, Command logs, Metadata, Video recording, Screenshots, etc. In the below screenshot I want you to focus on the raw Selenium Logs offered by LambdaTest.&lt;/p&gt;

&lt;p&gt;You can notice that the capabilities declared in the automation scripts are displayed there.&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%2AbE1hHNYWnwPO2gNR.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%2AbE1hHNYWnwPO2gNR.png" width="800" height="411"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Desired Capabilities In Appium For Mobile Automation
&lt;/h2&gt;

&lt;p&gt;Till now we have seen desired capabilities with different languages, browsers and different methods available for capabilities. And I hope by far, you have had a good idea on how to use Desired Capabilities in Selenium automation testing. However, Selenium automation testing can only ensure your web application for desktop devices but your customers may be using their mobiles for accessing your web application or website, especially your blog page.&lt;/p&gt;

&lt;p&gt;We are living in a mobile-first era. The automated browser testing over &lt;strong&gt;desktops only&lt;/strong&gt; cannot ensure you that your &lt;a href="https://www.lambdatest.com/blog/how-to-make-a-cross-browser-compatible-website/" rel="noopener noreferrer"&gt;website is cross browser compatible&lt;/a&gt;. Almost every business is going digital, so it requires a website or a web application to be both desktop and mobile-ready. This means that you may have to perform automated browser testing over mobile browsers too!&lt;/p&gt;

&lt;p&gt;How can we perform automated browser testing for mobile browsers then? The good news is that there is another spectacular open-source framework to help you out with that purpose and it is called Appium.&lt;/p&gt;

&lt;p&gt;Now, we will discuss the Appium testing, how we can use desired capabilities in Appium.&lt;/p&gt;

&lt;p&gt;So there can be different requirements for platform or operating system (like Android, iOS), platform version, device, etc. which are similar to what we do in case of web application automation. This is where the desired capabilities in Appium come into play for automated browser testing for mobile web-applications.&lt;/p&gt;

&lt;p&gt;Looking to automate mobile apps on real devices, check out our video below –&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Example For Desired Capabilities In Appium Testing
&lt;/h2&gt;

&lt;p&gt;When a new automation session is requested, Appium client sends request to server with JSON object which includes Desired Capabilities in the form of key and value pairs.&lt;/p&gt;

&lt;p&gt;Using these key and values from JSON object, we provide decide and instruct appium drivers about how we want our mobile automation test to work.&lt;/p&gt;

&lt;p&gt;Desired Capabilities can then be set within a server of Appium or we can also add it in our Webdriver test script.&lt;/p&gt;

&lt;p&gt;Following is an example for desired capabilities in Appium testing using a JSON object:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
   “platformName”: “Android”,
    “platformVersion”: “10.0”,
    “deviceName”:  “Samsung Galaxy s10”,
    “automationName”: “Appium”,
    “app”: “path for the app under test”
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;So using above desired capabilities in Appium testing through a JSON object, we are instructing drivers to start our mobile automation session on device Samsung Galaxy s10 with Android version 10.0 using Appium and for the app with the given file location.&lt;/p&gt;

&lt;p&gt;There are different desired capabilities Appium supports, out of which some capabilities are common for all the platform or drivers, while some are driver or platform-specific. Let us discuss some of them as we proceed further.&lt;/p&gt;

&lt;h2&gt;
  
  
  General or Standard Desired Capabilities in Appium Testing
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;automationName:&lt;/strong&gt; Using this capability we can instruct driver about which automation engine it should use. By default, it is set as Appium. Other available engines like Appium, Espresso (both are for android), XCUITest (for iOS)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;platformName:&lt;/strong&gt; We can use this to instruct about the mobile operating system platform like iOS, Android, etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;platformVersion&lt;/strong&gt;: We can use this for mentioning the mobile operating system version on which test expect to execute.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;deviceName:&lt;/strong&gt; We can use this to specify the particular mobile device over which we wish to perform automated browser testing. Like we have used Samsung Galaxy s10 in the above example.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;app:&lt;/strong&gt; This capability is used to provide the path of our application which needs to be tested with script. Here we provide an absolute local path or remote path with HTTP URL.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;browserName:&lt;/strong&gt; This can be used when we want to execute a test on mobile web browser. We can provide the name of the browser like Safari for iOS, Chrome for Android, etc. It can be left empty when we want to automate app and not using browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;language:&lt;/strong&gt; This can be used to set the language of Android or iOS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;newCommandTimeout:&lt;/strong&gt; This capability helps to instruct driver for the time it has to wait for a new command from client before ending the idle session.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are few more general capabilities like noReset, fullReset, eventTimings, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  Desired Capabilities In Appium For Android
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;appActivity:&lt;/strong&gt; Use this capability to declare a name for an Android activity which you wish to launch from the package. E.g. .MainActivity, .Settings&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;appPackage:&lt;/strong&gt; Using this capability, we decide the JAva package of the Android app which we want to execute. By default package manifest provides this capability.&lt;br&gt;
E.g. com.example.android.testApp&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;**appWaitActity: **This capability provides name of android activity we want to wait.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;appWaitPackage:&lt;/strong&gt; This provides java package for android app which we want to wait for.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;appWaitDuration:&lt;/strong&gt; This capability used to instruct the wait in milliseconds for the appWaitActivity to launch.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;deviceReadyTimeout:&lt;/strong&gt; This capability instructs about timeout in seconds while driver is waiting for device under test to become ready.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Desired Capabilities In Appium For iOS
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;calendarFormat:&lt;/strong&gt; This capability can be used to set the calendar format for the iOS simulator. E.g. Gregorian&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;launchTimeout:&lt;/strong&gt; This capability instructs about the time in milliseconds upto which driver has to wait and after that it considers session as failed or hung.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;autoAcceptAlerts;&lt;/strong&gt; This capability is used to accept all the iOS alerts, if they popup while performing automated browser testing. Examples: privacy access permission alerts like location, contacts, etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;autoDismissAlerts:&lt;/strong&gt; This capability is used to decline/dismiss all the iOS alerts when they popup while performing automated browser testing. Examples: privacy access permission alerts like location, contacts, etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;safariInitialUrl:&lt;/strong&gt; Using this capability we can set the initial URL for safari browser, so it works as welcome page when browser launches.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;appName:&lt;/strong&gt; This capability used to display the name of application which is under test.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Apart from the above iOS capabilities, there are few more like safariAllowPopups, &lt;strong&gt;customSSLCert&lt;/strong&gt;, etc.&lt;/p&gt;

&lt;p&gt;So we have seen desired capabilities that we can use while creating a test with examples for different browsers, with different languages and we also discussed it for Appium with different platforms/operating systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  LambdaTest Capabilities Generator Offers Desired Capabilities In Appium
&lt;/h2&gt;

&lt;p&gt;LambdaTest Desired Capabilities Generator now provides the Appium capabilities as well. They can be found under the tab which says Appium. You can test over both Android and iOS browsers to ensure that your web application is working as perfectly as it should.&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%2F2696%2F0%2ASqqzaK8XrAJn5aPa.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%2F2696%2F0%2ASqqzaK8XrAJn5aPa.png" width="800" height="309"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What Have We Learned
&lt;/h2&gt;

&lt;p&gt;As we perform Selenium automation testing we need to declare a set of basic requirements regarding the test environment such as specific browsers, operating systems, and more. This is achieved using the Desired Capabilities class for Selenium testing and Appium testing.&lt;/p&gt;

&lt;p&gt;We can also specify the conditions over which we need to perform the test such as locally hosted testing, parallel testing, testing with javascript disabled and more.&lt;/p&gt;

&lt;p&gt;This Desired Capabilities class is generated with ease if you are already using LambdaTest through our Desired Capabilities Generator which offers you the class on the basis of your testing requirements from the drop-down menus.&lt;/p&gt;

&lt;p&gt;If you wish to perform Selenium automation testing for ensuring a wider browser compatibility testing then LambdaTest is your go-to store with all the latest browsers, operating systems, Selenium versions. Happy testing! 🙂&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>selenium</category>
      <category>webdriver</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to Automate Registration Page Using Selenium And Java</title>
      <dc:creator>Ramit Dhamija</dc:creator>
      <pubDate>Wed, 21 Sep 2022 08:52:21 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-automate-registration-page-using-selenium-and-java-3jmn</link>
      <guid>https://forem.com/testmuai/how-to-automate-registration-page-using-selenium-and-java-3jmn</guid>
      <description>&lt;p&gt;If you are just starting with Selenium automation testing of your product, the first page you would probably want to automate Registration page or Login Page. If you have an online platform like an ecommerce company or a Software-as-a-Service product, the Signup page acts as the door to welcome your web application visitors. It is one of the simplest yet one of the most important pages of your platform, and comes at the start of every possible user journey that you may want to test. Hence, it is also one of the most important web pages for your web application.&lt;/p&gt;

&lt;p&gt;So today, we are going deeper into How to Automate Registration Page Using Selenium. We are going to execute automation testing with Selenium and Java. In one of our previous &lt;a href="https://www.lambdatest.com/blog/selenium-java-tutorial-how-to-test-login-process/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Java tutorials&lt;/a&gt;, we demonstrated how to automate the login process using Selenium automation testing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Which are the most wanted &lt;a href="https://www.lambdatest.com/blog/automation-testing-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;tools for automation testing&lt;/a&gt; that have climbed the top of the ladder so far? Let’s take a look.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps Of How to Automate Registration Page Using Selenium
&lt;/h2&gt;

&lt;p&gt;Today, we will take an example of a Registration Page / Sign Up Page from LambdaTest. We will start our discussion with the test cases and process for automate registration page of LambdaTest and then move to the Automation part to see how we can increase our browser coverage for efficient &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; and accelerate automation testing through &lt;a href="https://www.lambdatest.com/blog/selenium-grid-setup-tutorial/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing on Selenium Grid&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Before moving forward, let’s look at the workflow in a bit more detail and see how &lt;a href="https://accounts.lambdatest.com/register?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Sign Up page of LambdaTest&lt;/a&gt; works.&lt;/p&gt;

&lt;p&gt;If you’re new to Selenium and wondering what it is then we recommend checking out our guide — &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;What is Selenium?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a first step, we enter URL &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;https://www.lambdatest.com&lt;/a&gt; in any browser to reach the landing page of the LambdaTest website. You can refer following screenshot for the landing page.&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%2Fksnu5tzx7w1wc4kgynp1.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%2Fksnu5tzx7w1wc4kgynp1.png" width="800" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From there we are going to click on &lt;strong&gt;‘Free Signup’&lt;/strong&gt; button and reach to the &lt;a href="https://accounts.lambdatest.com/register?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Registration page&lt;/a&gt; of the LambdaTest.&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%2AuqxQspT3fkK427_z.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%2AuqxQspT3fkK427_z.png" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, let us check the Functional fields on this Registration page and list them down.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Organization&lt;/strong&gt; / &lt;strong&gt;Company Name&lt;/strong&gt; (Text field)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Full Name&lt;/strong&gt; of the user (Text field)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Work Email&lt;/strong&gt; Id (Text field)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Desired Password&lt;/strong&gt; (Text field)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Phone&lt;/strong&gt; number of the user (Text field)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Terms and Privacy Policy&lt;/strong&gt; (checkbox)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Free Signup&lt;/strong&gt; (button)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  WorkFlow Of The Sign Up Page
&lt;/h2&gt;

&lt;p&gt;Enter all the required fields: Full Name, Work Email, Desired Password, Phone number, Terms and Privacy policy checkbox.&lt;/p&gt;

&lt;p&gt;Validate the fields:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Work email : Should not be an existing user, valid email.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Password : Should provide minimum required length for password.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Phone Number&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Terms and Privacy policy checkbox&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Till now, we have discussed all the basic things about the registration page, specifically related to the &lt;a href="https://accounts.lambdatest.com/register?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;registration page of LambdaTest&lt;/a&gt;. So let us proceed with &lt;a href="https://www.lambdatest.com/blog/17-lessons-i-learned-for-writing-effective-test-cases/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;writing test cases&lt;/a&gt; for this page.&lt;/p&gt;

&lt;p&gt;This certification demonstrates your knowledge of Selenium and Java, and your expertise at automating tests for any project.&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Here are the top 30 Top &lt;a href="https://www.lambdatest.com/blog/automation-testing-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Automation Testing Tools&lt;/a&gt; In 2022.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Possible Test Scenarios of the Sign Up Page
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Elements
&lt;/h2&gt;

&lt;p&gt;Check if all buttons, title, checkboxes are present on the page and if those are working by clicking on all buttons and checkboxes. In case of LambdaTest registration page, we should check the following buttons, text fields, terms and privacy policy checkbox, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;p&gt;Check if all the links present on the page are redirects to the expected pages.&lt;br&gt;
We also need to check if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;LambdaTest&lt;/strong&gt; link redirects to LambdaTest are launching the correct page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Terms of Service&lt;/strong&gt; link opens a new tab with redirection to the Terms of service page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Privacy Policy&lt;/strong&gt; link opens a new tab with redirection to the Privacy Policy page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Login&lt;/strong&gt; link redirects from registration page to login page.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Optional Fields
&lt;/h2&gt;

&lt;p&gt;In case of LambdaTest registration page, only optional is Organization or Company Name. So we shall try to register with and without providing Organization or Company name, and it should be possible to complete the registration in both the cases (considering user has provided all other information correctly).&lt;/p&gt;
&lt;h2&gt;
  
  
  Required Fields
&lt;/h2&gt;

&lt;p&gt;In case of LambdaTest registration page, we have the following required fields , so let us discuss about the cases related to each field.&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%2Fo7vxe6thv7cfz9kz4ucx.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%2Fo7vxe6thv7cfz9kz4ucx.png" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Full Name
&lt;/h3&gt;

&lt;p&gt;→ Verify without providing Full name, it should give the respective error and it should not be possible to proceed further the registration page.&lt;/p&gt;

&lt;p&gt;→ verify with providing Full name, it should be possible to complete the registration (considering user has provided all other information correctly).&lt;/p&gt;
&lt;h3&gt;
  
  
  Work Email
&lt;/h3&gt;

&lt;p&gt;→ Verify with valid email ID, but have an existing account on LambdaTest platform with that email ID, then in that case, it should not be allowed to register with that email ID and should give a respective error message (considering user has provided all other information correctly).&lt;/p&gt;

&lt;p&gt;→ Verify without providing any details in the Work Email field, it should not be allowed to register without any email ID and should give a respective error message.&lt;/p&gt;

&lt;p&gt;→ Verify with valid email ID, which does not have any account on LambdaTest platform with that email ID, so the user should be able to proceed and register successfully (considering user has provided all other information correctly).&lt;/p&gt;
&lt;h3&gt;
  
  
  Desired Password
&lt;/h3&gt;

&lt;p&gt;→ Verify without providing any password in the Desired Password field, it should give the respected error message to provide the password.&lt;/p&gt;

&lt;p&gt;→ As we can see that there is a minimum length of characters for the password is required, which is at least 8 characters are required. So we can make use of test design technique Boundary Value Analysis (BVA), as we have minimum criteria of 8 characters so we can test with lengths 7, 8 and 9 characters.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When it is less than 7 then it should give the error to the user and user can proceed to complete the registration process.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When it is 8 then it should be possible for the user to complete the registration process successfully without any error. (considering user has provided all other information correctly).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When it is 9 then also it should be possible for the user to complete the registration process successfully without any error. (considering user has provided all other information correctly).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Phone
&lt;/h3&gt;

&lt;p&gt;→ Verify without providing any phone number in the field, as it is also mandatory field so user should not be able to proceed and complete the registration without providing phone number.&lt;/p&gt;

&lt;p&gt;→ Verify with providing invalid phone number ( phone number with 2–3 digit), in this case also user should not be able to proceed and complete the registration with invalid providing phone number.&lt;/p&gt;

&lt;p&gt;→ Verify with providing valid phone number in the field, in this case the user should be able to register successfully with valid phone number (considering user has provided all other information correctly).&lt;/p&gt;
&lt;h3&gt;
  
  
  Terms of Service checkbox:
&lt;/h3&gt;

&lt;p&gt;→ Verify without checking Terms of Services checkbox, as it is required field in the registration process user can not proceed to complete the registration process without checking this checkbox.&lt;/p&gt;

&lt;p&gt;→ Verify with Terms of services checkbox is selected, then user can complete the registration successfully without any error (considering user has provided all other information correctly).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So we have seen till now&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;What are the fields generally present on the Registration Page, along with the example of registration page of LambdaTest.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Expected workflow of the registration page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test cases/scenarios for the Registration page&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  How to Automate Registration Page Using Selenium and Java
&lt;/h2&gt;

&lt;p&gt;So far in 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=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Java&lt;/a&gt; tutorial, you have established a fair understanding of what you need to test on the Signup page. With that in mind, let us roll into action and automate Registration page by performing Selenium automation testing with Java and TestNG.&lt;/p&gt;

&lt;p&gt;We will now come up with a Selenium automation scripts and execute it on an online Selenium Grid. We will also leverage the power of parallel testing to fast track our automated cross browser testing. But before all that, you should be ready with the below prerequisites.&lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before moving to the script, let us go through some basic prerequisites to write and execute Selenium Automation test script.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;JDK and JRE&lt;/strong&gt; — This is required to execute any Java program in our system. You can download it from the official website of Oracle.&lt;br&gt;
&lt;a href="https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html" rel="noopener noreferrer"&gt;https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Eclipse IDE&lt;/strong&gt; — We have used Eclipse to write our program or test script. You can download it from the official website of Eclipse or you can use any other IDE as per your choice.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Selenium Jars&lt;/strong&gt; — To write any Selenium automation testing script, it is required to have Selenium Jars in the project. You can download Selenium Jars from the official website of Selenium.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;TestNG Framework&lt;/strong&gt; — In the following test script we have used TestNG framework for Selenium automation testing which will help us in generating test reports, prioritizing test cases, grouping the test cases and also for parallel execution on different browsers.&lt;br&gt;
You can either download TestNG Jars or you can directly add it inside Eclipse from Eclipse Marketplace using the TestNG Eclipse URL or you may refer to TestNG to download.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the below example, we have integrated our test script with LambdaTest, a cross browser testing tool. Wondering why we are running our Selenium automation tests on cloud-based &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt; tool such as LambdaTest?&lt;/p&gt;

&lt;p&gt;Although, Selenium empowers you to automate your web application testing across different browsers. You can only perform Selenium automation testing on browsers installed on your machine where the local webdriver is running. Now, installing hundreds of browsers and maintaining the library for your inhouse Selenium infrastructure can be very strenous, not to forget, time-consuming too.&lt;/p&gt;

&lt;p&gt;This is why it is recommended to run Selenium automation testing on an online Selenium testing tool such as LambdaTest but that is not the only reason to it. LambdaTest is a lot more!&lt;/p&gt;
&lt;h2&gt;
  
  
  What is LambdaTest?
&lt;/h2&gt;

&lt;p&gt;LambdaTest is a cross browser testing tool on cloud which offers both manual and automated browser compatibility testing on a Selenium Grid consisting 3000+ real browsers on cloud. LambdaTest allows you to execute parallel testing, generate detailed test reports of Selenium automation testing, provides you with recorded video of the entire test script execution, along with the ability to seamlessly integrate your Selenium automation testing suite with your favourite CI/CD tools. It also offers native plugins for Jenkins, and more.&lt;/p&gt;
&lt;h2&gt;
  
  
  Test Automate Registration Page With LambdaTest And Selenium
&lt;/h2&gt;

&lt;p&gt;So, now let’s discuss the process of how we can integrate our test script with LambdaTest and execute it to see the results.In our selenium test script we initialize the WebDriver as,&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebDriver driver = new ChromeDriver();
Or 
WebDriver driver = new FirefoxDriver();
Or 
WebDriver driver = new EdgeDriver();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;While to start with, when we want to run test script on LambdaTest Selenium grid we have to initialize the WebDriver as&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebDriver driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + "@hub.lambdatest.com/wd/hub"),
DesiredCapabilities.firefox());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Now few questions will arise like what are these username and accesskey is for? So we can generate these username and accesskey from &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Capabilities Generator&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%2Fcdn-images-1.medium.com%2Fmax%2F2856%2F0%2A-fvkHOzuKHG83UhY.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%2F2856%2F0%2A-fvkHOzuKHG83UhY.png" width="800" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here once we select the OS, Browser, Selenium WebDriver version etc., we can get the username and accesskey for our users which we can use in the test script.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; To generate this username and accesskey, you should be registered and logged in your LambdaTest account.&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%2F2856%2F0%2AYyBDJCJW_dgvReSf.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%2F2856%2F0%2AYyBDJCJW_dgvReSf.png" width="800" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So after we generate those username and accesskey, we can use those in our test script in integration with LambdaTest. We have created the following test script for the LambdaTest registration page/ Sign Up page, we have covered the test scenarios which we have discussed above as manual test cases and scenarios.&lt;/p&gt;

&lt;p&gt;While executing any automation test cases, there are few steps which are common and required to perform at the start of the test suite while few needs to perform before every test case which we can call as pre conditions for the test case.&lt;br&gt;
For example: While executing every test case, we need to open the browser and navigate to the target URL before starting to execute the actual test case, delete cookies, etc..&lt;/p&gt;

&lt;p&gt;For this purpose we use @BeforeClass and @BeforeMethod annotations from Test NG, so in our case we will need&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;to set few capabilities (browser, platform etc.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open the browser&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Delete cookies&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Open LambdaTest platform and navigate to Signup page&lt;/p&gt;

&lt;p&gt;public String username = "yadneshshah91";  //your LambdaTest username&lt;br&gt;
    public String accesskey = "1234ABCD";      //your LambdaTest access key&lt;br&gt;
    public static RemoteWebDriver driver = null;&lt;br&gt;
    public String gridURL = "&lt;a class="mentioned-user" href="https://dev.to/hub"&gt;@hub&lt;/a&gt;.lambdatest.com/wd/hub"; //LambdaTest Hub URL&lt;br&gt;
    boolean status = false;&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Setting up capabilities to run our test script
@Parameters(value= {"browser","version"})
@BeforeClass
public void setUp(String browser, String version) throws Exception {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("browserName", browser);
    capabilities.setCapability("version", version);
    capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
    capabilities.setCapability("build", "LambdaTestSampleApp");
    capabilities.setCapability("name", "LambdaTestJavaSample");
    capabilities.setCapability("network", true); // To enable network logs
    capabilities.setCapability("visual", true); // To enable step by step screenshot
    capabilities.setCapability("video", true); // To enable video recording
    capabilities.setCapability("console", true); // To capture console logs
    try {
        driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
    } catch (MalformedURLException e) {
        System.out.println("Invalid grid URL");
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }

}

//Opening browser with the given URL and navigate to Registration Page
@BeforeMethod
public void openBrowser()
{
    driver.manage().deleteAllCookies();

    driver.get("https://www.lambdatest.com/");

    driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);

    WebElement signUpButton = driver.findElement(By.xpath("//a[contains(text(),'Free Signup')]"));
    signUpButton.click(); 

}
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the above part of code, notice the DesiredCapabilities object. This object is used to set capabilities like browser, version, operating system etc, and instructs LambdaTest grid to run tests on the desired configurations. If you want to run tests locally, then you would not necessarily need this object. , then we opened the browser, deleted cookies, navigate to default page of the LambdaTest and then click on the Sign Up button to redirect to our target page which is Sign Up page.&lt;/p&gt;

&lt;p&gt;Same is the case for the operations/tasks which are required to perform at the end or after the execution of test cases.&lt;br&gt;
For Example: Closing the browser session, etc.&lt;/p&gt;

&lt;p&gt;For this we have used @AfterMethod or @AfterMethod annotations from TestNG. If you are new to TestNG, then I suggest you read our detailed article on &lt;a href="https://www.lambdatest.com/blog/complete-guide-on-testng-annotations-for-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;TestNG annotations&lt;/a&gt;.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Closing the browser session after completing each test case
    @AfterClass
    public void tearDown() throws Exception {
       if (driver != null) {
            ((JavascriptExecutor) driver).executeScript("lambda-status=" + status);
            driver.quit();
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;In the above part of the code, you can see that we have closed the browser session which we need to do after every test case.&lt;/p&gt;

&lt;p&gt;As we have seen, what and how it works before and after every test case now let us execute Selenium automation testing for the test cases, discussed above. In any Selenium automation test script, to perform any actions on the elements of the web page, we need to locate them first. For this, we make use of &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=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Locators&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Perform browser &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep21_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automation testing platform&lt;/a&gt; on the most powerful cloud infrastructure. Leverage LambdaTest automation testing for faster, reliable and scalable experience on cloud.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Diving Deep Into Test Cases
&lt;/h2&gt;

&lt;p&gt;Let’s look into our test cases to comprehend our test scenarios that we need to automate registration page with Selenium testing.&lt;/p&gt;
&lt;h2&gt;
  
  
  Test Case 1
&lt;/h2&gt;

&lt;p&gt;To verify if the expected elements are available on the Sign Up page.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Verifying elements on Registration page
    @Test
    public void verifyElemntsOnPageTest()
    {
        WebElement lambdaTestLogo = driver.findElement(By.xpath("//p[@class='signup-titel']"));
        lambdaTestLogo.isDisplayed();

        WebElement signUpTitle = driver.findElement(By.xpath("//p[@class='signup-titel']"));
        signUpTitle.isDisplayed();

        WebElement termsText = driver.findElement(By.xpath("//label[@class='woo']"));
        termsText.isDisplayed();

        WebElement loginLinkText = driver.findElement(By.xpath("//p[@class='login-in-link test-left']"));
        loginLinkText.isDisplayed();

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

&lt;/div&gt;
&lt;p&gt;In the above test case function verifyElemntsOnPageTest, we have located a few elements like LambdaTest logo, Sign up title, terms of services text, etc. To locate the web elements we can use different locating strategies like ID, XPath, CSS Selector, ClassName, etc.. In the above case, we have located those elements using XPath.&lt;/p&gt;

&lt;p&gt;Once those elements are located, we have verified each of them if those are displayed using method isDisplayed().&lt;/p&gt;
&lt;h2&gt;
  
  
  Test Case 2
&lt;/h2&gt;

&lt;p&gt;To verify the redirections with the links present on the pages.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Verifying redirection to the terms and conditions page
    @Test
    public void termsRedirectionTest()
    {
        WebElement termsLink = driver.findElement(By.xpath("//a[contains(text(),'Terms')]"));
        termsLink.click();      

        Set &amp;lt;String&amp;gt; allWindows = driver.getWindowHandles();

        for(String handle : allWindows)
        {
            driver.switchTo().window(handle);
        }                   

        String expectedURL = "https://www.lambdatest.com/terms-of-service";
        String actualURL = driver.getCurrentUrl();
        //System.out.println(actualURL);
        Assert.assertEquals(actualURL, expectedURL);

        String expectedTitle = "Terms of Service - LambdaTest";
        String actualTitle = driver.getTitle();
        //System.out.println(actualTitle);
        Assert.assertEquals(actualTitle, expectedTitle);        
    }

//Verifying Privacy policy page redirection
    @Test
    public void privacyPolicyRedirectionTest()
    {
        WebElement privacyPolicyLink = driver.findElement(By.xpath("//a[contains(text(),'Privacy')]"));
        privacyPolicyLink.click();

        Set &amp;lt;String&amp;gt; allWindows = driver.getWindowHandles();

        for(String handle : allWindows)
        {
            driver.switchTo().window(handle);
        }                   

        String expectedURL = "https://www.lambdatest.com/privacy";
        String actualURL = driver.getCurrentUrl();
        //System.out.println(actualURL);
        Assert.assertEquals(actualURL, expectedURL);

        String expectedTitle = "Privacy Policy | LambdaTest";
        String actualTitle = driver.getTitle();
        //System.out.println(actualTitle);
        Assert.assertEquals(actualTitle, expectedTitle);
    }    

    //Verifying redirection to the Login page from Registration page
    @Test
    public void loginRedirectionTest()
    {
        WebElement loginLink = driver.findElement(By.xpath("//a[contains(text(),'Login')]"));
        loginLink.click();

        String expectedURL = "https://accounts.lambdatest.com/login";
        String actualURL = driver.getCurrentUrl();
        //System.out.println(actualURL);
        Assert.assertEquals(actualURL, expectedURL);

        String expectedTitle = "Login - LambdaTest";
        String actualTitle = driver.getTitle();
        //System.out.println(actualTitle);
        Assert.assertEquals(actualTitle, expectedTitle);        
    }

    //Verifying redirection to the landing page
    @Test
    public void landingPageRedirectionTest()
    {
        WebElement lambdaTestLogo = driver.findElement(By.xpath("//p[@class='logo-home']//a//img"));
        lambdaTestLogo.click();

        String expectedURL = "https://www.lambdatest.com/";
        String actualURL = driver.getCurrentUrl();
        Assert.assertEquals(actualURL, expectedURL);

        String expectedTitle = "";
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;So here, you can see we have added 4 methods for different links present on the Sign Up page and we have verified after clicking those links user is redirected to the correct URL and page or not. In the above methods, we have also added assertions to verify if the redirection is done as expected.&lt;/p&gt;
&lt;h2&gt;
  
  
  Test Case 3
&lt;/h2&gt;

&lt;p&gt;To verify Registration process with providing valid input data.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Registration with all valid data
    @Test
    public void validRegistrationTest(){            

        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");

        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");

        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test6.lambdatest@gmail.com");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@12345");

        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");

        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();

        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();

        String expectedURL = "https://accounts.lambdatest.com/email/verify";
        String actualURL = driver.getCurrentUrl();
        Assert.assertEquals(actualURL, expectedURL);

        String expectedTitle = "Verify Your Email Address - LambdaTest";
        String actualTitle = driver.getTitle();
        Assert.assertEquals(actualTitle, expectedTitle);

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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Test Case 4
&lt;/h2&gt;

&lt;p&gt;To verify registration process with different invalid input data.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Registration without providing Company Name field
    @Test
    public void emptyCompanyNameTest()
    {
         WebElement companyName = driver.findElement(By.name("organization_name"));
         companyName.sendKeys("");

         WebElement fullName = driver.findElement(By.name("name"));
         fullName.sendKeys("TestName");

         WebElement email = driver.findElement(By.name("email"));
         email.sendKeys("test7.lambdatest@gmail.com");

         WebElement password = driver.findElement(By.name("password"));
         password.sendKeys("Test@12345");

         WebElement phone = driver.findElement(By.name("phone"));
         phone.sendKeys("9876543210");

         WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
         termsOfServices.click();

         WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
         signUp.click();         

        /*
         * Set &amp;lt;String&amp;gt; allWindows = driver.getWindowHandles();
         * 
         * for(String handle : allWindows) { driver.switchTo().window(handle); }
         */ 

         String expectedURL = "https://accounts.lambdatest.com/email/verify";
         String actualURL = driver.getCurrentUrl();
         Assert.assertEquals(actualURL, expectedURL);

         String expectedTitle = "Verify Your Email Address - LambdaTest";
         String actualTitle = driver.getTitle();
         Assert.assertEquals(actualTitle, expectedTitle);
    }

    // Registration without providing Name field
    @Test
    public void emptyNameTest()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");

        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("");

        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");

        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");

        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();

        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();

        String expectedErrorMsg = "Please enter your Name";

        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Please enter your Name')]"));
        String actualErrorMsg = exp.getText();

        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);

    }

    // Registration without providing user email field
    @Test
    public void emptyEmailTest()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");

        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("test");

        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");

        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");

        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();

        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();

        String expectedErrorMsg = "Please enter your Email Address";

        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Please enter your Email Address')]"));
        String actualErrorMsg = exp.getText();

        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
    }

    // Registration with email id which already have account
    @Test
    public void invalidEmailTest()
    {

        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");

        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");

        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");

        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");

        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();

        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();

        String expectedErrorMsg = "This email is already registered";

        WebElement exp = driver.findElement(By.xpath("//p[@class='error-mass']"));
        String actualErrorMsg = exp.getText();

        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
    }

    // Registration without providing password field
    @Test
    public void emptyPasswordTest()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");

        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");

        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("");

        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");

        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();

        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();

        String expectedErrorMsg = "Please enter a desired password";

        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Please enter a desired password')]"));
        String actualErrorMsg = exp.getText();

        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
    }

    // Registration with invalid password
    @Test
    public void inValidPasswordTest()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");

        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");

        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("T");

        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");

        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();

        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();

        String expectedErrorMsg = "Password should be at least 8 characters long";

        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Password should be at least 8 characters long')]"));
        String actualErrorMsg = exp.getText();

        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
        //Password should be at least 8 characters long
    }

    // Registration without providing user phone number field
    @Test
    public void emptyPhoneTest()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");

        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");

        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");

        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("");

        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();

        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();

        String expectedErrorMsg = "The phone field is required.";

        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'The phone field is required.')]"));
        String actualErrorMsg = exp.getText();

        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
    }

    // Registration with providing invalid user phone number field
    @Test
    public void inValidPhoneTest()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");

        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");

        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");

        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("98");

        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();

        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();

        String expectedErrorMsg = "Please enter a valid Phone number";

        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Please enter a valid Phone number')]"));
        String actualErrorMsg = exp.getText();

        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);

        //Please enter a valid Phone number
    }

    // Registration without accepting terms and condition tickbox
    @Test
    public void uncheckedTerms()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");

        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");

        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");

        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");

        //WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        //termsOfServices.click();

        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();

        String expectedTermsErrorMessage = "To proceed further you must agree to our Terms of Service and Privacy Policy";
        WebElement uncheckedTermCheckbox = driver.findElement(By.xpath("//p[@class='error-mass mt-2']"));
        String actualTermsErrorMessage = uncheckedTermCheckbox.getText();
        //To proceed further you must agree to our Terms of Service and Privacy Policy

        Assert.assertEquals(actualTermsErrorMessage, expectedTermsErrorMessage);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;In the above part of code, you can see that we have covered different cases in which one or other field is provided with invalid input data. Also, at the end of every method we have added assertion along with expected error messages for the invalid input we have provided.&lt;/p&gt;
&lt;h2&gt;
  
  
  Entire Test Script To Automate Registration Page Using Selenium And Java
&lt;/h2&gt;

&lt;p&gt;As we have seen the Selenium automation testing script and different test cases in bits and pieces, now, let us combine this code to present the entire test script which we can be executed on multiple browsers which we provide as parameter.&lt;br&gt;
So please also refer the testng.xml file which is provided at the end, which is very important to execute Selenium automation testing in parallel across different browsers.&lt;/p&gt;

&lt;p&gt;Automation test script for LambdaTest Registration Page:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.lambdatest;


//TestNG Todo : Sample App
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.testng.asserts.Assertion;

import com.beust.jcommander.Parameter;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;
import java.util.concurrent.TimeUnit;

public class SignUpTest{

    public String username = "yadneshshah91";
    public String accesskey = "iD4oCZKyC8R2kwH1kLhTxAGgXZFANGoyzGDzY9RTqDTx9jskZo";
    public static RemoteWebDriver driver = null;
    public String gridURL = "@hub.lambdatest.com/wd/hub";
    boolean status = false;


    //Setting up capabilities to run our test script
    @Parameters(value= {"browser","version"})
    @BeforeClass
    public void setUp(String browser, String version) throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", browser);
        capabilities.setCapability("version", version);
        capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get any available one
        capabilities.setCapability("build", "LambdaTestSampleApp");
        capabilities.setCapability("name", "LambdaTestJavaSample");
        capabilities.setCapability("network", true); // To enable network logs
        capabilities.setCapability("visual", true); // To enable step by step screenshot
        capabilities.setCapability("video", true); // To enable video recording
        capabilities.setCapability("console", true); // To capture console logs
        try {
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
        } catch (MalformedURLException e) {
            System.out.println("Invalid grid URL");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }

    //Opening browser with the given URL and navigate to Registration Page
    @BeforeMethod
    public void openBrowser()
    {
        driver.manage().deleteAllCookies();

        driver.get("https://www.lambdatest.com/");

        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);

        WebElement signUpButton = driver.findElement(By.xpath("//a[contains(text(),'Start Free Testing')]"));
        signUpButton.click(); 

    }

    //Verifying elements on Registration page
    @Test
    public void verifyElemntsOnPageTest()
    {
        WebElement lambdaTestLogo = driver.findElement(By.xpath("//p[@class='signup-titel']"));
        lambdaTestLogo.isDisplayed();

        WebElement signUpTitle = driver.findElement(By.xpath("//p[@class='signup-titel']"));
        signUpTitle.isDisplayed();

        WebElement termsText = driver.findElement(By.xpath("//label[@class='woo']"));
        termsText.isDisplayed();

        WebElement loginLinkText = driver.findElement(By.xpath("//p[@class='login-in-link test-left']"));
        loginLinkText.isDisplayed();

    }

    //Verifying redirection to the terms and conditions page
    @Test
    public void termsRedirectionTest()
    {
        WebElement termsLink = driver.findElement(By.xpath("//a[contains(text(),'Terms')]"));
        termsLink.click();      

        Set &amp;lt;String&amp;gt; allWindows = driver.getWindowHandles();

        for(String handle : allWindows)
        {
            driver.switchTo().window(handle);
        }                   

        String expectedURL = "https://www.lambdatest.com/terms-of-service";
        String actualURL = driver.getCurrentUrl();
        //System.out.println(actualURL);
        Assert.assertEquals(actualURL, expectedURL);

        String expectedTitle = "Terms of Service - LambdaTest";
        String actualTitle = driver.getTitle();
        //System.out.println(actualTitle);
        Assert.assertEquals(actualTitle, expectedTitle);        
    }

    //Verifying Privacy policy page redirection
    @Test
    public void privacyPolicyRedirectionTest()
    {
        WebElement privacyPolicyLink = driver.findElement(By.xpath("//a[contains(text(),'Privacy')]"));
        privacyPolicyLink.click();

        Set &amp;lt;String&amp;gt; allWindows = driver.getWindowHandles();

        for(String handle : allWindows)
        {
            driver.switchTo().window(handle);
        }                   

        String expectedURL = "https://www.lambdatest.com/privacy";
        String actualURL = driver.getCurrentUrl();
        //System.out.println(actualURL);
        Assert.assertEquals(actualURL, expectedURL);

        String expectedTitle = "Privacy Policy | LambdaTest";
        String actualTitle = driver.getTitle();
        //System.out.println(actualTitle);
        Assert.assertEquals(actualTitle, expectedTitle);
    }    

    //Verifying redirection to the Login page from Registration page
    @Test
    public void loginRedirectionTest()
    {
        WebElement loginLink = driver.findElement(By.xpath("//a[contains(text(),'Login')]"));
        loginLink.click();

        String expectedURL = "https://accounts.lambdatest.com/login";
        String actualURL = driver.getCurrentUrl();
        //System.out.println(actualURL);
        Assert.assertEquals(actualURL, expectedURL);

        String expectedTitle = "Login - LambdaTest";
        String actualTitle = driver.getTitle();
        //System.out.println(actualTitle);
        Assert.assertEquals(actualTitle, expectedTitle);        
    }

    //Verifying redirection to the landing page
    @Test
    public void landingPageRedirectionTest()
    {
        WebElement lambdaTestLogo = driver.findElement(By.xpath("//p[@class='logo-home']//a//img"));
        lambdaTestLogo.click();

        String expectedURL = "https://www.lambdatest.com/";
        String actualURL = driver.getCurrentUrl();
        Assert.assertEquals(actualURL, expectedURL);


    }

    // Registration with all valid data
    @Test
    public void validRegistrationTest(){            

        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");

        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");

        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test6.lambdatest@gmail.com");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@12345");

        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");

        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();

        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();

        String expectedURL = "https://accounts.lambdatest.com/email/verify";
        String actualURL = driver.getCurrentUrl();
        Assert.assertEquals(actualURL, expectedURL);

        String expectedTitle = "Verify Your Email Address - LambdaTest";
        String actualTitle = driver.getTitle();
        Assert.assertEquals(actualTitle, expectedTitle);


    }

    // Registration without providing Company Name field
    @Test
    public void emptyCompanyNameTest()
    {
         WebElement companyName = driver.findElement(By.name("organization_name"));
         companyName.sendKeys("");

         WebElement fullName = driver.findElement(By.name("name"));
         fullName.sendKeys("TestName");

         WebElement email = driver.findElement(By.name("email"));
         email.sendKeys("test7.lambdatest@gmail.com");

         WebElement password = driver.findElement(By.name("password"));
         password.sendKeys("Test@12345");

         WebElement phone = driver.findElement(By.name("phone"));
         phone.sendKeys("9876543210");

         WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
         termsOfServices.click();

         WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
         signUp.click();


        /*
         * Set &amp;lt;String&amp;gt; allWindows = driver.getWindowHandles();
         * 
         * for(String handle : allWindows) { driver.switchTo().window(handle); }
         */ 

         String expectedURL = "https://accounts.lambdatest.com/email/verify";
         String actualURL = driver.getCurrentUrl();
         Assert.assertEquals(actualURL, expectedURL);

         String expectedTitle = "Verify Your Email Address - LambdaTest";
         String actualTitle = driver.getTitle();
         Assert.assertEquals(actualTitle, expectedTitle);
    }

    // Registration without providing Name field
    @Test
    public void emptyNameTest()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");

        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("");

        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");

        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");

        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();

        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();

        String expectedErrorMsg = "Please enter your Name";

        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Please enter your Name')]"));
        String actualErrorMsg = exp.getText();

        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);

    }

    // Registration without providing user email field
    @Test
    public void emptyEmailTest()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");

        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("test");

        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");

        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");

        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();

        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();

        String expectedErrorMsg = "Please enter your Email Address";

        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Please enter your Email Address')]"));
        String actualErrorMsg = exp.getText();

        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
    }

    // Registration with email id which already have account
    @Test
    public void invalidEmailTest()
    {

        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");

        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");

        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");

        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");

        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();

        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();

        String expectedErrorMsg = "This email is already registered";

        WebElement exp = driver.findElement(By.xpath("//p[@class='error-mass']"));
        String actualErrorMsg = exp.getText();

        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
    }

    // Registration without providing password field
    @Test
    public void emptyPasswordTest()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");

        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");

        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("");

        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");

        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();

        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();

        String expectedErrorMsg = "Please enter a desired password";

        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Please enter a desired password')]"));
        String actualErrorMsg = exp.getText();

        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
    }

    // Registration with invalid password
    @Test
    public void inValidPasswordTest()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");

        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");

        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("T");

        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");

        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();

        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();

        String expectedErrorMsg = "Password should be at least 8 characters long";

        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Password should be at least 8 characters long')]"));
        String actualErrorMsg = exp.getText();

        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
        //Password should be at least 8 characters long
    }

    // Registration without providing user phone number field
    @Test
    public void emptyPhoneTest()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");

        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");

        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");

        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("");

        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();

        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();

        String expectedErrorMsg = "The phone field is required.";

        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'The phone field is required.')]"));
        String actualErrorMsg = exp.getText();

        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);
    }

    // Registration with providing invalid user phone number field
    @Test
    public void inValidPhoneTest()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");

        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");

        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");

        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("98");

        WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        termsOfServices.click();

        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();

        String expectedErrorMsg = "Please enter a valid Phone number";

        WebElement exp = driver.findElement(By.xpath("//p[contains(text(),'Please enter a valid Phone number')]"));
        String actualErrorMsg = exp.getText();

        Assert.assertEquals(actualErrorMsg, expectedErrorMsg);

        //Please enter a valid Phone number
    }

    // Registration without accepting terms and condition tickbox
    @Test
    public void uncheckedTerms()
    {
        WebElement companyName = driver.findElement(By.name("organization_name"));
        companyName.sendKeys("TestCompany");

        WebElement fullName = driver.findElement(By.name("name"));
        fullName.sendKeys("TestName");

        WebElement email = driver.findElement(By.name("email"));
        email.sendKeys("test@test.com");

        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("Test@123");

        WebElement phone = driver.findElement(By.name("phone"));
        phone.sendKeys("9876543210");

        //WebElement termsOfServices = driver.findElement(By.id("terms_of_service"));
        //termsOfServices.click();

        WebElement signUp = driver.findElement(By.xpath("//button[contains(@class,'btn sign-up-btn-2 btn-block')]"));
        signUp.click();

        String expectedTermsErrorMessage = "To proceed further you must agree to our Terms of Service and Privacy Policy";
        WebElement uncheckedTermCheckbox = driver.findElement(By.xpath("//p[@class='error-mass mt-2']"));
        String actualTermsErrorMessage = uncheckedTermCheckbox.getText();
        //To proceed further you must agree to our Terms of Service and Privacy Policy

        Assert.assertEquals(actualTermsErrorMessage, expectedTermsErrorMessage);
    }

    // Closing the browser session after completing each test case
    @AfterClass
    public void tearDown() throws Exception {
       if (driver != null) {
            ((JavascriptExecutor) driver).executeScript("lambda-status=" + status);
            driver.quit();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;In above test script example you can observe that we have used parameterized option to provide browser name and browser version, so that we can provide the browser and browser version as per our requirement on which we need to test above test script. We can also provide multiple browsers and version to execute our test script parallely.&lt;/p&gt;

&lt;p&gt;And to achieve this we need to provide these value of browser name and version from testng.xml file, which we use with every TestNG script.&lt;br&gt;
For example, you can refer following testng.xml in which we have provided 2 browsers (Chrome and Firefox) with their respective versions.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd"&amp;gt;
&amp;lt;suite thread-count="3" name="LambaTestSuite" parallel="tests"&amp;gt;

  &amp;lt;test name="FirefoxTest"&amp;gt;
  &amp;lt;parameter name="browser" value="firefox"/&amp;gt;
  &amp;lt;parameter name="version" value="69.0"/&amp;gt;
    &amp;lt;classes&amp;gt;
      &amp;lt;class name="com.lambdatest.SignUpTest"/&amp;gt;
    &amp;lt;/classes&amp;gt;
  &amp;lt;/test&amp;gt; &amp;lt;!-- Test --&amp;gt;

  &amp;lt;test name="ChromeTest"&amp;gt;
  &amp;lt;parameter name="browser" value="chrome"/&amp;gt;
  &amp;lt;parameter name="version" value="77.0"/&amp;gt;
    &amp;lt;classes&amp;gt;
      &amp;lt;class name="com.lambdatest.SignUpTest"/&amp;gt;
    &amp;lt;/classes&amp;gt;
  &amp;lt;/test&amp;gt; &amp;lt;!-- Test --&amp;gt;

    &amp;lt;test name="EdgeTest"&amp;gt;
  &amp;lt;parameter name="browser" value="edge"/&amp;gt;
  &amp;lt;parameter name="version" value="44.0"/&amp;gt;
    &amp;lt;classes&amp;gt;
      &amp;lt;class name="com.lambdatest.SignUpTest"/&amp;gt;
    &amp;lt;/classes&amp;gt;
  &amp;lt;/test&amp;gt; &amp;lt;!-- Test --&amp;gt;

&amp;lt;/suite&amp;gt; &amp;lt;!-- Suite --&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2F1%2AvsKPGMXSlBB-NZJh0hJAiA.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%2F1%2AvsKPGMXSlBB-NZJh0hJAiA.png" width="800" height="462"&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%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AvsKPGMXSlBB-NZJh0hJAiA.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%2F1%2AvsKPGMXSlBB-NZJh0hJAiA.png" width="800" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below is a snapshot of the final execution that was triggered over the LambdaTest platform. We have executed the cross browser testing automation script over two browsers i.e. Google Chrome 77 and Mozilla Firefox 69.&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%2A1cbO2Y6YFdFQ4aRM.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%2A1cbO2Y6YFdFQ4aRM.png" width="800" height="441"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you gaze over the LambdaTest &lt;a href="https://automation.lambdatest.com/" rel="noopener noreferrer"&gt;automation dashboard&lt;/a&gt;, you will be able to notice multiple tabs representing different types of logs for your test automation script. You get tabs to analyze command logs, network logs, raw Selenium logs, metadata, and more. You also get a full video-recording of your cross browser testing script over the LambdaTest cloud servers, along with command-by-command screenshot.&lt;/p&gt;

&lt;p&gt;Watch this video to learn How to Automate Registration Page Using Selenium 4 and Java.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  That Was All
&lt;/h2&gt;

&lt;p&gt;Now, you are good to go with automate registration page using Selenium and Java. In blog of How to Automate Registration Page Using Selenium And Java, we gazed upon the registration process of LambdaTest. We thought of different test cases, compiled a test script to have them executed and the Selenium Automation testing script was then analyzed to run for different browsers in parallel.&lt;/p&gt;

&lt;p&gt;The Selenium automation test scripts were executed using Selenium and Java, with the help of TestNG framework. In case you feel I missed out on a peculiar test cases regarding the LambdaTest registration page then feel free to let me know. I am all ears! Happy testing. 🙂&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>selenium</category>
      <category>javascript</category>
      <category>testing</category>
    </item>
    <item>
      <title>Selenium Grid Tutorial: Parallel Testing Guide with Examples</title>
      <dc:creator>Ramit Dhamija</dc:creator>
      <pubDate>Tue, 20 Sep 2022 08:34:37 +0000</pubDate>
      <link>https://forem.com/ramitdhamija/selenium-grid-tutorial-parallel-testing-guide-with-examples-57l0</link>
      <guid>https://forem.com/ramitdhamija/selenium-grid-tutorial-parallel-testing-guide-with-examples-57l0</guid>
      <description>&lt;p&gt;Unlike Selenium WebDriver which allows you automated browser testing in a sequential manner, a &lt;a href="https://www.lambdatest.com/blog/why-selenium-grid-is-ideal-for-automated-browser-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep20_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;Selenium Grid&lt;/a&gt; setup will allow you to run test cases in different browsers/ browser versions, simultaneously.&lt;/p&gt;

&lt;p&gt;One of the reasons behind the huge popularity of Selenium is its capability to automate cross browser testing. And Selenium Grid has by far been the most useful component of the Selenium project. Why? Well, there was a major challenge with Selenium until Selenium Grid was introduced.&lt;/p&gt;

&lt;p&gt;Earlier, you could only load a handful of different browsers on your local machine. So if you had a windows machine, you couldn’t test on Safari browsers. Similarly, if you had a Mac machine then you couldn’t test on IE or Edge browsers. In addition, running tests on a single machine was a time-consuming process. Also, if you have multiple computers, why test on a single one at a time?&lt;/p&gt;

&lt;p&gt;The ideal scenario would be to test on a network of interconnected machines having different browser environments running multiple tests cases concurrently, in parallel, and reducing the overall testing time by multiple folds. And here I am also including time taken for &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep20_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;cross browser testing&lt;/a&gt; as well.&lt;/p&gt;

&lt;p&gt;This is exactly why &lt;strong&gt;Selenium Grid&lt;/strong&gt; is built. It can help you test on all major browsers, all major operating systems, and even on mobile device browsers. You can get a huge browser coverage in all your functional tests ensuring the perfect experience for a wide range of your potential users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;This &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep20_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;cypress test automation&lt;/a&gt; tutorial will help you learn the benefits of Cypress automation, and how to install Cypress and execute Cypress automation testing.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Selenium Grid?
&lt;/h2&gt;

&lt;p&gt;Before we start with &lt;a href="https://www.lambdatest.com/blog/why-selenium-grid-is-ideal-for-automated-browser-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep20_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;what is Selenium Grid&lt;/a&gt;, it is necessary to realize the basics of a Selenium Grid. Selenium Grid allows parallel testing against various browsers &amp;amp; OS combinations through a Client-Server model. Here, the Server is known as the Hub which has multiple Clients to interact with.&lt;/p&gt;

&lt;p&gt;With Selenium Grid, you can connect a server to multiple remote machines which can then be used to run a browser automation script over multiple browser + OS configurations, simultaneously.&lt;/p&gt;

&lt;p&gt;Selenium Grid 3 has been deprecated and the &lt;a href="https://www.selenium.dev/documentation/en/grid/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep20_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;official Selenium documentation&lt;/a&gt; recommends using the Selenium Grid 4.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Selenium Grid Works?
&lt;/h2&gt;

&lt;p&gt;Selenium Grid is comprised of two concepts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Hub&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Nodes&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What Is A Hub In Selenium Grid?
&lt;/h2&gt;

&lt;p&gt;It is the center of the Selenium Grid architecture that manages the network of the test machines. There is only one hub in a network which is assigned to a test of DesiredCapabilities(operating system, browser, browser versions) and then the hub finds the test that matches the given configurations. A Selenium Hub is referred as the server.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Are Nodes in Selenium Grid?
&lt;/h2&gt;

&lt;p&gt;Nodes are the test machines that execute the test that was earlier loaded on the hub. There can be multiple nodes configured with a different operating system and different browsers. It is not mandatory for the node to run on the same platform on which the hub is running. Selenium nodes are referred as &lt;strong&gt;clients&lt;/strong&gt; connected to a server i.e. a Hub.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ebhC9TnJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AlgMGV1xrJ7oJdaJH.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ebhC9TnJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AlgMGV1xrJ7oJdaJH.png" alt="" width="548" height="524"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Infrastructure to configuring a Selenium Grid setup for parallel execution involves just two steps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Creating a hub.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Defining the nodes and connecting to that hub.&lt;/p&gt;

&lt;h2&gt;
  
  
  Selenium Grid Setup &amp;amp; Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You would have to make sure that your system has Java Runtime Environment (JRE) or better yet Java Development Kit (JDK) installed. Though most people recommend going for the latest JDK, I prefer an earlier tried and tested versions like JDK SE 08 or 09. You can go for the latest one if you wish.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Download and extract Selenium Standalone server JAR files. You can download them from here.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Configuring A Selenium Hub
&lt;/h2&gt;

&lt;p&gt;The first step of a &lt;strong&gt;Selenium Grid&lt;/strong&gt; setup would be to create a hub. Open a command prompt or terminal and navigate to the directory where the Selenium Standalone Server jar file is saved. Run the below command.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java -jar selenium-server-standalone-3.141.59.jar -role hub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This command would launch a Selenium Grid hub on port 4444 by default. You can also check the same by directing to &lt;a href="http://localhost:4444/grid/console."&gt;&lt;em&gt;http://localhost:4444/grid/console&lt;/em&gt;.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuring Nodes For Selenium Grid
&lt;/h2&gt;

&lt;p&gt;Since the Hub has already been created, the next step to &lt;strong&gt;Selenium Grid&lt;/strong&gt; setup for parallel execution would involve launching a node. You start with going to the other machines where we want to setup nodes. Again, these machines should have a JDK/JRE setup.&lt;/p&gt;

&lt;p&gt;In the node machine, open a command prompt or terminal and navigate to the directory where you have saved the browser driver files.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configuring ChromeDriver In Selenium Grid Setup
&lt;/h3&gt;

&lt;p&gt;Enter the below command in order to configure Chrome driver in your Selenium Grid setup for parallel execution.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java -Dwebdriver.chrome.driver="C:\chromedriver.exe" -jar 
selenium-server-standalone-3.141.59.jar -role webdriver -hub 
[http://10.0.0.22:4444/grid/register](http://10.0.0.22:4444/grid/register) -port 4546
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: In the above command I have used my machine IP along with the port 4444 where the hub is actually running. I have also selected the port 4546 where I want my node to get registered. You can opt for any free port for registering the node.&lt;/p&gt;

&lt;p&gt;Similarly, you can register other nodes for other browsers. For example, here’s how you can configure Firefox(Gecko) driver and Internet Explorer driver to your &lt;strong&gt;Selenium Grid setup&lt;/strong&gt; for parallel execution.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configuring Firefox(Gecko) Driver In Selenium Grid Setup
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java -Dwebdriver.gecko.driver="C:\geckodriver.exe" -jar 
selenium-server-standalone-3.141.59.jar -role webdriver -hub 
[http://10.0.0.22:4444/grid/register](http://10.0.0.22:4444/grid/register) -port 5566
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Configuring IE(Internet Explorer) Driver In Selenium Grid Setup
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java -Dwebdriver.ie.driver="C:\IEDriverServer.exe" -jar 
selenium-server-standalone-3.141.59.jar -role webdriver -hub 
[http://10.0.0.22:4444/grid/register](http://10.0.0.22:4444/grid/register) -port 4547
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Please make sure that you select different ports for different nodes to connect with the single hub running on port 4444. Also, before running your test on IE, make sure that the browser zoom is exactly 100% otherwise it might show an error.&lt;/p&gt;

&lt;p&gt;You can notice by above commands that we are running our first node for chrome driver on port 4546, the second node for firefox driver is running on port 5566, and the third node for IE browser is running on port 4547. Here is the output screenshot for further reference:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2jbjDR1a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/0%2ArSdVn0_Ns1d5l61Z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2jbjDR1a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/0%2ArSdVn0_Ns1d5l61Z.png" alt="" width="880" height="269"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, that we have our Selenium Grid setup configured, your next step is to perform Selenium automation testing for your cross browser testing suite.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;This &lt;a href="https://www.lambdatest.com/blog/playwright-framework?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep20_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;Playwright automation&lt;/a&gt; tutorial will guide you through the setup of the Playwright framework, which will enable you to write end-to-end tests for your future projects.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Run Selenium Grid For Parallel Automation Testing
&lt;/h2&gt;

&lt;p&gt;It is time for some automated cross browser testing! I will be running an automation script demonstrating the Selenium testing Grid for parallel execution. This script would run in parallel on Chrome, Firefox, and Internet Explorer which are registered on different ports and attached to a single hub.&lt;/p&gt;

&lt;p&gt;Here is the sample code I used to perform &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep20_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;automation testing&lt;/a&gt; with &lt;strong&gt;Selenium Grid&lt;/strong&gt; for parallel execution in different browsers.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package DemoAutomation;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;


public class Selenium_MultiBrowser_Test 
{
    WebDriver driver;
    String nodeURL;

    @Parameters({"Port"})
    @BeforeMethod()
    public void setUp(String Port) throws MalformedURLException
    {           
        if(Port.equalsIgnoreCase("4546"))
        {
            nodeURL = "http://10.0.0.22:4546/wd/hub";
            System.out.println("Chrome Browser Initiated");
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();            
            capabilities.setBrowserName("chrome");
            capabilities.setPlatform(Platform.WINDOWS);

            driver = new RemoteWebDriver(new URL(nodeURL),capabilities);

            driver.get("https://www.apple.com/");
            driver.manage().window().maximize();
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        }

        else
            if(Port.equalsIgnoreCase("5566"))
            {
                nodeURL = "http://10.0.0.22:5566/wd/hub";
                System.out.println("Firefox Browser Initiated");
                DesiredCapabilities capabilities1 = DesiredCapabilities.firefox();
                capabilities1.setBrowserName("firefox");
                capabilities1.setPlatform(Platform.WINDOWS);

                driver = new RemoteWebDriver(new URL(nodeURL),capabilities1);   

                driver.get("https://www.apple.com/");
                driver.manage().window().maximize();
                driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            }

        else

        if(Port.equalsIgnoreCase("4547"))
        {
            nodeURL = "http://10.0.0.22:4547/wd/hub";
            System.out.println("Internet Browser Initiated");
            DesiredCapabilities capabilities2 = DesiredCapabilities.internetExplorer();
            capabilities2.setBrowserName("internet explorer");
            capabilities2.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
            capabilities2.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
            capabilities2.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            capabilities2.setCapability("ignoreProtectedModeSettings", true);
            capabilities2.setCapability("nativeEvents", false);
            capabilities2.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "");
            capabilities2.setCapability(InternetExplorerDriver.LOG_LEVEL, "DEBUG");


            capabilities2.setPlatform(Platform.WINDOWS);

            driver = new RemoteWebDriver(new URL(nodeURL),capabilities2);

            driver.get("https://www.apple.com/");
            driver.manage().window().maximize();    
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        }
    }

    @Test
    public void appleSite() throws InterruptedException
    {
        try
        {

        driver.findElement(By.xpath("//*[@id=\'ac-globalnav\']/div/ul[2]/li[3]")).click();
        Thread.sleep(2000);

        driver.findElement(By.cssSelector("#chapternav &amp;gt; div &amp;gt; ul &amp;gt; li.chapternav-item.chapternav-item-ipad-air &amp;gt; a &amp;gt; figure")).click();
        Thread.sleep(2000);

        driver.findElement(By.linkText("Why iPad")).click();
        Thread.sleep(2000);
        }

        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
    }


    @AfterMethod()
    public void tearDown()
    {
            driver.quit();
            System.out.println("Browser Closed");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Above is the java class file that is configured with the XML file which includes the values of parameters passed in the java file and also helps in creating a suite of different classes that would run in a parallel manner.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&amp;gt;
&amp;lt;suite thread-count="3" name="BlogSuite" parallel="tests"&amp;gt;

&amp;lt;test name="Chrome Test"&amp;gt;
&amp;lt;parameter name="Port" value="4546"/&amp;gt;
    &amp;lt;classes&amp;gt;
      &amp;lt;class name="DemoAutomation.Selenium_MultiBrowser_Test"/&amp;gt;

    &amp;lt;/classes&amp;gt;
  &amp;lt;/test&amp;gt; 

  &amp;lt;test name="Firefox Test"&amp;gt;
&amp;lt;parameter name="Port" value="5566"/&amp;gt;
    &amp;lt;classes&amp;gt;
      &amp;lt;class name="DemoAutomation.Selenium_MultiBrowser_Test"/&amp;gt;

    &amp;lt;/classes&amp;gt;
  &amp;lt;/test&amp;gt; 


  &amp;lt;test name="Internet Explorer Test"&amp;gt;
&amp;lt;parameter name="Port" value="4547"/&amp;gt;
    &amp;lt;classes&amp;gt;
      &amp;lt;class name="DemoAutomation.Selenium_MultiBrowser_Test"/&amp;gt;

    &amp;lt;/classes&amp;gt;
  &amp;lt;/test&amp;gt; 


  &amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Output Screen:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MReU30su--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AlqVf6bdWuR5Hr6UQ.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MReU30su--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AlqVf6bdWuR5Hr6UQ.jpg" alt="" width="850" height="503"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above code, I have used &lt;strong&gt;DesiredCapabilities&lt;/strong&gt; class that would help you set properties for the Selenium WebDriver. These properties can be used to configure instances of browsers such as BrowserName and BrowserVersion on which you want your script to run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; However, the script would only run on the browser and browser version that is currently installed on the test machine. Suppose, if you try running your test on Chrome 72 and you only have Chrome 74 installed on your test machine, then your script would show an error. This same scenario occurs while you opt for the different operating system compared to the operating system of your test machines.&lt;/p&gt;

&lt;p&gt;In addition, it is quite expensive to invest in new Mac and Windows environments every time a new OS is launched.&lt;/p&gt;

&lt;p&gt;So, if you wish to perform automated cross browser testing on different browsers, browser versions and operating systems then I would recommend you look for a tool that offers &lt;strong&gt;Selenium Grid&lt;/strong&gt; setup on-cloud, such as LambdaTest.&lt;/p&gt;

&lt;p&gt;LambdaTest saves you from the hassle of maintaining your Selenium Grid setup, so you could focus on &lt;a href="https://www.lambdatest.com/blog/8-actionable-insights-to-write-better-automation-code/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep20_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;writing better automation&lt;/a&gt; code. LambdaTest also empowers you with that ability of Selenium Grid for parallel execution, all on the cloud.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using LambdaTest Cloud Selenium Grid For Automation Testing
&lt;/h2&gt;

&lt;p&gt;LambdaTest is a cross browser testing platform on the cloud which allows you to test your website/ web application across 3000+ combinations of browsers, browser versions, and operating systems.&lt;/p&gt;

&lt;p&gt;LambdaTest offers a cloud Selenium Grid to help you automate browser testing in parallel. You could also integrate your LambdaTest account with numerous CI/CD tools, project management tools, codeless automation tools etc. for faster go-to-market launch. Check out all of the &lt;a href="https://www.lambdatest.com/integrations?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep20_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;LambdaTest integrations&lt;/a&gt;.Even perform live interactive real time cross browser testing, responsive testing of your web app/ website as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running The Earlier Test Over LambdaTest Selenium Grid
&lt;/h2&gt;

&lt;p&gt;Let’s try running our same test case on LambdaTest Selenium Grid. You can use LambdaTest &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep20_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;Desired Capabilities Generator&lt;/a&gt; for configuring the desired capabilities object. This would save you a lot of your time spent in &lt;strong&gt;Selenium Grid setup&lt;/strong&gt; when done manually.&lt;/p&gt;

&lt;p&gt;With LambdaTest, you only need to &lt;strong&gt;create a Remote Server, add your LambdaTest username, access key, and the Grid URL in your script,&lt;/strong&gt; and then you are good to go.&lt;/p&gt;

&lt;p&gt;Below is the Java code in the TestNG framework that would be more beneficial in this scenario:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package lambdatest;
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;


public class SampleTest {
   public String username = "enteryourusernamehere";
  public String accesskey = "enteryourkeyhere";
  public RemoteWebDriver driver = null;
  public String gridURL = "@hub.lambdatest.com/wd/hub";
  boolean status = false;

  @BeforeTest
  @org.testng.annotations.Parameters(value={"browser","version","platform"})
  public void setUp(String browser, String version, String platform) throws Exception {
     DesiredCapabilities capabilities = new DesiredCapabilities();
      capabilities.setCapability("browserName", browser);
      capabilities.setCapability("version", version);
      capabilities.setCapability("platform", platform); // If this cap isn't specified, it will just get the any available one
      capabilities.setCapability("build", "Selenium Grid");
      capabilities.setCapability("name", "Sample Test");
      capabilities.setCapability("network", true); // To enable network logs
      capabilities.setCapability("visual", true); // To enable step by step screenshot
      capabilities.setCapability("video", true); // To enable video recording
      capabilities.setCapability("console", true); // To capture console logs
      try {
          driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
      } catch (MalformedURLException e) {
          System.out.println("Invalid grid URL");
      } catch (Exception e) {
          System.out.println(e.getMessage());
      }
  }

  @Test
  public void testSimple() throws Exception {
     try {

            driver.get("https://www.apple.com/");
            driver.manage().window().maximize();

            driver.findElement(By.xpath("//*[@id=\'ac-globalnav\']/div/ul[2]/li[3]")).click();
            Thread.sleep(2000);

            driver.findElement(
            By.cssSelector("#chapternav &amp;gt; div &amp;gt; ul &amp;gt; li.chapternav-item.chapternav-item-ipad-air &amp;gt; a")).click();
            Thread.sleep(2000);

            driver.findElement(By.linkText("Why iPad")).click();
            Thread.sleep(2000);

      } catch (Exception e) {
          System.out.println(e.getMessage());
      }
  }


  @AfterTest
  public void tearDown() throws Exception {
     if (driver != null) {
          ((JavascriptExecutor) driver).executeScript("lambda-status=" + status);
          driver.quit();
      }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, we would run this Java class file with the XML file that contains the value of parameters passed in the Java file and also helps in creating a suite of different classes, using which, we can perform &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep20_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;test automation&lt;/a&gt; for parallel execution on different configurations.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&amp;gt;
&amp;lt;suite thread-count="3" name="BlogSuite" parallel="tests"&amp;gt;

  &amp;lt;test name="FirefoxTest"&amp;gt;
  &amp;lt;parameter name="browser" value="firefox"/&amp;gt;
  &amp;lt;parameter name="version" value="62.0"/&amp;gt;
  &amp;lt;parameter name="platform" value="WIN8"/&amp;gt;
    &amp;lt;classes&amp;gt;
      &amp;lt;class name="lambdatest.SampleTest"/&amp;gt;
    &amp;lt;/classes&amp;gt;
  &amp;lt;/test&amp;gt; 

  &amp;lt;test name="ChromeTest"&amp;gt;
  &amp;lt;parameter name="browser" value="chrome"/&amp;gt;
  &amp;lt;parameter name="version" value="70.0"/&amp;gt;
  &amp;lt;parameter name="platform" value="WIN10"/&amp;gt;
    &amp;lt;classes&amp;gt;
      &amp;lt;class name="lambdatest.SampleTest"/&amp;gt;
    &amp;lt;/classes&amp;gt;
  &amp;lt;/test&amp;gt; 

  &amp;lt;test name="SafariTest"&amp;gt;
  &amp;lt;parameter name="browser" value="safari"/&amp;gt;
  &amp;lt;parameter name="version" value="11.0"/&amp;gt;
  &amp;lt;parameter name="platform" value="macos High Sierra"/&amp;gt;
    &amp;lt;classes&amp;gt;
      &amp;lt;class name="lambdatest.SampleTest"/&amp;gt;
    &amp;lt;/classes&amp;gt;
  &amp;lt;/test&amp;gt; 

&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Output Screen:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gly2M5vT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/0%2AsthEexrVuVcd0R2M.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gly2M5vT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/0%2AsthEexrVuVcd0R2M.png" alt="" width="880" height="419"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we have successfully executed automation testing with Selenium Grid for parallel execution on different browsers along with different operating systems without any hassle of creating a hub and launching the nodes on different ports. While the test is running on a &lt;strong&gt;Selenium test Grid&lt;/strong&gt;, you can see the live video streaming of your tests and various other details such as commands which includes the screenshot of each command passed by your script and also the logs and exceptions raised.&lt;/p&gt;

&lt;p&gt;You can also create your own team and run your automated cross browser compatibility testing scripts as a team. These test results would be visible to each member added to a team. In addition through our single click integration, your teammates can log any bug found during their cross browser testing session directly to various project management platforms like Jira, Trello, Asana, Mantis, GitHub, etc. In addition, LambdaTest also integrates with CI/CD platforms that are complementary to your automation testing tools like CircleCI, Jenkins, TravisCI, etc. Check out all of the &lt;a href="https://www.lambdatest.com/integrations?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep20_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;LambdaTest integrations&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Now, perform &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=hashnode&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep20_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage"&gt;test automation cloud&lt;/a&gt; on the most powerful cloud infrastructure. Leverage LambdaTest automation testing for faster, reliable and scalable experience on cloud.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Selenium Grid&lt;/strong&gt; setup, if done manually, could be challenging. If the main purpose of Selenium testing Grid is to run tests in parallel and test on a different configuration, you can perform the same on LambdaTest without investing time and resources on creating hub and nodes. So, give it a try once by running your automated tests on this online Grid and let us know in the comment box about your feedback using LambdaTest. Happy Testing! 🙂&lt;/p&gt;

</description>
      <category>selenium</category>
      <category>testing</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>TestNG Listeners In Selenium WebDriver With Examples</title>
      <dc:creator>Ramit Dhamija</dc:creator>
      <pubDate>Mon, 19 Sep 2022 10:17:18 +0000</pubDate>
      <link>https://forem.com/testmuai/testng-listeners-in-selenium-webdriver-with-examples-ll9</link>
      <guid>https://forem.com/testmuai/testng-listeners-in-selenium-webdriver-with-examples-ll9</guid>
      <description>&lt;p&gt;There are different interfaces provided by Java that allows you to modify TestNG behaviour. These interfaces are further known as TestNG Listeners in &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=sep19_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt;. TestNG Listeners also allows you to customize the tests logs or report according to your project requirements.&lt;br&gt;
TestNG Listeners in Selenium WebDriver are modules that listens to certain events and keep track of test execution while performing some action at every stage of test execution.&lt;/p&gt;

&lt;p&gt;This is a TestNG tutorial, where I will help you realize the different TestNG listeners with examples so you could use them proficiently the next time you plan to work with &lt;a href="https://www.lambdatest.com/selenium-automation-testing-with-testng?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep19_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium automation with TestNG&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;TestNG Listeners in Selenium WebDriver can be implemented at two levels:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Class level:&lt;/strong&gt; In this, you implement listeners for each particular class no matter how much test cases it includes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Suite level:&lt;/strong&gt; In this, you implement listeners for a particular suite which includes several classes as test cases.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Also, Try this online &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep19_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium Automation&lt;/a&gt; Grid to run your browser automation testing scripts.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Types of TestNG Listeners In Selenium WebDriver
&lt;/h2&gt;

&lt;p&gt;There are numerous TestNG listeners in Selenium WebDriver, some of them are used very frequently by the testing community &amp;amp; some are almost forgotten. In this TestNG tutorial, I will demonstrate the most popular TestNG listeners with examples but before that, let me enlist the various TestNG listeners in Selenium WebDriver.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;ITestListener&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IAnnotationTransformer&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IInvokedMethodListener&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ISuiteListener&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IReporter&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IConfigurable&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IExecutionListener&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IHookable&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IMethodInterceptor&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IConfigurationListener&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With TestNG certification, you can challenge your skills in performing automated testing with TestNG and take your career to the next level.&lt;/p&gt;

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

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

&lt;h2&gt;
  
  
  Frequently Used TestNG Listeners With Examples
&lt;/h2&gt;

&lt;p&gt;Now, in this TestNG tutorial, let’s us first look into the most popular &amp;amp; widely used TestNG listeners with examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. ITestListener
&lt;/h2&gt;

&lt;p&gt;ITestListener is the most adopted TestNG listener in Selenium WebDriver. Providing you with an easy to implement interface through a normal Java class, where the class overrides every method declared inside the ITestListener. By using this TestNG listener in Selenium WebDriver, you can change the default behaviour of your test by adding different events to the methods. It also defines a new way of logging or reporting.&lt;/p&gt;

&lt;p&gt;Following are some methods provided by this interface:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;onStart:&lt;/strong&gt; This method is invoked before any test method gets executed. This can be used to get the directory from where the tests are running.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;onFinish:&lt;/strong&gt; This method is invoked after all tests methods gets executed. This can be used to store information of all the tests that were run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;onTestStart:&lt;/strong&gt; This method is invoked before any tests method is invoked. This can be used to indicate that the particular test method has been started.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;onTestSkipped:&lt;/strong&gt; This method is invoked when each test method is skipped. This can be used to indicate that the particular test method has been skipped.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;onTestSuccess:&lt;/strong&gt; This method is invoked when any test method gets succeeded. This can be used to indicate that the particular test method has successfully finished its execution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;onTestFailure:&lt;/strong&gt; This method is invoked when any test method gets failed. This can be used to indicate that the particular test method has been failed. You can create an event of taking a screenshot which would show where the test has been failed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;onTestFailedButWithinSuccessPercentage:&lt;/strong&gt; This method is invoked each time the test method fails but is within the success percentage mentioned. To implement this method, we use two attributes as a parameter of &lt;a href="https://www.lambdatest.com/blog/complete-guide-on-testng-annotations-for-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep19_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;TestNG annotations&lt;/a&gt; i.e. successPercentage and invocationCount. The success percentage takes the value of success percentage and invocation count denotes the number of times that a particular test method would execute.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For example:&lt;/strong&gt; &lt;a class="mentioned-user" href="https://dev.to/test"&gt;@test&lt;/a&gt;(successPercentage=60, invocationCount=5), in this annotation success percentage is 60% and invocation count is 5, that means out of 5 times if at least 3 times ((⅗)*100= 60) the test method gets passed, it would be considered as passed.&lt;/p&gt;

&lt;p&gt;For every ITestListener method we usually pass the following arguments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;“ITestResult”&lt;/strong&gt; interface along with its instance “result” which describes the result of a test.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you want to trace your exception through ITestResult then you need to avoid try/catch handling.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;“ITestContext”&lt;/strong&gt; interface along with its instance “context” which describes the test context containing all the information of the given test run.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now, in this TestNG tutorial for listeners, we will take a basic example code for running the test at the class level. Logs would get generated at a console and it would help you understanding which tests passed, failed and skipped.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The first class(ListentersBlog.java) would contain all the methods implemented by ITestListener interface:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 package TestNgListeners;

    import org.testng.ITestContext;
    import org.testng.ITestListener;
    import org.testng.ITestResult;

    public class ListenersBlog implements ITestListener {

    public void onTestStart(ITestResult result) {

      System.out.println("New Test Started" +result.getName());

     }

     public void onTestSuccess(ITestResult result) {

      System.out.println("Test Successfully Finished" +result.getName());

     }

    public void onTestFailure(ITestResult result) {

      System.out.println("Test Failed" +result.getName());

     }

    public void onTestSkipped(ITestResult result) {

      System.out.println("Test Skipped" +result.getName());

     }

    public void onTestFailedButWithinSuccessPercentage(ITestResult result) {

      System.out.println("Test Failed but within success percentage" +result.getName());

     }

    public void onStart(ITestContext context) {


      System.out.println("This is onStart method" +context.getOutputDirectory());

     }

    public void onFinish(ITestContext context) {

      System.out.println("This is onFinish method" +context.getPassedTests());
      System.out.println("This is onFinish method" +context.getFailedTests());
     }
    }

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

&lt;/div&gt;



&lt;p&gt;Below is the code that includes the tests methods(TestNGListenersTest.java). Make sure you add a Listeners annotation just above your class name to implement the above added methods.&lt;br&gt;
Syntax: @Listeners(PackageName.ClassName.class)&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package TestNgListeners;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.SkipException;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import junit.framework.Assert;

[@Listeners](http://twitter.com/Listeners)(TestNgListeners.ListenersBlog.class)
public class TestNGListenersTest {


 [@Test](http://twitter.com/Test)  //Passing Test
 public void sampleTest1() throws InterruptedException
 {
  System.setProperty("webdriver.chrome.driver", "C:\\Users\\Lenovo-I7\\Desktop\\Selenium\\chromedriver.exe");

WebDriver driver = new ChromeDriver();

  driver.get("[https://www.apple.com/](https://www.apple.com/)");
        driver.manage().window().maximize();

        driver.findElement(By.xpath("//*[[@id](http://twitter.com/id)=\'ac-globalnav\']/div/ul[2]/li[3]")).click();
        Thread.sleep(2000); 

        driver.findElement(By.cssSelector("#chapternav &amp;amp;gt; div &amp;amp;gt; ul &amp;amp;gt; li.chapternav-item.chapternav-item-ipad-air &amp;amp;gt; a")).click();
        Thread.sleep(2000); 

        driver.findElement(By.linkText("Why iPad")).click();
        Thread.sleep(2000); 

        driver.quit();

}

 [@Test](http://twitter.com/Test)  //Failing Test
 public void sampleTest2() throws InterruptedException
 {
  System.out.println("Forcely Failed Test Method");
  Assert.assertTrue(false);
 }

 private int i = 0;

[@Test](http://twitter.com/Test)(successPercentage = 60, invocationCount = 5)  //Test Failing But Within Success Percentage
 public void sampleTest3() {
  i++;
  System.out.println("Test Failed But Within Success Percentage Test Method, invocation count: " + i);
  if (i == 1 || i == 2) {
   System.out.println("sampleTest3 Failed");
   Assert.assertEquals(i, 6);
  }
 }

 [@Test](http://twitter.com/Test)  //Skipping Test
 public void sampleTest4()
 {
   throw new SkipException("Forcely skipping the sampleTest4");
 }

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

&lt;/div&gt;
&lt;p&gt;Console Output Screen:&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%2AiA9JKZh-3bVU7e5u.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%2AiA9JKZh-3bVU7e5u.png" width="800" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, suppose you have multiple classes in your project, then adding TestNG Listeners in Selenium WebDriver to each class might be a pain. In such cases, you can create a test suite and add Listeners tag to your suite(xml file) instead of adding Listeners to each class.&lt;/p&gt;

&lt;p&gt;Here is the example code(testng.xml) for running the test at the suite level :&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "[http://testng.org/testng-1.0.dtd](http://testng.org/testng-1.0.dtd)"&amp;gt;

&amp;lt;suite name="TestNG Listeners Suite" parallel="false"&amp;gt;

&amp;lt;listeners&amp;gt;
       &amp;lt;listener class-name="TestNgListeners.ListenersBlog" /&amp;gt;
   &amp;lt;/listeners&amp;gt;

&amp;lt;test name="Test"&amp;gt;
       &amp;lt;classes&amp;gt;
           &amp;lt;class name="TestNgListeners.TestNGListenersTest" /&amp;gt;
       &amp;lt;/classes&amp;gt;
   &amp;lt;/test&amp;gt;

&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Watch this video to learn how TestNG has become one of the most robust test automation frameworks and all you need to know to get started with TestNG in Selenium.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  2. IAnnotationTransformer
&lt;/h2&gt;

&lt;p&gt;IAnnotationTransformer is an interface that provides a method “transform” which would get invoked by TestNG to modify the behaviour of Test annotation method in our test class.&lt;br&gt;
The transform method provides various parameters:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;annotation:&lt;/strong&gt; The annotation that would get read from the test class.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;testClass:&lt;/strong&gt; If the annotation found on a class, this parameter would represent that same class.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;testConstructor:&lt;/strong&gt; If the annotation found on a constructor, this parameter would represent that same constructor.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;testMethod:&lt;/strong&gt; If the annotation found on a method, this parameter would represent that same method.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; At least one of the parameters will be non-null.&lt;/p&gt;

&lt;p&gt;Below is the sample code that would be executed at the suite level. In this code, we have used a parameter &lt;strong&gt;“alwaysRun = true”&lt;/strong&gt; in our Test annotation that indicates that the test method would always run even if the parameters on which the method depends fails. However, we would transform this behaviour of our test method through IAnnotationTransformer Listener which won’t allow the particular test method to get executed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Listeners Class File:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package TestNgListeners;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

import org.testng.IAnnotationTransformer;
import org.testng.annotations.ITestAnnotation;

public class AnnotationTransformers implements IAnnotationTransformer {

public boolean isTestRunning(ITestAnnotation ins) 
 {
  if(ins.getAlwaysRun())
  {
   return true;
  }
  return false;
 }


  public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {

  if(isTestRunning(annotation))
  {
   annotation.setEnabled(false);

  } 

 }

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

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Test Class File:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package TestNgListeners;

import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

public class AnnotationTransformerTests {

 [@Test](http://twitter.com/Test)(alwaysRun=true)
 public void test1()
 {
    System.out.println("This is my first test whose behaviour would get changed while executing"); 
 }

 [@Test](http://twitter.com/Test)
 public void test2()
 {
    System.out.println("This is my second test executing"); 
 }

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

&lt;/div&gt;
&lt;p&gt;Console Output Screen:&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%2At5uRjJuoHzlUBLKe.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%2At5uRjJuoHzlUBLKe.png" width="800" height="187"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  3. IInvokedMethodListener
&lt;/h2&gt;

&lt;p&gt;This interface allows you to perform some action before and after a method has been executed. This listener gets invoked for configuration and test methods. This TestNG listener in Selenium WebDriver works same as the ITestListerner and the ISuiteListerner. However, there is a difference that you should make a note of &amp;amp; that is, in IInvokedMethodListener, it makes the call before and after every method.&lt;/p&gt;

&lt;p&gt;There are two methods to be implemented:&lt;/p&gt;

&lt;p&gt;beforeInvocation(): This method is invoked prior every method.&lt;/p&gt;

&lt;p&gt;afterInvocation(): This method is invoked post every method.&lt;/p&gt;

&lt;p&gt;Here is sample code for this listener, implemented at class level.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;InvokedMethodListeners.java(includes listeners implemented methods)

package TestNgListeners;

import org.testng.IInvokedMethod;
import org.testng.IInvokedMethodListener;
import org.testng.ITestResult;

public class InvokedMethodListeners implements IInvokedMethodListener {

public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {

   System.out.println("Before Invocation of: " + method.getTestMethod().getMethodName() + "of Class:" + testResult.getTestClass());  
 }

public void afterInvocation(IInvokedMethod method, ITestResult testResult) {

   System.out.println("After Invocation of: " + method.getTestMethod().getMethodName() + "of Class:" + testResult.getTestClass());

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

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;File Name:&lt;/strong&gt; InvokedMethodListenersTest.java (includes configuration and test methods)&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package TestNgListeners;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

[@Listeners](http://twitter.com/Listeners)(value=InvokedMethodListeners.class)
public class InvokedMethodListenersTest { 
 [@Test](http://twitter.com/Test)
 public void test1()
 {
  System.out.println("My first test");
 }

 [@Test](http://twitter.com/Test)
 public void test2()
 {
  System.out.println("My second test");
 }

  [@BeforeClass](http://twitter.com/BeforeClass)
     public void setUp() {
         System.out.println("Before Class method");
     }
     [@AfterClass](http://twitter.com/AfterClass)
     public void cleanUp() {
         System.out.println("After Class method");
     }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Console Output Screen:&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%2A0rSaq7nx1p7jUWpl.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%2A0rSaq7nx1p7jUWpl.png" width="800" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Watch this video to learn how to set up and use TestNG with Selenium to automate your testing process. We will also introduce the TestNG Priority method, which allows you to write easy-to-read and maintainable tests.&lt;/p&gt;

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

&lt;p&gt;***Check out this comprehensive &lt;a href="https://www.lambdatest.com/learning-hub/end-to-end-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep19_kj&amp;amp;utm_term=kj&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;end-to-end Testing&lt;/a&gt; tutorial that covers what E2E Testing is, its importance, benefits, and how to perform it with real-time examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. ISuiteListener
&lt;/h2&gt;

&lt;p&gt;This TestNG listener in Selenium WebDriver is implemented at a suite level called ISuiteListener. It has 2 methods:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;onStart:&lt;/strong&gt; This method is invoked prior the test suite execution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;onFinish:&lt;/strong&gt; This method is invoked post the test suite execution.&lt;/p&gt;

&lt;p&gt;This listener basically listen to the events to have occurred before and after the execution of the suite.If the parent suite further contains child suites then child suites are executed before running the parent suite.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Implementing ISuiteListener with normal java class and adding the unimplemented methods.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Class: SuiteListeners&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package TestNgListeners;

import org.testng.ISuite;
import org.testng.ISuiteListener;

public class SuiteListeners implements ISuiteListener {
 public void onStart(ISuite suite) { 
  System.out.println("Suite executed onStart"  + suite.getName());
 }
 public void onFinish(ISuite suite) {
  System.out.println("Suite executed onFinish"  + suite.getName());
 } 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Creating two test classes to be added in two different child suites.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Class 1: SuiteListenersTests1&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package TestNgListeners;

import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class SuiteListenersTests1 {

 [@BeforeSuite](http://twitter.com/BeforeSuite)
 public void test1()
 {
    System.out.println("BeforeSuite method in Suite1"); 
 }


 [@Test](http://twitter.com/Test)
 public void test2()
 {
  System.out.println("Main Test method 1");
 }

 [@AfterSuite](http://twitter.com/AfterSuite)
 public void test3()
 {
    System.out.println("AfterSuite method in Suite1"); 
 }

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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Class 2: SuiteListenersTests2&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package TestNgListeners;

import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class SuiteListenersTests2 {

 [@BeforeSuite](http://twitter.com/BeforeSuite)
 public void test1()
 {
    System.out.println("BeforeSuite method in Suite2"); 
 }


 [@Test](http://twitter.com/Test)
 public void test2()
 {
  System.out.println("Main Test method 2");
 }

 [@AfterSuite](http://twitter.com/AfterSuite)
 public void test3()
 {
    System.out.println("AfterSuite method in Suite2"); 
 }

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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Adding the test classes to the child suites.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Suite 1: Test Suite One.xml&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "[http://testng.org/testng-1.0.dtd](http://testng.org/testng-1.0.dtd)"&amp;gt;
&amp;lt;suite name="Test Suite One"&amp;gt;

&amp;lt;test name="Test Method1"&amp;gt;
   &amp;lt;classes&amp;gt;
     &amp;lt;class name="TestNgListeners.SuiteListenersTests1"/&amp;gt;
   &amp;lt;/classes&amp;gt;
 &amp;lt;/test&amp;gt;

&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Suite 2: Test Suite Two.xml&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "[http://testng.org/testng-1.0.dtd](http://testng.org/testng-1.0.dtd)"&amp;gt;
&amp;lt;suite name="Test Suite Two"&amp;gt;

&amp;lt;test name="Test Method2"&amp;gt;
   &amp;lt;classes&amp;gt;
     &amp;lt;class name="TestNgListeners.SuiteListenersTests2"/&amp;gt;
   &amp;lt;/classes&amp;gt;
 &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Creating a parent suite xml file that would combine other 2 defined suites along with the listeners class.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "[http://testng.org/testng-1.0.dtd](http://testng.org/testng-1.0.dtd)"&amp;gt;

&amp;lt;suite name="suiteListener"&amp;gt;

    &amp;lt;listeners&amp;gt;
        &amp;lt;listener class-name="TestNgListeners.SuiteListeners"&amp;gt;&amp;lt;/listener&amp;gt;
    &amp;lt;/listeners&amp;gt;

    &amp;lt;suite-files&amp;gt;
        &amp;lt;suite-file path="./Suite1.xml"&amp;gt; &amp;lt;/suite-file&amp;gt;
        &amp;lt;suite-file path="./Suite2.xml"&amp;gt; &amp;lt;/suite-file&amp;gt;
    &amp;lt;/suite-files&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Console Output Screen:&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%2AIgclvkLsksdBDO7_.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%2AIgclvkLsksdBDO7_.png" width="800" height="780"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. IReporter
&lt;/h2&gt;

&lt;p&gt;This TestNG listener in Selenium WebDriver provides an interface which helps you to customize the test report generated by TestNG. It provides generateReport method which would get invoked after execution of all the suites. The method further contains three parameters:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;xmlSuite:&lt;/strong&gt; it provides you with a list of multiple suites presented in the testng xml file that goes under execution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;suites:&lt;/strong&gt; This object represents a great deal of information about the classes, packages, test execution result, along with all the test methods. Basically, it represents detailed information around the suite after the final execution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;outputDirectory:&lt;/strong&gt; contains the output folder path where the report gets generated.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Below is the example of IReporterer listener at suite level.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;File Name :ReporterListener.java&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package TestNgListener;

import java.util.List;
import java.util.Map;

import org.testng.IReporter;
import org.testng.ISuite;
import org.testng.ISuiteResult;
import org.testng.ITestContext;
import org.testng.xml.XmlSuite;

public class ReporterListener implements IReporter {

public void generateReport(List xmlSuites, List suites, String outputDirectory) {

  for(ISuite isuite : suites)
  {
   Map&amp;amp;lt;string, isuiteresult=""&amp;amp;gt; suiteResults = isuite.getResults();
   String sn = isuite.getName();

   for(ISuiteResult obj : suiteResults.values())
   {
    ITestContext tc = obj.getTestContext();

    System.out.println("Passed Tests of"  + sn + "=" +  tc.getPassedTests().getAllResults().size());

    System.out.println("Failed Tests of"  + sn + "=" +  tc.getFailedTests().getAllResults().size());

    System.out.println("Skipped Tests of"  + sn + "=" +  tc.getSkippedTests().getAllResults().size());
   }

  }


 }

}
&amp;amp;lt;/string,&amp;amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;File Name: ReporterTest.java&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package TestNgListener;

import org.testng.SkipException;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import junit.framework.Assert;

public class ReporterTest {

 [@Test](http://twitter.com/Test)
 public void FirstTest()
 {
  System.out.println("The First Test Method");
  Assert.assertTrue(true);
 }

 [@Test](http://twitter.com/Test)
 public void SecondTest()
 {
  System.out.println("The Second Test Method");
  Assert.fail("Failing this test case");
 }

 [@Test](http://twitter.com/Test)
 public void ThirdTest()
 {
  System.out.println("The Third Test Method");
  throw new SkipException("Test Skipped");
 }

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

&lt;/div&gt;

&lt;p&gt;Console Output Screen:&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%2AV2cDLDETPYbegSaw.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%2AV2cDLDETPYbegSaw.png" width="800" height="176"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Not So Frequently Used TestNG Listeners In Selenium WebDriver
&lt;/h2&gt;

&lt;p&gt;In this section, I will be highlighting those TestNG listeners which are not so renowned as the ones discussed in the previous section. I have avoided the practical demonstration of these TestNG listeners with their examples as they are rarely used. I will, however, help you understand their purpose.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Try out this online &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep19_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium Online&lt;/a&gt; Grid to run your browser automation testing scripts.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  6. IConfigurationListener
&lt;/h2&gt;

&lt;p&gt;This TestNG listener in Selenium WebDriver is used to create an event only when the configuration method is passed, failed or skipped.&lt;br&gt;
Below are the unimplemented methods provided by this listener:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;onConfigurationSuccess:&lt;/strong&gt; It gets invoked when the configuration method gets succeeded.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;onConfigurationFailure:&lt;/strong&gt; It gets invoked when the configuration method gets failed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;onConfigurationSkip:&lt;/strong&gt; As the name suggests, when your configuration method is skipped, it calls for onConfigurationSkip method.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  7. IExecutionListener
&lt;/h2&gt;

&lt;p&gt;This listener is used to keep track when the test or suite run start and finish. It provides two methods:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;onExecutionStart:&lt;/strong&gt; It is invoked before the suite or test starts running.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;onExecutionFinish:&lt;/strong&gt; It is invoked after the suite or test gets executed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; It is not possible for this listener to prevent the execution but only to create events in some way. Also, you can provide more than one “IExecution” listener as you configure TestNG.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. IHookable
&lt;/h2&gt;

&lt;p&gt;This interface skips the invocation of test methods and provides a run method which gets invoked instead of each &lt;a class="mentioned-user" href="https://dev.to/test"&gt;@test&lt;/a&gt; method found. The test method is then invoked once the callBack() method of the IHookCallBack parameter is called.&lt;/p&gt;

&lt;p&gt;IHookable listener is utilized when you wish to perform testing on classes which require JAAS authentication. This can be used to set permissions i.e. for whom the test method should run and when the test method should get skipped.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. IMethodInterceptor
&lt;/h2&gt;

&lt;p&gt;→To return the list of IMethodInstance, post-execution of TestNG.&lt;/p&gt;

&lt;p&gt;→ To sort the list of test methods.&lt;/p&gt;

&lt;p&gt;TestNG would execute the tests methods in the same order defined in the returned value.&lt;br&gt;
IMethodInterceptor interface includes only one method to implement “intercept” which returns the modified list of test methods.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; One of the test methods SampleTestOne is to test the logs, so we grouped it in “LogCheck”.&lt;/p&gt;

&lt;p&gt;Now, suppose we only want to run the LogCheck grouped tests and not the other tests, so, we have to provide an IMethodInterceptor listener that can eliminate the other tests and return only LogCheck grouped tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. IConfigurable
&lt;/h2&gt;

&lt;p&gt;The ICongurable listener is somewhat similar to IHookable listener. This interface skips the invocation of test methods and provides a run method which gets invoked instead of each configuration method found. The configuration method is then invoked once the callBack() method of the IConfigureCallBack parameter is called.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which TestNG Listeners In Selenium WebDriver Do You Use The Most?
&lt;/h2&gt;

&lt;p&gt;I hope this TestNG tutorial, helped you to realize which TestNG listeners are most suitable for your project requirements. Regarding the rarely used TestNG listeners, if there are any specific TestNG listener in Selenium that you find highly useful then feel free to share them in the comment section below. Also, if you have any questions related to the article, let me know. I look forward to your replies. Happy testing! 🙂&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>testng</category>
      <category>selenium</category>
      <category>webdriver</category>
    </item>
    <item>
      <title>[Tutorial On JUnit Annotations In Selenium With Examples]</title>
      <dc:creator>Ramit Dhamija</dc:creator>
      <pubDate>Mon, 12 Sep 2022 08:53:14 +0000</pubDate>
      <link>https://forem.com/ramitdhamija/tutorial-on-junit-annotations-in-selenium-with-examples-1nbp</link>
      <guid>https://forem.com/ramitdhamija/tutorial-on-junit-annotations-in-selenium-with-examples-1nbp</guid>
      <description>&lt;p&gt;JUnit is a Java-based, open-source framework to help you execute unit testing. JUnit is used primarily to test each and every unit or component of your application like classes and methods. It helps to write and run repeatable automated tests, to ensure your code runs as intended. You can also perform &lt;a href="https://www.lambdatest.com/selenium-automation-testing-with-junit?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep12_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;Selenium automation testing with JUnit&lt;/a&gt; for testing web apps or websites.&lt;/p&gt;

&lt;p&gt;This article is my attempt to help you use JUnit annotations in &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep12_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage"&gt;Selenium&lt;/a&gt; as a professional tester would. We would be looking at examples of JUnit annotations in Selenium, their order of execution, along with some special JUnit annotations that are used for a specific purpose. We will also be looking into a collective code for executing each example of JUnit annotation in Selenium. At last, we will perform cross browser testing with &lt;a href="https://www.lambdatest.com/blog/why-selenium-grid-is-ideal-for-automated-browser-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep12_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;What is Selenium Grid&lt;/a&gt; using JUnit annotations.&lt;/p&gt;

&lt;p&gt;Before we head on to JUnit annotations in Selenium, let us quickly recap the reasons behind JUnit’s popularity among the tester community.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why JUnit Is So Popular Among Testers?
&lt;/h2&gt;

&lt;p&gt;JUnit without a doubt, is considered as one of the &lt;a href="https://www.lambdatest.com/blog/top-5-java-test-frameworks-for-automation-in-2019/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep12_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;top Java test frameworks&lt;/a&gt;. Below are the pointers behind it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Open Source Framework&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Offers integrations with IDEs such as Eclipse, IntelliJ etc. so you could test run your code quickly and easily.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Offers integration with CI/CD tools such as Jenkins, Teamcity etc. to help you create a sturdy delivery pipeline.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Offers assertions to help you conveniently compare actual results with the expected results.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Offers annotations to help you identify the type of test methods.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Provides a facility to create a test suite which further includes multiple test cases and even other test suites.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Provides Test Runner to help your easily execute a Test Suite.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Makes the test code more readable, elegant and increases the quality.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Provides JUnit Test Report Generation in HTML format.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Which are the most wanted &lt;a href="https://www.lambdatest.com/blog/automation-testing-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep12_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;automated testing tools&lt;/a&gt; that have climbed the top of the ladder so far? Check out here.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What Are JUnit Annotations?
&lt;/h2&gt;

&lt;p&gt;As stated in the pros above, JUnit Annotations in Selenium help to identify the type of methods we have defined in our test code. But the question that arises here is, how do we use JUnit annotations in Selenium? What are the keywords that defines JUnit annotations in Selenium? When to use JUnit annotations in Selenium? If you are going through the same questions then I will help you get to the answer of them by the end of this article.&lt;/p&gt;

&lt;p&gt;So, basically Annotations are the meta-tags that provides additional information about the methods and classes defined in our code structure.&lt;br&gt;
In order to execute &lt;a href="https://www.lambdatest.com/blog/automated-testing-with-junit-and-selenium-for-browser-compatibility/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep12_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;Selenium WebDriver testing with JUnit&lt;/a&gt;, it is necessary to add JUnit Annotations in our script.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; JUnit Annotations would only be accessible in JUnit 4 plus versions and it requires at least JDK(Java Development Kit) 1.5 version.&lt;/p&gt;

&lt;p&gt;Below is the list of every JUnit annotation in Selenium that will be covered in this blog.&lt;/p&gt;
&lt;h2&gt;
  
  
  Common JUnit Annotations In Selenium
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@ BeforeClass&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@ Before&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@ Test&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@ After&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@ AfterClass&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@ Ignore&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  JUnit annotations In Selenium For Specific Purposes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@ ParameterizedTest&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@ RunWith&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@ RepeatedTest&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@ Parameters&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This JUnit certification establishes testing standards for those who wish to advance their careers in Selenium automation testing with JUnit.&lt;/p&gt;

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

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

&lt;h2&gt;
  
  
  Digging Deeper with Examples of JUnit Annotations In Selenium WebDriver
&lt;/h2&gt;

&lt;p&gt;Now, we look at each annotation one by one and at the end, I’ll present you the entire compiled code representing all the annotations along with the console output, at the end of this section.&lt;/p&gt;

&lt;h2&gt;
  
  
  @ BeforeClass
&lt;/h2&gt;

&lt;p&gt;This annotation is used to initialize any object that we use in our running test case. Whenever, we initialize any object in BeforeClass method, it would be invoked only once. The primary purpose of @ BeforeClass JUnit annotation is to execute some statements before all the test cases mentioned in the script.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[@ BeforeClass](http://twitter.com/BeforeClass)
    public static void SetUpClass()
    {
            //Initialization code goes here
            System.out.println("This is [@ BeforeClass](http://twitter.com/BeforeClass) annotation");
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  @ Before
&lt;/h2&gt;

&lt;p&gt;This annotation is used whenever we want to initialize any object for the time the method is being used. Suppose, we are having 5 test cases, the Before method will be called before each test method for 5 times. So, it would be invoked every time the test case is executed. This annotation is usually used for setting up the test environment.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[@ Before](http://twitter.com/Before)
    public void SetUp()
    {   
            // Setting up the test environment
            System.out.println("This is [@ Before](http://twitter.com/Before) annotation");
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  @ Test
&lt;/h2&gt;

&lt;p&gt;This annotation tells JUnit that the public void method() to which it is attached can be run as a test case. This annotation includes the test method for an application that you want to test. A single automation test script may comprise numerous test methods in it.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[@ Test](http://twitter.com/Test)
    public void Addition()
    {   
            c= a+b;
            assertEquals(15,c);
            System.out.println("This is first [@ Test](http://twitter.com/Test) annotation method= " +c);
    }

    [@ Test](http://twitter.com/Test)
    public void Multiplication()
    {   
            c=a*b;
            assertEquals(50,c);
            System.out.println("This is second [@ Test](http://twitter.com/Test) annotation method= " +c);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  @ After
&lt;/h2&gt;

&lt;p&gt;Whatever we have initialized in @ Before annotation method, that initialization should be released in @ After annotation method. So, this annotation is executed every time after each test method. The primary purpose of @ After annotation is to teardown. Teardown is a process of deleting temporary data. Teardown can also be used to define the default values or to wipe the slate clean of the test environment.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[@ After](http://twitter.com/After)
    public void TearDown()
    {
            // Cleaning up the test environment
            c= null;
            System.out.println("This is [@ After](http://twitter.com/After) annotation");
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  @ AfterClass
&lt;/h2&gt;

&lt;p&gt;Whatever we have initialized in @ BeforeClass annotation method, that initialization should be released in @ AfterClass annotation method. So, this annotation is executed once but it will be executed after all tests has finished executing.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[@ AfterClass](http://twitter.com/AfterClass)
    public static void TearDownClass()
    {
            //Release your resources here
            System.out.println("This is [@ AfterClass](http://twitter.com/AfterClass) annotation");
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  @ Ignore
&lt;/h2&gt;

&lt;p&gt;This annotation tells JUnit that this method shall not be executed. In scenarios, where our code module is not ready in a particular test case, we can temporarily put that code module in @ Ignore annotation method to avoid test case failure. Native JUnit 4 offers powerful reporting to help you realize the count of tests that were ignored along with count of tests that run and count of tests that failed.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[@ Ignore](http://twitter.com/Ignore)
    public void IgnoreMessage()
    {
       String info = "JUnit Annotation Blog" ;
       assertEquals(info,"JUnit Annotation Blog");
       System.out.println("This is [@ Ignore](http://twitter.com/Ignore) annotation");
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is the compiled code with output representing all the JUnits annotations in Selenium WebDriver:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package JUnitAnnotationBlog;


import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

public class JUnitAnnotations {

    int a=10;
    int b=5;
    Object c;


    [@ BeforeClass](http://twitter.com/BeforeClass)
    public static void SetUpClass()
    {
            //Initialization code goes here
            System.out.println("This is [@ BeforeClass](http://twitter.com/BeforeClass) annotation");
    }


    [@ Before](http://twitter.com/Before)
    public void SetUp()
    {   
            // Setting up the test environment
            System.out.println("This is [@ Before](http://twitter.com/Before) annotation");
    }


    [@ Test](http://twitter.com/Test)
    public void Addition()
    {   
            c= a+b;
            assertEquals(15,c);
            System.out.println("This is first [@ Test](http://twitter.com/Test) annotation method= " +c);
    }

    [@ Test](http://twitter.com/Test)
    public void Multiplication()
    {   
            c=a*b;
            assertEquals(50,c);
            System.out.println("This is second [@ Test](http://twitter.com/Test) annotation method= " +c);
    }


    [@ After](http://twitter.com/After)
    public void TearDown()
    {
            // Cleaning up the test environment
            c= null;
            System.out.println("This is [@ After](http://twitter.com/After) annotation");
    }


    [@ AfterClass](http://twitter.com/AfterClass)
    public static void TearDownClass()
    {
            //Release your resources here
            System.out.println("This is [@ AfterClass](http://twitter.com/AfterClass) annotation");
    }

    [@ Ignore](http://twitter.com/Ignore)
    public void IgnoreMessage()
    {
       String info = "JUnit Annotation Blog" ;
       assertEquals(info,"JUnit Annotation Blog");
       System.out.println("This is [@ Ignore](http://twitter.com/Ignore) annotation");
    }


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Console Output Of JUnit Annotations in Selenium WebDriver
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xS_p1FLQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2Ap0oYpZZV5l9lxM8bnutQng.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xS_p1FLQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2Ap0oYpZZV5l9lxM8bnutQng.png" alt="" width="706" height="209"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Execution Sequence Of JUnit Annotations For Selenium
&lt;/h2&gt;

&lt;p&gt;A basic process flowchart of JUnit Annotations that would help you understanding the flow, step by step.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LtsxE4-l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AgCE00K9mjl8KfNBS.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LtsxE4-l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AgCE00K9mjl8KfNBS.png" alt="" width="252" height="912"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Annotations In JUnit For Specific Purposes
&lt;/h2&gt;

&lt;p&gt;In earlier section we covered most basic JUnit annotations in Selenium. Now, I will show you some advanced JUnit annotations along with their specific purpose.&lt;/p&gt;
&lt;h2&gt;
  
  
  @ParameterizedTest
&lt;/h2&gt;

&lt;p&gt;This annotation is somewhat similar to @ Test annotation, the difference is that it is used to identify the parameterized test methods. We can also make use of &lt;strong&gt;&lt;code&gt;@ ValueSource&lt;/code&gt;&lt;/strong&gt; annotation for providing the method parameters after annotating the test method. Keep in mind, that the data type for a parameters could be of any type such as String or Integer.&lt;/p&gt;

&lt;p&gt;In the below sample code, the variable &lt;strong&gt;"data"&lt;/strong&gt; of String type passed as a parameter takes an argument from the source annotation.&lt;/p&gt;

&lt;p&gt;The primary purpose of this annotation is to run a test multiple times with different arguments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Add the below libraries before using these annotation&lt;/p&gt;

&lt;p&gt;org.junit.jupiter.params.ParameterizedTest&lt;br&gt;
org.junit.jupiter.params.provider.ValueSource&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[@ ParameterizedTest](http://twitter.com/ParameterizedTest)
    [@ ValueSource](http://twitter.com/ValueSource)(strings = {"LambdaTest", "JUnit", "Annotations", "Blog"})
    void ExampleCode(String data)
    {
       assertNotNull(data);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Cw2r3f7f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2416/0%2A3m_hDlOL3W-LT8ii.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Cw2r3f7f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2416/0%2A3m_hDlOL3W-LT8ii.png" alt="" width="880" height="165"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  @ RepeatedTest
&lt;/h2&gt;

&lt;p&gt;This annotation which has been introduced in JUnit 5 is used to run test method several times as per the requirement. The number of repetitions that you want a test to go under, can be passed as a parameter to @ RepeatedTest annotation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[@ Test](http://twitter.com/Test)
    [@ RepeatedTest](http://twitter.com/RepeatedTest)(5)
    public void Addition()
    {   
        int a=10;
        int b=5;
        Object c; 

        c= a+b;
        assertEquals(15,c);
        System.out.println("This is [@ RepeatedTest](http://twitter.com/RepeatedTest) annotation method= " +c);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Output&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9wyxHQ-u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2816/0%2A4aP6esYa9qOdp-K_.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9wyxHQ-u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2816/0%2A4aP6esYa9qOdp-K_.png" alt="" width="880" height="114"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3) @ RunWith&lt;/p&gt;

&lt;p&gt;When a class is annotated with @ RunWith annotation, JUnit invokes the class which are annotated to execute the test. This annotation basically runs with @ SuiteClasses Annotation which specifies a group of many classes to be executed. Each class in a suite executes after the execution of prior running class.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; It is necesarry to add org.junit.runner.RunWith librarby in order to use this annotation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[@ RunWith](http://twitter.com/RunWith)(Suite.class)               
[@Suite](http://twitter.com/Suite).SuiteClasses({               
  TestSample1.class,
  TestSample2.class,
  TestSample3.class,
  TestSample4.class,
  TestSample5.class,  
})

public class JunitTest {                
            // This class remains empty, it is used only as a holder for the above annotations.     
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  @ Parameters
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Do not get confused between &lt;strong&gt;&lt;code&gt;@ ParameterizedTest&lt;/code&gt;&lt;/strong&gt; annotation and &lt;strong&gt;&lt;code&gt;@ Parameters&lt;/code&gt;&lt;/strong&gt; annotation. @ Parameters annotation requires &lt;strong&gt;&lt;code&gt;@ RunWith annotation&lt;/code&gt;&lt;/strong&gt; to specify that the test would run with Parameterized runner. However, in @ ParameterizedTest annotations, &lt;strong&gt;&lt;code&gt;@ ValueSource&lt;/code&gt;&lt;/strong&gt; would be used as a source annotation to pass arguments.&lt;/p&gt;

&lt;p&gt;While using @ Parameters annotation, we use @ RunWith annotation to specify that the test will run with Parameterized Runner. The runner looks for a method that initialize the test, provides values for the test and executes the test.&lt;br&gt;
In the below code, the value-set is defined as list Object arrays which is annotated with @ Parameters. A parameterized test is a common test which is executed again and again using test parameters.This saves a lot of time for developers in executing the same test with different input types.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
`&lt;br&gt;
    &lt;a href="http://twitter.com/RunWith"&gt;@ RunWith&lt;/a&gt;(Parameterized.class)&lt;br&gt;
    public class Blog1 {&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String name, password;

   [@ Parameters](http://twitter.com/Parameters)
   public Object[][] getData()
   {
   Object[][] info = {{"ramit1","ramitd11"}, {"ramit2","ramitd22"}};
   return info;
   }

   public Blog1(String id, String pass)
   {
       this.name = id;
       this.password= pass;

   }

   [@ Test](http://twitter.com/Test)
   public void Sample()
   {
       SampleCode.login(name, password);
   }
}

Below is the code for SampleCode class used in above example:

public class SampleCode
{
    public static void login(String name, String password)
        {
            System.out.println(“Login credentials are ”  + name + password ) ;
         }
}`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Output&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E9I21uKC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2814/0%2A0rpvYx9Udox9_Hni.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E9I21uKC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2814/0%2A0rpvYx9Udox9_Hni.png" alt="" width="880" height="173"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This JUnit Tutorial for beginners and professionals will help you learn JUnit Annotations in Selenium.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Here are the 30 Top &lt;a href="https://www.lambdatest.com/blog/automation-testing-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep12_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;tools for automation testing&lt;/a&gt; In 2022.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Attributes Used With JUnit Annotations In Selenium WebDriver
&lt;/h2&gt;

&lt;p&gt;These test annotations in JUnit have multiple attributes that can be used for our test method:&lt;/p&gt;

&lt;p&gt;1) &lt;strong&gt;timeout&lt;/strong&gt; — To specify timeout for each test case, timeout attribute is specified within @ Test annotation. Timeout time is specified in milliseconds. For example, suppose, you know your particular test case takes around 15–20 seconds to get executed and you want your test to fail if it takes more than 20 seconds to get executed, then you can use this attribute as @ Test(timeout=20000) for your particular test case. If an execution fails then the progress bar would get red instead of green.&lt;/p&gt;

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

&lt;p&gt;` &lt;a href="http://twitter.com/Test"&gt;@ Test&lt;/a&gt;(timeout=10000)&lt;br&gt;
        public void ExampleCode() throws InterruptedException&lt;br&gt;
        {&lt;br&gt;
                System.setProperty("webdriver.chrome.driver","C:\Users\Lenovo-I7\Desktop\Selenium\chromedriver.exe");&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        WebDriver driver = new ChromeDriver();
        driver.get("[https://www.lambdatest.com](https://www.lambdatest.com)");
        driver.manage().window().maximize();

        driver.findElement(By.xpath("//*[[@ id](http://twitter.com/id)=\'bs-example-navbar-collapse-1\']/ul/li[6]/a")).click();
        Thread.sleep(2000);  //Login Page Button

        driver.findElement(By.xpath("//*[[@ id](http://twitter.com/id)='app']/section/form/div/div/input[1]")).sendKeys("[ramit@ lambdatest.com](mailto:ramit@ lambdatest.com)");
            //Username

        driver.findElement(By.xpath("//*[[@ id](http://twitter.com/id)=\'app\']/section/form/div/div/input[2]")).sendKeys("Hello1234");
        Thread.sleep(2000);  //Password

        driver.quit();
    }`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;-&amp;gt; Now, if you want to put this same timeout for multiple test cases, it is not necessary to add timeout attribute within each and every @ Test annotation you have specified in your script. In such case, you can use &lt;strong&gt;@ Rule annotation&lt;/strong&gt; to define a global timeout that would be applicable for each @ Test method annotation of your script.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[@ Rule](http://twitter.com/Rule)
public Timeout globalTimeout = Timeout.seconds(10); // 10 seconds max per test method
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;2) *&lt;em&gt;expected *&lt;/em&gt;— This is a special feature introduced by JUnit 4 which provides the facility to trace an exception that was expected from the execution of a particular code. There are different kinds of exceptions that are probably expected while running a code, such as, NoSuchMethodException, ArithmeticException, IndexOutOfBoundsExceptions etc. For example, you expect occurrence of exception from your code when a particular number is divided by zero, in this case, you would be using ArithmeticException. If the excepted exception does not occur then the test execution will fail.&lt;/p&gt;

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


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&lt;a href="http://twitter.com/Test"&gt;@ Test&lt;/a&gt;(expected= ArithmeticException.class)&lt;br&gt;
    public void ExampleCode() &lt;br&gt;
      {&lt;br&gt;
            int a= 10,b=0,c;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        c=a/b;

        System.out.println("Value= " +c);
}
&lt;/code&gt;&lt;/pre&gt;

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

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Performing Cross Browser Testing with JUnit annotations On Selenium Grid&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep12_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;Cross Browser Testing&lt;/a&gt;, as the name suggests, is a practice to test your website or web-application on different browsers, browser versions and on different operating systems as well, making sure that the particular application works as expected in desired configurations without any compromise in quality. Primarily, with &lt;a href="https://www.lambdatest.com/feature?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep12_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;browser compatibility testing&lt;/a&gt;, we test the appearance and functionality of a website. The purpose of cross browser testing is to provide consistent behavior of any application on different browsers, devices and platforms. Selenium helps us to perform &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep12_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;automated cross browser testing&lt;/a&gt; for pacing our go-to-market delivery.&lt;/p&gt;

&lt;p&gt;Selenium comes under 4 variants –&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&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=sep12_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;Selenium IDE&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Selenium RC&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&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=sep12_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;Selenium WebDriver&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/why-selenium-grid-is-ideal-for-automated-browser-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep12_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;Selenium Grid&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Selenium Grid would be the best option for automated cross browser testing, as it empowers users to perform &lt;a href="https://www.lambdatest.com/blog/speed-up-automated-parallel-testing-in-selenium-with-testng/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep12_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;parallel testing in Selenium&lt;/a&gt; for which we would be using Java with JUnit framework. For this, we would be running our automated test script on LambdaTest, a cross browser testing tool to realize the use of **common JUnit annotations in Selenium **by &lt;a href="https://www.lambdatest.com/blog/performing-cross-browser-testing-with-lambdatest/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep12_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;performing cross browser testing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Below is the code using which will first go to Apple’s website → iPad → iPad Air → Why iPad. Our code will then capture a screenshot of the last webpage i.e. &lt;strong&gt;Why iPad&lt;/strong&gt;, and will store it in my local machine. I will be making use of LambdaTest &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep12_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;Selenium&lt;/a&gt; Grid for running my below automation script to perform automated cross browser testing.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`package LambdaAutoPack;

&lt;p&gt;import java.io.File;&lt;br&gt;
import java.io.IOException;&lt;br&gt;
import java.net.MalformedURLException;&lt;br&gt;
import java.net.URL;&lt;/p&gt;

&lt;p&gt;import org.apache.commons.io.FileUtils;&lt;br&gt;
import org.junit.After;&lt;br&gt;
import org.junit.AfterClass;&lt;br&gt;
import org.junit.Before;&lt;br&gt;
import org.junit.BeforeClass;&lt;br&gt;
import org.junit.Ignore;&lt;br&gt;
import org.junit.Test;&lt;br&gt;
import org.openqa.selenium.By;&lt;br&gt;
import org.openqa.selenium.JavascriptExecutor;&lt;br&gt;
import org.openqa.selenium.OutputType;&lt;br&gt;
import org.openqa.selenium.TakesScreenshot;&lt;br&gt;
import org.openqa.selenium.remote.DesiredCapabilities;&lt;br&gt;
import org.openqa.selenium.remote.RemoteWebDriver;&lt;/p&gt;

&lt;p&gt;public class JUnitAnnotation {&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public String username = "ramitdlambdatest";
public String accesskey = "abcd1234";
public static RemoteWebDriver driver = null;
public String gridURL = "[@ hub](http://twitter.com/hub).lambdatest.com/wd/hub";
boolean status = false;

[@ BeforeClass](http://twitter.com/BeforeClass)
public static void setUpClass()
{
   System.out.println("Cross Browser Testing on LambdaTest");
   System.out.println("Testing on High Sierra, Chrome 72, Resolution-1920x1080");

}


[@ Before](http://twitter.com/Before)
public void setUp() throws Exception {
   DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("browserName", "Chrome");
    capabilities.setCapability("version", "72.0");
    capabilities.setCapability("platform", "macOS High Sierra"); // If this cap isn't specified, it will just get the any available one
    capabilities.setCapability("build", "JUnit Annotations");                                                       
    capabilities.setCapability("name", "MyBlog");
    capabilities.setCapability("network", true); // To enable network logs
    capabilities.setCapability("visual", true); // To enable step by step screenshot
    capabilities.setCapability("video", true); // To enable video recording
    capabilities.setCapability("console", true); // To capture console logs
    capabilities.setCapability("resolution","1920x1080");


    try {
        driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
    } catch (MalformedURLException e) {
        System.out.println("Invalid grid URL");
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}

[@ Test](http://twitter.com/Test)
public void testSimple() throws Exception {
try {


        driver.get("[https://www.apple.com/](https://www.apple.com/)");
        driver.manage().window().maximize();

        driver.findElement(By.xpath("//*[[@ id](http://twitter.com/id)=\'ac-globalnav\']/div/ul[2]/li[3]")).click();
        Thread.sleep(2000);

        driver.findElement(By.cssSelector("#chapternav &amp;amp;gt; div &amp;amp;gt; ul &amp;amp;gt; li.chapternav-item.chapternav-item-ipad-air &amp;amp;gt; a")).click();
            Thread.sleep(2000);

            driver.findElement(By.linkText("Why iPad")).click();
            Thread.sleep(2000);            

    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[@ After](http://twitter.com/After)
public void tearDown() throws Exception {
   if (driver != null) {
        ((JavascriptExecutor) driver).executeScript("lambda-status=" + status); 
    }
}

[@ AfterClass](http://twitter.com/AfterClass)
public static void teardownClass() throws IOException
{
   File screenshotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
   FileUtils.copyFile(screenshotFile, new File("D:\\Testing.png"));
   driver.quit();
}

[@ Ignore](http://twitter.com/Ignore)
public void IgnoreMethod()
{
   System.out.println("Some modules are not yet ready, please ignore"); 
}   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;}`&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;

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

&lt;p&gt;The above code will trigger my test in &lt;strong&gt;Google Chrome 72 on Mac High Sierra&lt;/strong&gt;. If you wish to perform the test on some other browser + OS configuration then you can do so by simple changing the desired capabilities. LambdaTest provides a &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep12_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;DesiredCapabilities Generator&lt;/a&gt; to help you with coded values based on your selections from drop-down list values.&lt;/p&gt;

&lt;p&gt;Since the &lt;strong&gt;&lt;code&gt;@ BeforeClass annotation&lt;/code&gt;&lt;/strong&gt; method executes only once, I have mentioned the conclusion of this script there itself i.e. Cross Browser Testing on operating system-High Sierra, browser- Chrome, version-72 and resolution- 1920×1080&lt;/p&gt;

&lt;p&gt;Coming to &lt;strong&gt;&lt;code&gt;@ Before annotation&lt;/code&gt;&lt;/strong&gt; method, I have passed the desired capabilities from the capability generator provided by LambdaTest which defines the configurations(OS, Browser, Browser version, Resolution) on which you want your test to run on along with the desired Build name. The same capabilities would be used for each test method since the @ Before annotation method executes before each test case.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;@ Test annotation&lt;/code&gt;&lt;/strong&gt; method would include your test case of an application that you want to test. In this test method I have written a small automation script that would execute on LambdaTest Selenium Grid which includes live video streaming of selenium test and show the output on IDE console as well. You can create as many @ Test annotation depending upon your different project test case executions.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;@ After annotation&lt;/code&gt;&lt;/strong&gt; method that executes after each test method shows the status of each test case that whether it has passed or failed. According to the status, you can decide whether the test case needs any improvisation or not.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;@ AfterClass annotation&lt;/code&gt;&lt;/strong&gt; method which gets executed only once after the execution of all the test methods, would take the screenshot of the web page that was last accessible through the script and would save the screenshot in the mentioned directory/folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;@ Ignore annotation&lt;/code&gt;&lt;/strong&gt; would just show that some modules of this particular web application has not been fully developed and are still in progress. So, the @ Ignore annotation method won’t show any output.&lt;/p&gt;

&lt;h2&gt;
  
  
  Output
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Vp6aNMLb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2804/0%2AOzgBZAMbsid2hsxJ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Vp6aNMLb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2804/0%2AOzgBZAMbsid2hsxJ.png" alt="" width="880" height="181"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below is the video that would show you the complete execution of my above automation test script on LambdaTest Selenium Grid.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Take a look over the most wanted &lt;a href="https://www.lambdatest.com/blog/automation-testing-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep12_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog"&gt;automation testing tools&lt;/a&gt; that have climbed the top of the ladder so far.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Summarizing It All!
&lt;/h2&gt;

&lt;p&gt;We have covered all the JUnit annotations in Selenium along with their explanation and sample code. We have also performed automated cross browser testing with the help of JUnit annotations in Selenium Grid on a cloud-based cross browser testing tool, LambdaTest.&lt;/p&gt;

&lt;p&gt;JUnit annotations are very powerful feature of JUnit, and help to improve code structure by making JUnit tests easier and more readable. Use of these annotations totally depends on your project requirement, using an appropriate annotation at correct place would be very helpful for developers as well as for other team members.&lt;/p&gt;

&lt;p&gt;Remember, JUnit annotations for Selenium would only work in JUnit 4 plus versions and would also require to import this particular library, “&lt;strong&gt;org.junit&lt;/strong&gt;.”&lt;/p&gt;

&lt;p&gt;Execute your automation script using JUnit annotations on LambdaTest Selenium Grid now! Happy testing. 🙂&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>junit</category>
      <category>selenium</category>
    </item>
  </channel>
</rss>
