<?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: Abeer Mishra</title>
    <description>The latest articles on Forem by Abeer Mishra (@aboywithscar).</description>
    <link>https://forem.com/aboywithscar</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%2F222432%2F9734c118-c2eb-4e23-b40b-b93ae356809b.jpg</url>
      <title>Forem: Abeer Mishra</title>
      <link>https://forem.com/aboywithscar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/aboywithscar"/>
    <language>en</language>
    <item>
      <title>How To Take Screenshots In Selenium WebDriver Using JavaScript</title>
      <dc:creator>Abeer Mishra</dc:creator>
      <pubDate>Tue, 17 Aug 2021 07:41:01 +0000</pubDate>
      <link>https://forem.com/aboywithscar/how-to-take-screenshots-in-selenium-webdriver-using-javascript-4f8o</link>
      <guid>https://forem.com/aboywithscar/how-to-take-screenshots-in-selenium-webdriver-using-javascript-4f8o</guid>
      <description>&lt;p&gt;While performing &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-17082021&amp;amp;utm_term=Praveen"&gt;automation testing&lt;/a&gt;, even the most reliable of test cases might face roadblocks as the action progresses. A failed test case, for instance, is a sure sign that something has gone wrong. Test failure can either be due to some issue in the script or due to some issue in the AUT (Application Under Test). What’s even more challenging is debugging such deviation scenarios for the development as well as the testing teams. Capturing screenshots of the failed scenarios can be of great help to figure out where things went wrong. Screenshots in Selenium should be the way forward to make the most out of Selenium automation testing. In this blog, we deep dive into how to take screenshots in Selenium WebDriver using JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--udgAXtg8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thumbs.gfycat.com/CostlySoreDragon-max-1mb.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--udgAXtg8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thumbs.gfycat.com/CostlySoreDragon-max-1mb.gif" alt="Capturing Screenshots"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Selenium WebDriver has built-in functionality to capture screenshots of the page, and it’s quite easy to use. It uses the TakesScreenshot interface for capturing the respective screenshot. This &lt;a href="https://www.lambdatest.com/blog/automation-testing-with-selenium-javascript/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-17082021&amp;amp;utm_term=Praveen"&gt;Selenium JavaScript tutorial&lt;/a&gt; shows the usage of TakesScreenshot method to take screenshots of a page and particular element. It is demonstrated with a step-by-step process that is executed over cloud-based Selenium Grid using Selenium automation testing.&lt;/p&gt;

&lt;p&gt;_ &lt;strong&gt;Bonus Tip&lt;/strong&gt; : If you are on Selenium 4, you can capture a screenshot of the page &amp;amp; WebElements with minimal instructions._&lt;/p&gt;

&lt;h2&gt;
  
  
  Why take screenshots when running a Selenium test
&lt;/h2&gt;

&lt;p&gt;Before we go in-depth about how to take screenshots in Selenium WebDriver, let’s have a look as the ‘why’ part of capturing screenshots:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Screenshots can be very useful in understanding the test execution flow of the application and its behavior.&lt;/li&gt;
&lt;li&gt;Capturing screenshots can be helpful in debugging any test scenario with ease.&lt;/li&gt;
&lt;li&gt;In case of a test failure, screenshots can help to identify if the problem is with the test script or the application under test.&lt;/li&gt;
&lt;li&gt;While executing a test script, screenshots at certain steps can be compared with the baseline image to verify if there is any deviation from the actual image.&lt;/li&gt;
&lt;li&gt;When we execute any &lt;a href="https://www.lambdatest.com/selenium?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-17082021&amp;amp;utm_term=Praveen"&gt;Selenium&lt;/a&gt; test, sometimes we need to see the execution at later stages. So such screenshots can help us avoid re-execution of tests.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So taking or capturing screenshots during a Selenium test is essential and can be of great help. These screenshots can be in different forms, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.lambdatest.com/full-page-screen-capture"&gt;Full page screenshot&lt;/a&gt; of the application under test.&lt;/li&gt;
&lt;li&gt;Screenshot of a particular element in the application.&lt;/li&gt;
&lt;li&gt;Screenshot of only the viewable part of the page.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to take screenshots in Selenium WebDriver using JavaScript?
&lt;/h2&gt;

&lt;p&gt;Now that we have understood the need to capture screenshots, it’s time for some action! Some classes (or interfaces) in the Selenium WebDriver can help us take screenshots of the AUT such as TakeScreenshot, AShot, etc. Let us deep dive into these classes one by one and see how to take screenshots in Selenium WebDriver using JavaScript.&lt;/p&gt;

&lt;h3&gt;
  
  
  Taking screenshots in Selenium JavaScript using the TakeScreenshot interface
&lt;/h3&gt;

&lt;p&gt;Before getting to know about taking screenshots, let us first look at the TakeScreenshot interface of Selenium WebDriver in detail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TakesScreenshot Interface in Selenium&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The TakeScreenshot interface in the Selenium WebDriver package is made with the sole purpose of capturing screenshots of applications during Selenium test automation. The TakeScreenshot interface has a subinterface – WebElement, which indicates a WebDriver instance or an HTML element to capture a screenshot and store it as per the specified instructions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Browsers that support TakeScreenshot Interface&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here is a list of browsers that support the TakeScreenshot interface:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--z_N6iu_5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ucarecdn.com/a2d54cd4-d10a-4eaa-95a4-1bfac4c17559/" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z_N6iu_5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ucarecdn.com/a2d54cd4-d10a-4eaa-95a4-1bfac4c17559/" alt="1.png"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Here is the basic syntax for how the TakeScreenshot interface can be used to take screenshots in Selenium using JavaScript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.takeScreenshot().then(
    function(image) {
        require('fs').writeFileSync(file, image, encoding_system);
    }
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me break the sequence of execution of the above code syntax:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, the TakeScreenshot interface of Selenium WebDriver is called using the driver.takeScreenshot() method.&lt;/li&gt;
&lt;li&gt;A promise is called using then.&lt;/li&gt;
&lt;li&gt;In the promise, a custom function is made with the parameter as the image. It is the captured image which is further returned by the driver.takeScreenshot() method.&lt;/li&gt;
&lt;li&gt;In the next step, the captured image is saved into a file with the specified name as ‘file’ and a desired ‘encoding system.’&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Let us try to automate a test scenario where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The LambdaTest sample todo app is called using the URL &lt;a href="https://lambdatest.github.io/sample-todo-app/"&gt;https://lambdatest.github.io/sample-todo-app/&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The 1st item in the list is clicked.&lt;/li&gt;
&lt;li&gt;The 2nd item in the list is clicked. &lt;/li&gt;
&lt;li&gt;A new item is added to the list with the name “New item.”&lt;/li&gt;
&lt;li&gt;The screenshot is captured of the application under test in the current state.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below is the complete implementation of the test scenario automation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Include the chrome driver
require("chromedriver");
require("selenium-webdriver")
// Include selenium webdriver
let webdriver = require("selenium-webdriver");
var By = require("selenium-webdriver").By;
let browser = new webdriver.Builder();
let driver = browser.forBrowser("chrome").build();

driver.get('https://lambdatest.github.io/sample-todo-app/');

driver.findElement(By.name('li1')).click();
driver.findElement(By.name('li2')).click();
driver.findElement(By.id("sampletodotext")).sendKeys("New item");
driver.findElement(By.id("addbutton")).click();

driver.takeScreenshot().then(
    function(image) {
        require('fs').writeFileSync('captured_image_3.png', image, 'base64');
    }
);

driver.quit();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;First, the required instances of Selenium WebDriver and &lt;a href="https://www.lambdatest.com/blog/selenium-chromedriver-automation-testing-guide/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-17082021&amp;amp;utm_term=Praveen"&gt;ChromeDriver&lt;/a&gt; are called.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Include the chrome driver
require("chromedriver");
require("selenium-webdriver")
// Include selenium webdriver
let webdriver = require("selenium-webdriver");
var By = require("selenium-webdriver").By;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The WebDriver is instantiated and a local instance of the Google Chrome browser is opened.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let browser = new webdriver.Builder();
let driver = browser.forBrowser("chrome").build();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, the LambdaTest sample ToDo app is navigated to by the Selenium WebDriver.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.get('https://lambdatest.github.io/sample-todo-app/');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first item in the list is searched using the Name Selenium locator and then clicked.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.name('li1')).click();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly, the second item in the list is searched using the name Selenium locator and then clicked.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.name('li2')).click();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then the text box to input a new item is searched using &lt;a href="https://www.lambdatest.com/blog/making-the-move-with-id-locator-in-selenium-webdriver/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-17082021&amp;amp;utm_term=Praveen"&gt;Selenium locator ID&lt;/a&gt;, and then the text “New item” is passed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.id("sampletodotext")).sendKeys("New item");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the text is input, now the add button is located and clicked. This inserts a new item to the list with the name “New item.”&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.id("addbutton")).click();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the next step, the screenshot of the application under test is taken and captured into a file, using the TakeScreenshot interface of Selenium WebDriver.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.takeScreenshot().then(
    function(image) {
        require('fs').writeFileSync('captured_image_3.png', image, 'base64');
    }
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once done, the test scenario is executed. Then, the Selenium WebDriver instance gets closed using the quit() method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.quit();
&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;Execute the test using the below-given command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node take_screenshot_implementation.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the test execution is complete, you can see the required image getting saved:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ch_XU4iH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/required-image-getting-1024x544.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ch_XU4iH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/required-image-getting-1024x544.png" alt="required image saving"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you open the saved image, you can see the screenshot of the viewable area in the application, representing the test scenario executed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MO634rVX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/lambdatest-todo-app-1024x523.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MO634rVX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/lambdatest-todo-app-1024x523.png" alt="LambdaTest todo app"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Let us try to automate a different test scenario this time, where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The LambdaTest Dynamic Data Loading Selenium playground is called using the URL Dynamic Data Loading Demo.&lt;/li&gt;
&lt;li&gt;The “Get New User” button is clicked.&lt;/li&gt;
&lt;li&gt;The dynamic content of the page is loaded.&lt;/li&gt;
&lt;li&gt;The screenshot is captured of the application under test in the current state with the dynamic elements. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below is the implementation to automate the required test scenario:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Include the chrome driver
require("chromedriver");
require("selenium-webdriver")

// Include selenium webdriver
let webdriver = require("selenium-webdriver");
var By = require("selenium-webdriver").By;
let browser = new webdriver.Builder();
let driver = browser.forBrowser("chrome").build();

(async function () {

    // Navigate to the required URL
    driver.get('');

    // Press the Get New User button
    driver.findElement(By.id('save')).click();

    // Wait for 5 secs to let the dynamic content to load
    await driver.sleep(5000);

    // Take screenshot of the application with the dynamic content
    driver.takeScreenshot().then(
        function (image) {
            require('fs').writeFileSync('screenshot_with_wait.png', image, 'base64')
        });

    // Exit the driver
    driver.quit();

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

&lt;/div&gt;



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

&lt;p&gt;First, the required instances of Selenium WebDriver and ChromeDriver are called.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Include the chrome driver
require("chromedriver");
require("selenium-webdriver")
// Include selenium webdriver
let webdriver = require("selenium-webdriver");
var By = require("selenium-webdriver").By;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The WebDriver instance is then built, and a local instance of the Google Chrome browser is opened.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let browser = new webdriver.Builder();
let driver = browser.forBrowser("chrome").build();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we will do the required actions in an async state as we will be using &lt;a href="https://www.lambdatest.com/blog/explicit-fluent-wait-in-selenium-c/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-17082021&amp;amp;utm_term=Praveen"&gt;Selenium explicit wait&lt;/a&gt; in this code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Include the chrome driver
require("chromedriver");
require("selenium-webdriver")

// Include selenium webdriver
let webdriver = require("selenium-webdriver");
var By = require("selenium-webdriver").By;
let browser = new webdriver.Builder();
let driver = browser.forBrowser("chrome").build();

(async function () {

    // Navigate to the required URL
    driver.get('');

    // Press the Get New User button
    driver.findElement(By.id('save')).click();

    // Wait for 5 secs to let the dynamic content to load
    await driver.sleep(5000);

    // Take screenshot of the application with the dynamic content
    driver.takeScreenshot().then(
        function (image) {
            require('fs').writeFileSync('screenshot_with_wait.png', image, 'base64')
        });

    // Exit the driver
    driver.quit();

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

&lt;/div&gt;



&lt;p&gt;Then, the LambdaTest Dynamic Data Loading Selenium Playground is navigated to by the Selenium WebDriver.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Navigate to the required URL
    driver.get('');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As per the test scenario, the “Get New User” button is searched and clicked using the ID Selenium locator to start loading the web page’s dynamic content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Press the Get New User button
driver.findElement(By.id('save')).click();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the major issue with dynamic content on a web page is that it takes time to load. Hence we cannot just go ahead and perform our next step. As a result, we need to use &lt;a href="https://www.lambdatest.com/blog/types-of-waits-in-selenium/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-17082021&amp;amp;utm_term=Praveen"&gt;waits in Selenium&lt;/a&gt; to wait for the dynamic content to load successfully. That is why an explicit wait of 5 seconds is used.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Wait for 5 secs to let the dynamic content to load
await driver.sleep(5000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the next step, the screenshot of the AUT is taken and captured into a file, using the TakeScreenshot interface of Selenium WebDriver.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Take screenshot of the application with the dynamic content
driver.takeScreenshot().then(
        function (image) {
            require('fs').writeFileSync('screenshot_with_wait.png', image, 'base64')
        });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once done, the test scenario is executed. Close the existing instance of Selenium WebDriver using the quit() method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.quit();
&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;Execute the test using the below-given command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node take_screenshot_implementation2.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the test execution is complete, you can see the required image getting saved:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tzmAifg7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/pasted-image-0-20-1024x544.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tzmAifg7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/pasted-image-0-20-1024x544.png" alt="required image after screenshot test completion"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you open the saved image, you can see the screenshot of the viewable area in application, representing the test scenario executed. The expected screenshot must have an image, a first name, and a last name in it, loaded with the help of dynamic page loading content.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--flmtTYil--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/JavaScript-1024x523.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--flmtTYil--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/JavaScript-1024x523.png" alt="Dynamic Data Loading"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, the dynamic data has been loaded successfully, and the screenshot has also been captured.&lt;/p&gt;

&lt;p&gt;For a quick overview on getting started with JavaScript, check out the video below from &lt;a href="https://www.youtube.com/c/Lambdatest"&gt;LambdaTest YouTube Channel&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;@&lt;a href="https://youtu.be/w4cidssAdJg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Taking screenshots of a particular element in Selenium JavaScript
&lt;/h3&gt;

&lt;p&gt;Till now, we looked at how to take a screenshot of the viewable area of the AUT in Selenium using JavaScript. What if we need to take screenshots of a specific region or a particular element on the page. The TakeScreenshot interface of Selenium WebDriver can be used to do this as well. But, since the TakeScreenshot interface always takes the screenshot of the complete viewable area, the question is how?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps to take screenshots of a particular WebElement&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To take the screenshot of a particular WebElement, you need to follow the below steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Take a screenshot of the complete viewable area using the TakeScreenshot interface.&lt;/li&gt;
&lt;li&gt;Get the Position and dimensions of the element around which you want to take the screenshot.&lt;/li&gt;
&lt;li&gt;Crop the original image to the fetched dimensions of the element.&lt;/li&gt;
&lt;li&gt;Save the modified image.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Steps 1, 2, and 4 can be performed with the help of Selenium JavaScript. To perform step 3, (i.e. crop the image), external libraries such as Sharp, EasyImage, etc. can be used. For our demonstration, we have used the &lt;a href="https://www.npmjs.com/package/sharp"&gt;Sharp library&lt;/a&gt;. To install Sharp, run the following command on the terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install sharp&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;Let us try to automate a test scenario where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The LambdaTest sample todo app is called using the URL &lt;a href="https://lambdatest.github.io/sample-todo-app/"&gt;https://lambdatest.github.io/sample-todo-app/&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;A new item is added to the list with the name “New item.”&lt;/li&gt;
&lt;li&gt;The screenshot is captured of only this newly added item.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below is the complete implementation of the above test scenario:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sharp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sharp&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Include the chrome driver&lt;/span&gt;
&lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;chromedriver&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;selenium-webdriver&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Include selenium webdriver&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;webdriver&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;selenium-webdriver&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;By&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;selenium-webdriver&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;By&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;webdriver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Builder&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;driver&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forBrowser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;chrome&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://lambdatest.github.io/sample-todo-app/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;By&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;sampletodotext&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nx"&gt;sendKeys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;New item&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;By&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;addbutton&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nx"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;takeScreenshot&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;writeFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;image_viewable_full.png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;base64&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;_height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_top&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;By&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;xpath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/html/body/div/div/div/ul/li[6]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getLocation&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;_left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;_top&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;By&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;xpath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/html/body/div/div/div/ul/li[6]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getSize&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;_width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;_height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;


    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nx"&gt;sharp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;image_li6.png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;extract&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_left&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="na"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_top&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_width&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;image_li6_crop.png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;new_file_info&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Image cropped and saved&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;})&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="p"&gt;}());&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;quit&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;First, the required instances of Selenium WebDriver and ChromeDriver are called.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Include the chrome driver
require("chromedriver");
require("selenium-webdriver")
// Include selenium webdriver
let webdriver = require("selenium-webdriver");
var By = require("selenium-webdriver").By;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The WebDriver instance is then built, and a local instance of the Google Chrome browser is opened.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let browser = new webdriver.Builder();
let driver = browser.forBrowser("chrome").build();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, the LambdaTest sample todo app is navigated to by the Selenium WebDriver.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.get('https://lambdatest.github.io/sample-todo-app/');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The text box to input a new item is searched using Selenium locator ID, and then the text “New item” is passed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.id("sampletodotext")).sendKeys("New item");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the text is input, now the add button is found and clicked. This inserts a new item to the list with the name “New item.”&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.id("addbutton")).click();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the next step, the screenshot of the application under test is taken and captured into a file, using the TakeScreenshot interface of Selenium WebDriver.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.takeScreenshot().then(
    function (image) {
        require('fs').writeFileSync('image_viewable_full.png', image, 'base64')
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have the original image of the current state of the application captured. Now we need the dimensions of the newly added item so that image can be cropped. To store that, we will create four variables to keep the value of the corresponding dimension.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var _height = 0, _width = 0, _left = 0, _top = 0;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Among the required four dimensions, first, the left and top positions are fetched using the getLocation() method and stored as per the requirement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.xpath('/html/body/div/div/div/ul/li[6]'))
        .getLocation().then(location =&amp;gt; {
            _left = location.x;
            _top = location.y;
        });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then the width and the height of the newly added li6 element are fetched using the getSize() method and stored.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.xpath('/html/body/div/div/div/ul/li[6]'))
        .getSize().then(size =&amp;gt; {
            _width = size.width;
            _height = size.height;
        });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we have the required dimensions of the li6 item now, we can crop the captured screenshot using the Sharp package. As you can see, the Sharp object takes one parameter which is the image file. With the help of the extract() method, the image is then cropped. Once cropped, we can save the modified file to the same file or a new one, using the toFile() method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sharp('image_element_li6.png')
            .extract({ left: parseInt(_left), top: parseInt(_top), width: parseInt(_width), height: parseInt(_height) })
            .toFile('image_li6_crop.png')
            .then(function (new_file_info) {
                console.log("Image cropped and saved");
            })
            .catch(function (err) {
                if (err) console.log(err);
            });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once done, the test scenario is executed. Then, the Selenium WebDriver instance gets closed using the quit() method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.quit();
&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;To trigger the test, run the below command on the terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node screenshot_of_element.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;On successful execution, the captured image file is stored in the desired location (or directory).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---UShue5z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/successful-execution-1024x544.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---UShue5z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/successful-execution-1024x544.png" alt="successful screenshot test execution"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you open the saved image, you can see the screenshot of only the newly added 6th item in the list with the name “New item” and not the complete viewable area, representing the test scenario executed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Zx2xL6Pk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/image_element_li6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Zx2xL6Pk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/image_element_li6.png" alt="New Item"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to take screenshot of a particular WebElement using Selenium 4 and JavaScript
&lt;/h2&gt;

&lt;p&gt;In Selenium 3, the approach to capture the screenshot of the entire web page was pretty simple and straightforward. However, capturing the screenshot of a WebElement in the page required a fair bit of calculations! You would have witnessed this tedious calculation exercise in the earlier section where we demonstrated how to capture a screenshot of a WebElement in Selenium 3.&lt;/p&gt;

&lt;p&gt;Things are set to change with Selenium 4, considering the fact that it is relatively easy to &lt;a href="https://www.lambdatest.com/blog/upgrade-from-selenium3-to-selenium4/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-17082021&amp;amp;utm_term=Praveen"&gt;update from Selenium 3 to Selenium 4&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;One of the welcome changes in Selenium 4 is the ability to capture the screenshot of a particular WebElement with ultra ease. You no longer need to use third-party libraries to capture the screenshot of a WebElement.&lt;/p&gt;

&lt;p&gt;Here are the steps you need to perform for capturing WebElement screenshot with Selenium 4:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Locate the desired WebElement using the appropriate web locators (e.g. XPath, ID, CSS, etc.).&lt;/li&gt;
&lt;li&gt;Once the WebElement (e.g. ele) is located, use &amp;lt;element_name&amp;gt;.takeScreenshot(true) method for capturing the element screenshot (in the desired image format – base64) &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now that we have covered the steps to capture element screenshot with Selenium 4 &amp;amp; JavaScript, let’s get our hands dirty with the implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;By&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;Key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;Builder&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;selenium-webdriver&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;chromedriver&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;WebElementCapture&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
       &lt;span class="c1"&gt;//To wait for browser to build and launch properly&lt;/span&gt;
       &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;driver&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Builder&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;forBrowser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;chrome&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;//To fetch https://lambdatest.github.io/sample-todo-app/ from the browser with our code.&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://lambdatest.github.io/sample-todo-app/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;//Add a new item in the list&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;By&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;sampletodotext&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nx"&gt;sendKeys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Add a new item in the list&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;By&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;addbutton&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nx"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;ele&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;By&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;xpath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/html/body/div/div/div/ul/li[6]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

        &lt;span class="c1"&gt;//Capture the element screenshot&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;encodedString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;ele&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;takeScreenshot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;writeFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./image_li6_crop.png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;encodedString&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;base64&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;quit&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;WebElementCapture&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Implementation has only changed in the area where the TakeElementScreenshot method is used to capture a screenshot of the WebElement.&lt;/p&gt;

&lt;p&gt;To get started, we add a new item (i.e. Add a new item in the list) in the LambdaTest ToDo app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await driver.findElement(By.id("sampletodotext")).sendKeys("Add a new item in the list");
await driver.findElement(By.id("addbutton")).click();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that the item is added to the list, it is located using the XPath locator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let ele = await driver.findElement(By.xpath('/html/body/div/div/div/ul/li[6]'));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The takeScreenshot method is used on the required WebElement (i.e. ele in this case) and the captured image is written to the file system in the base64 encoded format.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let encodedString = await ele.takeScreenshot(true);
await fs.writeFileSync('./image_li6_crop.png', encodedString, 'base64');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s all. This is all that is required to capture screenshot of a desired WebElement in Selenium using JavaScript.&lt;/p&gt;

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

&lt;p&gt;Run the following command on the terminal to trigger the test&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node ImageCapture.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;A new item is added to the ToDo list. A screenshot of the new item is taken and stored in the given location in the file system. As mentioned earlier, the screenshot is stored in the base64 encoded format. As seen below, an image by the name image_li6_crop.png is created in the designated folder.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZPFUPmt4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/pasted-image-0-2-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZPFUPmt4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/pasted-image-0-2-2.png" alt="Automated Screenshot Captured"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the screenshot of the newly added element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WKOmFIE5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/pasted-image-0-3-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WKOmFIE5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/pasted-image-0-3-2.png" alt="Adding the new item to list"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are intrigued to learn more about Selenium 4, do check out &lt;a href="https://www.lambdatest.com/learning-hub/selenium-4?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-17082021&amp;amp;utm_term=Praveen"&gt;Selenium 4 Learning Hub&lt;/a&gt; on LambdaTest. It’s your go-to place to deep dive into the various facets of Selenium 4!&lt;/p&gt;

&lt;p&gt;We have seen how to take screenshots in Selenium WebDriver using JavaScript. Using a local setup has severe shortcomings, especially when the test cases are extremely long or when screenshots have to be captured at multiple test steps. Here are some of the major drawbacks of using a local Selenium setup for capturing screenshots:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For larger test scenarios, taking screenshots becomes difficult to implement.&lt;/li&gt;
&lt;li&gt;Using Local setup can become tedious when screenshots have to be captured at multiple steps.&lt;/li&gt;
&lt;li&gt;Full page screenshots can take up a huge chunk of system memory.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To overcome these shortcomings, it is recommended to use LambdaTest, an &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-17082021&amp;amp;utm_term=Praveen"&gt;online Selenium grid&lt;/a&gt; that helps you run your tests on 2000+ browsers, browser versions, and operating systems. That’s not all, the platform captures screenshots automatically at every test step.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to capture screenshots step-by-step on LambdaTest
&lt;/h3&gt;

&lt;p&gt;To capture the screenshot on the LambdaTest platform at every test step, you need to pass the “visual” capability in the desired capabilities. This capability is available in the advanced configuration of the capabilities generator. When “visual” is set to “true”, LambdaTest will record a step by step screenshot of your test.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qcBdHfJ---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/step-on-LambdaTest-1024x486.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qcBdHfJ---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/step-on-LambdaTest-1024x486.png" alt="capture screenshots step by step"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Below is an example of the desired capabilities with the “visual” capability passed as “true”. This is instrumental in capturing screenshots at every test step.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;capabilities = {
  'build': ’Capture Screenshots’, //Build name
  'name': 'Your Test Name', // Test name
  'platform':'MacOS Big sur', // OS name
  'browserName': 'Firefox', // Browser name
  'version': '89.0', // Browser version
  "resolution" : "1280x960",

  'visual': true,  // To take step by step screenshot

  'network':false,  // To capture network Logs
  'console':false, // To capture console logs.
  'tunnel': false // If you want to run the localhost then change it to true
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Consider the below example that solves the below test scenario:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The LambdaTest sample todo app is called using the URL &lt;a href="https://lambdatest.github.io/sample-todo-app/"&gt;https://lambdatest.github.io/sample-todo-app/&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The 1st item in the list is clicked.&lt;/li&gt;
&lt;li&gt;The 2nd item in the list is clicked. &lt;/li&gt;
&lt;li&gt;A new item is added to the list with the name “New item.”&lt;/li&gt;
&lt;li&gt;The screenshot is captured of the application under test in the current state.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The test is run on the LambdaTest platform. As the prerequisites, we first need to get the username, access key, and the desired capabilities.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Get the username and access key from the &lt;a href="https://accounts.lambdatest.com/detail/profile"&gt;LambdaTest Profile section&lt;/a&gt;, and update the below code snippet for the Grid URL. Grid URL is your specific Remote WebDriver route on which the tests will be executed.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String gridURL = "http://" + username + ":" + accesskey + "@hub.lambdatest.com/wd/hub";        
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Next, get the desired capabilities from the &lt;a href="https://www.lambdatest.com/capabilities-generator/"&gt;LambdaTest Capabilities Generator&lt;/a&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var capabilities = {
        "build" : "your build name",
        "name" : "your test name",
        "platform" : "'MacOS Big sur",
        "browserName" : "Firefox",
        "version" : "89.0",
        "visual" : true
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We need to create the Remote WebDriver instance and initialize it with the above capabilities and Grid URL.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LT_USERNAME = "username";
LT_ACCESS_KEY = "access key";

caps = {
  'build': 'Capture Screenshots', //Build name
  'name': 'Your Test Name', // Test name
  'platform':'MacOS Big sur', // OS name
  'browserName': 'Firefox', // Browser name
  'version': '89.0', // Browser version
  "resolution" : "1280x960",
  'visual': true,  // To take step by step screenshot
  'network':false,  // To capture network Logs
  'console':false, // To capture console logs.
  'tunnel': false // If you want to run the localhost then change it to true
  };

var buildDriver = function () {
    return new webdriver.Builder()
        .usingServer(
            "http://" +
            LT_USERNAME +
            ":" +
            LT_ACCESS_KEY +
            "@hub.lambdatest.com/wd/hub"
        )
        .withCapabilities(caps)
        .build();
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it. Now we can use this Remote WebDriver instance to write and execute our test to show how to take screenshots in Selenium WebDriver. Below is the complete JavaScript code for the same:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;LT_USERNAME&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;username&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;LT_ACCESS_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;access key&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;capabilities&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;build&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Capture Screenshots&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;//Build name&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Your Test Name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Test name&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;platform&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;MacOS Big sur&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// OS name&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;browserName&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Firefox&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Browser name&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;version&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;89.0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Browser version&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;resolution&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1280x960&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;visual&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;// To take step by step screenshot&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;network&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;// To capture network Logs&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;console&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// To capture console logs.&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;tunnel&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="c1"&gt;// If you want to run the localhost then change it to true&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;By&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;selenium-webdriver&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;By&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;assert&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;assert&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nx"&gt;webdriver&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;selenium-webdriver&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nx"&gt;conf_file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;conf/single.conf.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;caps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;conf_file&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;capabilities&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;buildDriver&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;caps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;webdriver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Builder&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;usingServer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
            &lt;span class="nx"&gt;LT_USERNAME&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
            &lt;span class="nx"&gt;LT_ACCESS_KEY&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@hub.lambdatest.com/wd/hub&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;withCapabilities&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;caps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Capture Screenshot &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;caps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;browserName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;beforeEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;done&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;caps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentTest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;driver&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;buildDriver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;caps&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;done&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Take Screenshot JavaScript&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;done&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://lambdatest.github.io/sample-todo-app/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;By&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;li1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nx"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;By&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;li2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nx"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;By&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;sampletodotext&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nx"&gt;sendKeys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;New item&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;By&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;addbutton&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nx"&gt;click&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="nx"&gt;afterEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;done&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentTest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isPassed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;executeScript&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lambda-status=passed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;executeScript&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lambda-status=failed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;quit&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;done&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Upon execution, you can see the test getting run on the desired environment configuration on the LambdaTest platform.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3TpAOQ-D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/LambdaTest-platform-1-1024x484.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3TpAOQ-D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/LambdaTest-platform-1-1024x484.png" alt="Screenshot Test Execution on LambdaTest"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How to view screenshots step-by-step on LambdaTest?
&lt;/h3&gt;

&lt;p&gt;You can view the screenshots step-by-step on the LambdaTest platform. Just go to the Commands tab of the test, and you will see the screenshots along with all the steps. You can view or download any of the screenshots as and when required.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r8A2xN9K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/LambdaTest-platform-2-1024x482.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r8A2xN9K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/LambdaTest-platform-2-1024x482.png" alt="view screenshots on LambdaTest"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below is one of the screenshots, where we send keys to enter the name of the 6th item in the list as New item, captured by LambdaTest.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_LVO_oPj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/captured-by-LambdaTest-1024x488.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_LVO_oPj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/captured-by-LambdaTest-1024x488.png" alt="Adding captured screenshots"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YneEz-VX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/pasted-image-0-1-3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YneEz-VX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/06/pasted-image-0-1-3.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The UI of a webpage is often very complex, and to test the complete UI, &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-17082021&amp;amp;utm_term=Praveen"&gt;Selenium automation testing&lt;/a&gt; is the most effective way. Capabilities offered by Selenium automation testing can be enhanced by capturing page (or WebElement) screenshots for the failed test scenarios.&lt;/p&gt;

&lt;p&gt;Taking screenshots in Selenium WebDriver using JavaScript can be super helpful in checking problematic areas on the page. Taking such screenshots can help you witness the execution as the desired point and debug your tests in a much easier and faster way. Online tools like LambdaTest can help you capture step by step screenshots of your test with a minimal addition in the test capabilities.&lt;/p&gt;

&lt;p&gt;We hope you learned how to take screenshots in Selenium WebDriver using JavaScript.&lt;/p&gt;

&lt;p&gt;Happy Testing!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How To Set Jenkins Pipeline Environment Variables?</title>
      <dc:creator>Abeer Mishra</dc:creator>
      <pubDate>Thu, 24 Jun 2021 09:13:02 +0000</pubDate>
      <link>https://forem.com/aboywithscar/how-to-set-jenkins-pipeline-environment-variables-3hhp</link>
      <guid>https://forem.com/aboywithscar/how-to-set-jenkins-pipeline-environment-variables-3hhp</guid>
      <description>&lt;p&gt;Jenkins is an open-source and extensible continuous integration and continuous deployment server. It is used to automate the process of continuous integration and continuous deployment(CI/CD). The importance of monitoring remote jobs and interacting with team members for stable code is immense; Jenkins takes care of all these requirements and allows a smooth integration via plugins, pipelines, and &lt;a href="https://www.lambdatest.com/learning-hub/jenkins?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-24062021&amp;amp;utm_term=Praveen" rel="noopener noreferrer"&gt;Jenkins&lt;/a&gt; environment variables.&lt;/p&gt;

&lt;p&gt;If you are amongst the typical Jenkins users who want to add to their knowledge about CI and CD, some fundamental concepts must be learned. In this article, we will learn about the critical concept of Jenkins pipeline environment variables. We will also view and install the Lambatest Jenkins plugin and use the in-build variables from the Jenkins environment variables list.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  What are Jenkins Pipeline Environment Variables?
&lt;/h2&gt;

&lt;p&gt;While writing the script for a &lt;a href="https://www.lambdatest.com/blog/jenkins-pipeline-tutorial/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-24062021&amp;amp;utm_term=Praveen" rel="noopener noreferrer"&gt;Jenkins pipeline&lt;/a&gt;, some dynamic values are to be injected and used. These are especially useful to avoid hardcoding every value into the pipeline. For this dynamic integration, Jenkins set environment variables.&lt;/p&gt;

&lt;p&gt;Jenkins environment variable is a global variable, exposed via env variable and used in Jenkins pipelines and anywhere into Jenkinsfile. Any value stored as the environment variable in the env variable is of string type.&lt;/p&gt;

&lt;p&gt;The Jenkins pipeline environment variables facilitate the benefits like :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Injection of sensitive data at runtime to avoid the hardcoding into the pipeline.&lt;/li&gt;
&lt;li&gt;Addition of job parameters available only at runtime, but not at design time.&lt;/li&gt;
&lt;li&gt;Boolean values set in environment variables help certain toggle stages in a pipeline via a parameter that describes a specific subset of tests you want to run.&lt;/li&gt;
&lt;li&gt;Providing IDs of credentials defined in Jenkins.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the Jenkins pipeline, there are a lot of helpful environment variables that can be accessed and maintained during build execution; some of the most useful ones are :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;env:&lt;/strong&gt; env is used to access the Jenkins pipeline environment variables in groovy code as env.VARNAME or simply as VARNAME. The env prefix also accesses the environment variables provided in the Jenkins pipeline.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;currentBuild:&lt;/strong&gt; As the name suggests, it addresses the currently running build of the Jenkins pipeline.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;params:&lt;/strong&gt; All the parameters provided for a successful build from a read-only map with various typed variables. These can be accessed via params.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;docker:&lt;/strong&gt; This is to provide convenient access to Docker – related functions in a Groovy script of Jenkins pipeline.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To ease building the pipeline, Jenkins has provided us with a Jenkins environment variables list. This list contains some of the most used variables. Let’s start by browsing through the list of environment variables.&lt;/p&gt;

&lt;h2&gt;
  
  
  Viewing Jenkins Environment Variables List
&lt;/h2&gt;

&lt;p&gt;Jenkins exposes the crucial characteristics of components using environment variables. Thus, a set of these variables are already defined by Jenkins. This includes information about the job and the specific build that is running. Some of the most commonly used variables are :&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Variable Name&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;JOB_NAME&lt;/td&gt;
&lt;td&gt;Provides the name of the job in Jenkins&lt;/td&gt;
&lt;td&gt;envvars&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JOB_URL&lt;/td&gt;
&lt;td&gt;Gives the URL to the job in the Jenkins UI&lt;/td&gt;
&lt;td&gt;&lt;code&gt;http://localhost:8082/job/envvars/&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BUILD_NUMBER&lt;/td&gt;
&lt;td&gt;Prints the build number in Jenkins console output&lt;/td&gt;
&lt;td&gt;5,6, etc.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BUILD_TAG&lt;/td&gt;
&lt;td&gt;Gives a unique tag for a specific job name and build number&lt;/td&gt;
&lt;td&gt;envvars-build-8&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The Jenkins environment variables list can be viewed using two different ways.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Via env-vars.html :
&lt;/h3&gt;

&lt;p&gt;The environment variables can be viewed on an HTML page. You have to open the page on your Jenkins controller server. The steps to view the jenkins environment variables list are :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;At the address bar of chrome, type &lt;code&gt;${YOUR_JENKINS_HOST}/env-vars.html&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;The ${YOUR_JENKINS_HOST} itself is an environment variable defining the Jenkins host address/Jenkins URL(that would be &lt;code&gt;http://localhost:8080/&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;And env-vars.html is the HTML file consisting of the list of all Jenkins environment variables. &lt;/li&gt;
&lt;li&gt;The page looks like this :&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-1-1024x518.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-1-1024x518.png" alt="The page looks like this :"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Via Windows batch script/shell command :
&lt;/h3&gt;

&lt;p&gt;You can also list all the environment variables by writing the shell command in the groovy script of the Jenkins pipeline. The steps to do the same are :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new pipeline in Jenkins, named ‘ &lt;strong&gt;envvars&lt;/strong&gt; ’.&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Pipeline Script&lt;/strong&gt; , type the following groovy script.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline{
    agent any

    stages{
        stage("Env Variables"){
            steps{
                bat ‘set’                                                     
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The windows batch command used here is “ &lt;strong&gt;set&lt;/strong&gt; ”. This command lists all the Jenkins pipeline environment variables in logs. &lt;/li&gt;
&lt;li&gt;For Linux/Unix, you can use the shell command “ &lt;strong&gt;printenv&lt;/strong&gt; ”, as :
&lt;strong&gt;sh ‘printenv’&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;This can be viewed as :&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-2-1024x523.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-2-1024x523.png" alt="Jenkins Env Va"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading Jenkins Environment Variables
&lt;/h2&gt;

&lt;p&gt;In this section, we will see how you can read your Jenkins environment variables list. Let’s take it one step at a time-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To access the Jenkins environment variables in a pipeline, you can use the env object, eg. &lt;strong&gt;env.BUILD_NUMBER&lt;/strong&gt; will give the current build number of a pipeline. The reference to Jenkins pipeline environment variables is made by surrounding it by &lt;strong&gt;${}&lt;/strong&gt; in the following way: &lt;strong&gt;${env.BUILD_NUMBER}&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;You can also use the short version, which is BUILD_NUMBER. But this variant is quite confusing for some users. The script to read the build number via environment variables is :
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline{
    agent any

    stages{
        stage("Env Build Number"){
            steps{
                echo "The build number is ${env.BUILD_NUMBER}"
                echo "You can also use \${BUILD_NUMBER} -&amp;gt; ${BUILD_NUMBER}"                                                
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The console output of the build processed via the above script is :&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-3-1024x499.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-3-1024x499.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Jenkins Environment Variables
&lt;/h2&gt;

&lt;p&gt;Jenkins environment variables are set both globally as well as locally. Global environment variables can be set via the UI of Jenkins, and local environment variables are set according to the pipeline, being declarative or scripted. The Jenkins pipeline environment variables can also be read from a properties file. For this, we use the &lt;a href="https://plugins.jenkins.io/pipeline-utility-steps/" rel="noopener noreferrer"&gt;Pipeline Utility Steps plugin&lt;/a&gt;. You can also inject the variables during the build startup via the &lt;a href="https://plugins.jenkins.io/envinject/" rel="noopener noreferrer"&gt;EnvInject plugin&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thus, different ways to set Jenkins environment variables are :&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Creating Global Environment Variables
&lt;/h3&gt;

&lt;p&gt;Global environment variables are the variables that can be used in any and every Pipeline or Job built on Jenkins. The global variables are set via the Jenkins console and via the groovy script of a pipeline. The ways to set these global environment variables are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Log in to the Jenkins Server first.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-4-1024x518.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-4-1024x518.png" alt="Jenkins Env Var 4"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;On the upper left side, you will find a dropdown menu on the right of Jenkins; Select the dropdown menu.&lt;/li&gt;
&lt;li&gt;In the dropdown menu, you will find an option for &lt;strong&gt;Manage Jenkins&lt;/strong&gt;. Please click on it.&lt;/li&gt;
&lt;li&gt;In the Manage Jenkins window, click on the &lt;strong&gt;Configure System&lt;/strong&gt;. Here, you can configure global properties, commands, and a lot more.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Funnamed-8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Funnamed-8.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Find the Global &lt;strong&gt;properties&lt;/strong&gt; section.&lt;/li&gt;
&lt;li&gt;In the Global properties section, tick the box of environment variables.&lt;/li&gt;
&lt;li&gt;As you will tick the box, the button to add the Jenkins environment variables list appears.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-6-1024x500.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-6-1024x500.png" alt="Jenkins Env Var 6"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click on &lt;strong&gt;Add&lt;/strong&gt;. Two fields appear- &lt;strong&gt;Name&lt;/strong&gt; and &lt;strong&gt;Value&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You can provide multiple environment variables by clicking on the &lt;strong&gt;add&lt;/strong&gt; button.&lt;/li&gt;
&lt;li&gt;This can be viewed as :&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fpasted-image-0-19-1024x576.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fpasted-image-0-19-1024x576.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Using Java Code in Groovy Script :&lt;/strong&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;You can create Jenkins environment variables by using Java code in the Groovy script. This code is to be written in the pipeline script section when a new pipeline is created.&lt;/li&gt;
&lt;li&gt;The required code is :
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import hudson.EnvVars;
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.slaves.NodeProperty;
import hudson.slaves.NodePropertyDescriptor;
import hudson.util.DescribableList;
import jenkins.model.Jenkins;
public createGlobalEnvironmentVariables(String key, String value){

       Jenkins instance = Jenkins.getInstance();

       DescribableList&amp;lt;NodeProperty&amp;lt;?&amp;gt;, NodePropertyDescriptor&amp;gt; globalNodeProperties = instance.getGlobalNodeProperties();
       List&amp;lt;EnvironmentVariablesNodeProperty&amp;gt; envVarsNodePropertyList = globalNodeProperties.getAll(EnvironmentVariablesNodeProperty.class);

       EnvironmentVariablesNodeProperty newEnvVarsNodeProperty = null;
       EnvVars envVars = null;

       if ( envVarsNodePropertyList == null || envVarsNodePropertyList.size() == 0 ) {
           newEnvVarsNodeProperty = new hudson.slaves.EnvironmentVariablesNodeProperty();
           globalNodeProperties.add(newEnvVarsNodeProperty);
           envVars = newEnvVarsNodeProperty.getEnvVars();
       } else {
           envVars = envVarsNodePropertyList.get(0).getEnvVars();
       }
       envVars.put(key, value)
       instance.save()
}
createGlobalEnvironmentVariables('Var1','Dummy')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In java, createGlobalEnvironmentVariables() method is used to create new global environment variables. Here, the environment variable named, “Var1” is created having the value “Dummy”.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You can populate the environment variable using a Jenkins file.&lt;/li&gt;
&lt;li&gt;There might be a file in your code repository where some configuration properties for your app are saved, Or the file would be available on fileshare somewhere.&lt;/li&gt;
&lt;li&gt;There is a plugin in Jenkins that can be used to read these properties from a file. This is the &lt;a href="https://plugins.jenkins.io/pipeline-utility-steps/" rel="noopener noreferrer"&gt;Pipeline Utility Steps plugin&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-7-1024x494.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-7-1024x494.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;So, firstly &lt;strong&gt;install the Pipeline Utility Steps plugin&lt;/strong&gt;. This provides the &lt;strong&gt;readProperties&lt;/strong&gt; step, which makes it easy to read properties from a file.&lt;/li&gt;
&lt;li&gt;Click on &lt;strong&gt;Manage Jenkins&lt;/strong&gt; on the left column. &lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Manage Plugins&lt;/strong&gt; and go to the &lt;strong&gt;Available Tab&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-8-1024x493.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-8-1024x493.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the filter box, type pipeline utility steps.&lt;/li&gt;
&lt;li&gt;You will find the plugin listed, select the checkbox in front of &lt;strong&gt;Pipeline Utility Steps&lt;/strong&gt; and click on the install button.&lt;/li&gt;
&lt;li&gt;After successful installation, you will find the required plugin under the &lt;strong&gt;Installed&lt;/strong&gt; tab.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-9-1024x495.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-9-1024x495.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Also, define Java &lt;strong&gt;.properties&lt;/strong&gt; file with some key and value pairs. The properties file is used to store the username, password, access tokens etc., which cannot be hardcoded due to privacy. As shown below :&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-10-1024x495.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-10-1024x495.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Username = root
Access_Token = ***************
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Then, you can read these values from the properties file using the &lt;strong&gt;.readProperties&lt;/strong&gt; step, provided by &lt;strong&gt;Pipeline Utility Steps plugin&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fpasted-image-0-1-2-1024x576.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fpasted-image-0-1-2-1024x576.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To read and use the key-value pairs, you have to write the following stage in your groovy script.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;stage(“reading properties from properties file”) {
    steps {
        // Use a script block to do custom scripting
        script {
            def props = readProperties file: 'extravars.properties' 
            env.Username = props.Username
        }
        echo "The username  is $Username"
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;This way, you can read the properties from the file and save them as environment variables. Remember, Jenkins will search the properties file in the local workspace. If your file is not present in the local workspace, do provide the path to the properties file.&lt;/li&gt;
&lt;li&gt;The output to the above groovy script for reading properties file will be :&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-11-1024x499.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-11-1024x499.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Creating Local Environment Variables
&lt;/h3&gt;

&lt;p&gt;The local environment variables are the variables explicitly defined for a particular job in Jenkins. These are defined according to the pipeline and its type. There are declarative pipelines as well as scripted pipelines. Declarative pipelines break down the stages into individual stages that can contain multiple steps; Scripted pipelines, on the other hand, use groovy code and references within the stages without any extra efforts. Because of this difference, the code for creating local environment variables is different for the two types of pipelines.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Using Declarative Pipeline:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;a href="https://www.lambdatest.com/blog/jenkins-declarative-pipeline-examples/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-24062021&amp;amp;utm_term=Praveen" rel="noopener noreferrer"&gt;Jenkins declarative pipeline&lt;/a&gt; uses an environment directive to define local environment variables. The environment directive looks like:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;environment {
       DISABLE_AUTH = 'true'
   }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The environment directive can be placed at the beginning of the pipeline. Then, the variable declared in the directive can be used in all steps. The groovy code for the same is:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
   agent any
   environment {
       DISABLE_AUTH = 'true'                               //can be used in whole pipeline
   }
   stages {
       stage(“Build”) {
           steps {
               echo env.DISABLE_AUTH
           }
       }
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The directive can also be placed in the stages. Thus, that variable can be used only in steps of that particular stage
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
   agent any
   environment {
       DISABLE_AUTH = 'true'
   }
   stages {
       stage(“Build”) {
           environment {
                   ENABLE_AUTH = ‘false’                                 //can be used in this stage only
              }
           steps {
               echo env.DISABLE_AUTH
               echo env.ENABLE_AUTH
           }
       }
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The output to the above groovy script is :&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fpasted-image-0-2-1-1024x576.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fpasted-image-0-2-1-1024x576.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create nodes for the scripted pipeline.&lt;/li&gt;
&lt;li&gt;In the scripted pipelines, use withEnv to define local Jenkins environment variables. The withEnv([“env=value]) {} block can also be used to override any environment variable.&lt;/li&gt;
&lt;li&gt;The simple code to declare local environment variables is :
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node{
   stage('Build') {
       withEnv(["DISABLE_AUTH=true"]) {
         echo env.DISABLE_AUTH   }
   }
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The output to the above groovy script will give the value of environment variable ‘DISABLE_AUTH’ : &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-12-1024x494.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-12-1024x494.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Injecting Environment Variables in Freestyle Projects
&lt;/h3&gt;

&lt;p&gt;Injecting Jenkins environment variables can be done with the help of a plugin. This plugin is the EnvInject plugin. You can install the EnvInject plugin and inject the environment variables during the build startup. This makes it possible to set up a custom environment for all Jenkins jobs. This plugin is used massively in the &lt;a href="https://www.lambdatest.com/blog/jenkins-freestyle-project/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-24062021&amp;amp;utm_term=Praveen" rel="noopener noreferrer"&gt;freestyle projects of Jenkins&lt;/a&gt;. The steps that demonstrate the usage of the EnvInject plugin are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Log in to the Jenkins server with your credentials. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-13-1024x522.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-13-1024x522.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;On the leftmost side, you will find the &lt;strong&gt;New Item&lt;/strong&gt; option. Click on that, and a new window appears.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-14-1024x495.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-14-1024x495.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Enter the Item name and select the Item type from the types available like &lt;strong&gt;freestyle project&lt;/strong&gt; , pipeline, multibranch pipeline, folder etc. &lt;/li&gt;
&lt;li&gt;You can provide the name of an existing job if you want this job to be its replica, or you can leave it blank and then click on &lt;strong&gt;OK&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-15.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-15.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Your freestyle project is created.&lt;/li&gt;
&lt;li&gt;Click on &lt;strong&gt;configure&lt;/strong&gt; to alter the project and to inject Jenkins environment variables.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-16.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-16.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the &lt;strong&gt;Source Code Management&lt;/strong&gt; section, select the None option as we are not fetching code from any code repository. You can choose Git if you want to fetch the code from a Git repository.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-17-1024x500.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-17-1024x500.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You can also select checkboxes in the &lt;strong&gt;Build Triggers&lt;/strong&gt; and &lt;strong&gt;Build Environment&lt;/strong&gt; section to do the necessary settings required.&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Build&lt;/strong&gt; section, click on the drop-down &lt;strong&gt;Add Build Steps&lt;/strong&gt;. (This provides the steps taken before a successful build happens.)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-18-1024x499.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-18-1024x499.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Select &lt;strong&gt;Inject environment variables&lt;/strong&gt; from the drop-down. A dialog box will be added to the build section.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-19-1024x501.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-19-1024x501.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In this box, specify the &lt;strong&gt;Properties File Path&lt;/strong&gt; if you have the environment variables defined in a properties file separately. &lt;/li&gt;
&lt;li&gt;You can also add environment variables in the &lt;strong&gt;Properties Content&lt;/strong&gt; directly without specifying the file path. Here, ‘Username’ is the environment variable with ‘root’ as its value.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-20-1024x498.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-20-1024x498.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You can also select an option from the drop-down, &lt;strong&gt;Post-build Actions&lt;/strong&gt; to be performed after the successful build.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Save and Apply&lt;/strong&gt;. Your freestyle project is configured successfully.&lt;/li&gt;
&lt;li&gt;The output shows that the given environment variable is injected successfully.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Funnamed-1-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Funnamed-1-2.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Capturing bat Command Output in the Environment Variable
&lt;/h2&gt;

&lt;p&gt;You can capture the output of a shell command or batch command as a Jenkins environment variable and use it in later stages of the pipeline. For that you need to use the exact given syntax – bat(script: ‘cmd’, returnStdout:true). This is to force the bat command to return the output to be captured and stored in an environment variable. The steps to store the output into a Jenkins environment variable are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Here, we have taken the dir command, and we will capture its output in an environment variable named LS.&lt;/li&gt;
&lt;li&gt;We have used a script block to save the output in LS, and then we have accessed the same variable and displayed the saved content.&lt;/li&gt;
&lt;li&gt;The groovy script that works for the same is :
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
    agent any

    stages {
        stage("capturing output in Environment Variables") {
            steps {
                script {
                    env.LS = bat(script:'dir', returnStdout: true).trim()
                   // if you access environment variable in the batch command
                    echo $LS
                }
            }
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The trim() method is used to avoid the new line character present in the batch output. It also removes the whitespaces from the beginning and the end of the captured output.&lt;/li&gt;
&lt;li&gt;The console output of a successful build for the pipeline which captures bat output in an environment variable is :&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-22-1024x497.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-22-1024x497.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In Linux/Unix, you can capture the output from the shell command to the Jenkins environment variable. As the shell commands are different, the syntax will be changed. This will be &lt;strong&gt;sh(script:’ls -lah’, returnStdout: true).trim()&lt;/strong&gt;. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As the installation of a plugin is facilitated, new environment variables are added to the jenkins environment variables list. Here, we will install the &lt;a href="https://plugins.jenkins.io/lambdatest-automation/" rel="noopener noreferrer"&gt;LambdaTest Jenkins plugin&lt;/a&gt; and view the environment variables added by this plugin.&lt;/p&gt;

&lt;p&gt;LambdaTest Jenkins plugin helps in pacing up your automated cross browser testing cycles. This easily automates your Selenium test scripts by connecting the Jenkins instance to the LambdaTest Selenium Grid. LambdaTest offers you an expansive library of 2000+ browser and browser versions so as to achieve higher test coverage while performing automation testing using the Selenium suite. You can view the steps to install the LambdaTest Jenkins plugin by clicking &lt;a href="https://www.lambdatest.com/support/docs/jenkins-with-lambdatest/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-24062021&amp;amp;utm_term=Praveen" rel="noopener noreferrer"&gt;here&lt;/a&gt;. Some new environment variables added due to the LambdaTest Jenkins plugin are:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fucarecdn.com%2F4452f03f-e897-425b-945d-786100acd29b%2F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fucarecdn.com%2F4452f03f-e897-425b-945d-786100acd29b%2F" alt="Capture.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fucarecdn.com%2Fd4c5b977-0d9d-4b43-926a-6b380c1f9113%2F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fucarecdn.com%2Fd4c5b977-0d9d-4b43-926a-6b380c1f9113%2F" alt="Capture1.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fucarecdn.com%2F3a808b4f-c9eb-4f5f-92ba-35a4752b6ff9%2F" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fucarecdn.com%2F3a808b4f-c9eb-4f5f-92ba-35a4752b6ff9%2F" alt="Capture2.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When set in the Jenkins pipeline, these environment variables provide the required information for the LambdaTest integration with Jenkins. The groovy script to set these environment variables in a pipeline is :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline{
    agent any
    environment{
          LT_USERNAME='racha10r@gmail.com'
          LT_ACCESS_KEY='iHnnmi0atXDjDKIqckdBH0gU72Uf8zJb76EyNlXjzvGPzvr54'
          LT_TUNNEL=true
        }
    stages{
        stage('printing the environment variables'){
            steps{
                echo env.LT_USERNAME
                echo env.LT_ACCESS_KEY
                echo env.LT_TUNNEL
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a simple groovy script to just set and print the environment variables in the build's console output. The Console Output looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-23-1024x493.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-23-1024x493.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Using Jenkins Pipeline Environment Variables with LambdaTest Jenkins Plugin
&lt;/h3&gt;

&lt;p&gt;Before we jump off to learn about the practical usage of Jenkins environment variables, let us understand the pre-requisites for the plugin.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pre-requisites:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;A Git repository containing Selenium Test:&lt;/strong&gt; This is a sample project with some Nightwatch tests scripts; We will run these tests script from Jenkins on the LambdaTest Selenium Grid Cloud. The URL to the repository is: &lt;a href="https://github.com/LambdaTest/nightwatch-selenium-sample.git" rel="noopener noreferrer"&gt;https://github.com/LambdaTest/nightwatch-selenium-sample.git&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A Jenkins pipeline:&lt;/strong&gt; A new pipeline will be created on Jenkins to run the Nightwatch tests on the LambdaTest Selenium Grid. To achieve this, this project is integrated into LambdaTest.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Credentials of LambdaTest Account:&lt;/strong&gt; The credentials to your LambdaTest profile will be needed. You can easily find the Username and Access Key on the profile section of your LambdaTest Account. (After logging in, click on the rightmost avatar, a dropdown menu will appear and then click on the profile section. You will find the username and Access token there.)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Steps to achieve Integration through Environment Variables
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Start the &lt;strong&gt;Jenkins Server&lt;/strong&gt; by traversing to the location of &lt;strong&gt;Jenkins&lt;/strong&gt; folder in CMD(Command Line Prompt) and typing the command “java -jar jenkins.war”. (You can also change the port on which Jenkins is running by adding --httpPort = &amp;lt;port number&amp;gt; attribute to the previous command.)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-24-1024x546.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-24-1024x546.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;As the Jenkins server is up and running, go to &lt;code&gt;http://localhost:8082/&lt;/code&gt; and Login to the Jenkins Server.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-25-1024x525.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-25-1024x525.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Jenkins Dashboard appears; On the Topmost left side, select the &lt;strong&gt;New Item&lt;/strong&gt; Icon. You will be directed to a new configuration page.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-26-1024x498.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-26-1024x498.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Enter the Name of the pipeline (in this case, it’s “Lambdatest Integration Pipeline”), and select Pipeline from the given options. Click on OK. A new Jenkins pipeline is created.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-27-1024x494.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-27-1024x494.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You will be directed to the configuration page for the Jenkins pipeline, Select Tab Pipeline and add the below Groovy Script in order to create three pipeline stages:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Providing the Environment by LambdaTest Environment Variables:&lt;/strong&gt; By the withEnv construct you will set the environment with variables, LT_USERNAME, LT_ACCESS_KEY, LT_TUNNEL. These variables will then be used in our whole pipeline.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Setup Stage:&lt;/strong&gt; In the setup stage, you will clone the git repository and download the binary file(LT_Windows.zip) required to create an ssh connection through a Tunnel. You will then unzip the zip file and Activate the tunnel by command “LT --user ${LT_USERNAME} --key ${LT_ACCESS_KEY}”.&lt;/li&gt;
&lt;li&gt;Build Stage: After the activation of Tunnel, you will install the required dependencies by commands, npm install and npm install nightwatch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test Stage:&lt;/strong&gt; In the test stage, we will run the tests with the help of Nightwatch. Here the command used is a batch command : bat 'node_modules/.bin/nightwatch -e chrome tests'. Through this command we are also providing the environment in which the Tests should be run(the environments can be chrome, ie, edge, firefox etc.. &lt;a href="https://www.lambdatest.com/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-24062021&amp;amp;utm_term=Praveen" rel="noopener noreferrer"&gt;LambdaTest&lt;/a&gt; eases the process of testing in various environments by providing us to choose the environment as per the need.)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-28-1024x494.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-28-1024x494.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Groovy Script for the Pipeline to create stages is :
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/env groovy

node {
    // Sets the environment variables from LambdaTest for testing
    withEnv(["LT_USERNAME=rachna10r@gmail.com",
    "LT_ACCESS_KEY=z71l7Q9ohS9HhKiCqd690mH0sDu5AYrz8VSB0whO3mZ2JEkNAN",
    "LT_TUNNEL=true"]){

    // Just printing the above set environment variables
    echo env.LT_USERNAME
    echo env.LT_ACCESS_KEY 

   stage('setup') { 

      // Get some code from a GitHub repository
    try{
      git 'https://github.com/LambdaTest/nightwatch-selenium-sample.git'

      //Download Tunnel Binary
     bat 'wget "https://downloads.lambdatest.com/tunnel/v3/windows/64bit/LT_Windows.zip"'

     //Required if unzip is not installed
      bat 'unzip -o LT_Windows.zip'

      //Starting Tunnel Process 
     'LT --user ${LT_USERNAME} --key ${LT_ACCESS_KEY}'
         }
    catch (err){
      echo err
        }
   }
   stage('build') {
      // Installing Dependencies
      bat 'npm install'
      bat 'npm install nightwatch'
    }

   stage('test') {
          try{
        // Running the nightwatch tests with environment set as Chrome
          bat 'node_modules/.bin/nightwatch -e chrome tests'
          }
          catch (err){
          echo err
          }  
   }
   stage('end') {  
    // Printing the success message
     echo "Success" 
     }
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Click on &lt;strong&gt;Apply and Save&lt;/strong&gt;. This will save the pipeline script. And the pipeline is ready to build now.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-29-1024x500.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-29-1024x500.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To run the Jenkins Pipeline, On the Left side menu click on &lt;strong&gt;Build Now&lt;/strong&gt; option. You can also use the Configure option to make changes in the Pipeline Configuration, if required. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-30-1024x494.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-30-1024x494.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;As soon as you click on &lt;strong&gt;Build Now&lt;/strong&gt; , You can view the four stages forming in the Stage View (shown in the above screenshot).&lt;/li&gt;
&lt;li&gt;On the left side of the Stage view, to check whether the Build was successful or not, click on the Build Number and then go to Console Output. (The Blue ball represents that the build was successful, you can view the whole logs by scrolling down in your log pane.)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-31-1024x498.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-31-1024x498.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Checking the Test Cases on the LambdaTest Automation Dashboard
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Log in to your LambdaTest account by visiting URL: &lt;code&gt;https://accounts.lambdatest.com/login&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-32.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-32.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You will be directed to the LambdaTest Dashboard; On the Left Menu, click on the Automation option.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-33-1024x518.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-33-1024x518.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The LambdaTest Automation Dashboard appears. Select Automation Logs Tab on it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-34-1024x518.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FJenkins-Env-Var-34-1024x518.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You will find the Test run from Jenkins with proper configurations. LambdaTest eases the process of testing by providing a video log, screenshot etc. You can view the video log and see how the test is passed and weigh the intricacies of the Nightwatch test run through LambdaTest - Jenkins Integration.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Thus, this way, you can use the LambdaTest Integration with Jenkins for easeful testing. You can also create a freestyle project where after installation of the LambdaTest plugin, the environment variables, LambdaTest credentials etc., can be set manually through a user-friendly UI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up!
&lt;/h2&gt;

&lt;p&gt;Jenkins has a lot of potential in it. With the integration of various plugins and configuration of different platforms like LambdaTest integration with Jenkins; It provides different environments to create a build and facilitates various applications of continuous integration and continuous deployment.&lt;/p&gt;

&lt;p&gt;However, setting up the environment variables is a crucial step in every use case provided by Jenkins. These variables maintain a lot of information required for a successful setup. These are accessed and injected in freestyle projects and pipelines to fulfil essential requirements of the build process and the test process. With Jenkins, we aim to create a robust product or software with excellent test resistance and performance. Thus, ensure that the required Jenkins environment variables are set and can be accessed wherever and whenever necessary.&lt;/p&gt;

&lt;p&gt;Also, don't forget to leave your comments, and if you have any query or question, shoot up to the &lt;a href="https://community.lambdatest.com/" rel="noopener noreferrer"&gt;LambdaTest community&lt;/a&gt; and get it resolved.&lt;/p&gt;

&lt;p&gt;Till then, Happy Testing!&lt;/p&gt;

</description>
      <category>jenkins</category>
      <category>devops</category>
      <category>cicd</category>
    </item>
    <item>
      <title>Comprehensive Guide To Jenkins Declarative Pipeline [With Examples]</title>
      <dc:creator>Abeer Mishra</dc:creator>
      <pubDate>Thu, 10 Jun 2021 08:56:27 +0000</pubDate>
      <link>https://forem.com/aboywithscar/comprehensive-guide-to-jenkins-declarative-pipeline-with-examples-cmj</link>
      <guid>https://forem.com/aboywithscar/comprehensive-guide-to-jenkins-declarative-pipeline-with-examples-cmj</guid>
      <description>&lt;p&gt;Jenkins Pipeline is an automation solution that lets you create simple or complex (template) pipelines via the DSL used in each pipeline. Jenkins provides two ways of developing a pipeline- Scripted and Declarative. Traditionally, Jenkins jobs were created using Jenkins UI called FreeStyle jobs. In Jenkins 2.0, Jenkins introduced a new way to create jobs using the technique called pipeline as code. In &lt;strong&gt;pipeline as code&lt;/strong&gt; technique, jobs are created using a script file that contains the steps to be executed by the job. In &lt;a href="https://www.lambdatest.com/learning-hub/jenkins?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-10062021&amp;amp;utm_term=Praveen" rel="noopener noreferrer"&gt;Jenkins&lt;/a&gt;, that scripted file is called &lt;strong&gt;Jenkinsfile&lt;/strong&gt;. In this blog, we will deep dive into Jenkins Declarative Pipeline with the help of Jenkins declarative pipeline examples.&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;Jenkinsfile&lt;/strong&gt; is just a text file, usually checked in along with the project’s source code in Git repo. Ideally, every application will have its own Jenkinsfile.&lt;/p&gt;

&lt;p&gt;Jenkinsfile can be written in two aspects – &lt;strong&gt;Scripted pipeline syntax &amp;amp; Declarative pipeline syntax&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Jenkins Scripted Pipeline?
&lt;/h2&gt;

&lt;p&gt;Jenkins pipelines are traditionally written as scripted pipelines. Ideally, the scripted pipeline is stored in Jenkins webUI as a Jenkins file. The end-to-end scripted pipeline script is written in Groovy.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It requires knowledge of Groovy programming as a prerequisite.&lt;/li&gt;
&lt;li&gt;Jenkinsfile starts with the word &lt;strong&gt;node&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Can contain standard programming constructs like if-else block, try-catch block, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Sample Scripted Pipeline&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node {
    stage('Stage 1') {
        echo 'hello'
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What is Jenkins Declarative Pipeline?
&lt;/h2&gt;

&lt;p&gt;The Declarative Pipeline subsystem in Jenkins Pipeline is relatively new, and provides a simplified, opinionated syntax on top of the Pipeline subsystems.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The latest addition in Jenkins pipeline job creation technique.&lt;/li&gt;
&lt;li&gt;Jenkins declarative pipeline needs to use the predefined constructs to create pipelines. Hence, it is not flexible as a scripted pipeline.&lt;/li&gt;
&lt;li&gt;Jenkinsfile starts with the word &lt;strong&gt;pipeline&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Jenkins declarative pipeline should be the preferred way to create a Jenkins job as they offer a rich set of features, come with less learning curve &amp;amp; no prerequisite to learn a programming language like Groovy just for the sake of writing pipeline code.&lt;/p&gt;

&lt;p&gt;We can also validate the syntax of the Declarative pipeline code before running the job. It helps to avoid a lot of runtime issues with the build script.&lt;/p&gt;

&lt;h3&gt;
  
  
  Our First Declarative Pipeline
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
    agent any
    stages {
        stage('Welcome Step') {
            steps { 
                echo 'Welcome to LambdaTest'
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We recommend VS Code IDE for writing Jenkins pipeline scripts, especially when creating Jenkins Declarative pipeline examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running Your First Declarative Pipeline
&lt;/h2&gt;

&lt;p&gt;Now that you are well-acquainted with the Jenkins pipeline’s basics, it’s time to dive deeper. In this section, we will learn how to run a Jenkins declarative pipeline. You can refer to our &lt;a href="https://www.lambdatest.com/blog/jenkins-pipeline-tutorial/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-10062021&amp;amp;utm_term=Praveen" rel="noopener noreferrer"&gt;Jenkins Pipeline Tutorial&lt;/a&gt; for more.&lt;/p&gt;

&lt;p&gt;Let us run our Jenkins declarative pipeline step by step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Open Jenkins home page (&lt;code&gt;http://localhost:8080&lt;/code&gt; in local) &amp;amp; click on &lt;strong&gt;New Item&lt;/strong&gt; from the left side menu.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage3-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage3-1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Enter &lt;strong&gt;Jenkins job name&lt;/strong&gt; &amp;amp; choose the style as &lt;strong&gt;Pipeline&lt;/strong&gt; &amp;amp; click &lt;strong&gt;OK&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage5-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage5-1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Scroll down to the &lt;strong&gt;Pipeline&lt;/strong&gt; section &amp;amp; copy-paste your first Declarative style Pipeline code from below to the script textbox.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage4-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage4-1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Click on the Save button &amp;amp; Click on &lt;strong&gt;Build Now&lt;/strong&gt; from the left side menu.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage2-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage2-1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see the build running stage by stage in &lt;strong&gt;Stage&lt;/strong&gt; View.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage1-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage1-1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; To check logs from Build Job, click on any stage &amp;amp; click on the &lt;strong&gt;check logs&lt;/strong&gt; button. Or you can use the &lt;strong&gt;Console Output&lt;/strong&gt; from the left side menu to see the logs for the build.&lt;/p&gt;

&lt;h3&gt;
  
  
  Console Output
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FConsole-Output-1024x383.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FConsole-Output-1024x383.png" alt="Console Output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Jenkins Declarative Pipeline Syntax
&lt;/h2&gt;

&lt;p&gt;In this section, we will look at the most commonly used Jenkins declarative pipeline examples or syntax. Typically, declarative pipelines contain one or more declarative steps or directives, as explained below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;pipeline&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Entire Declarative pipeline script should be written inside the &lt;strong&gt;pipeline&lt;/strong&gt; block. It’s a &lt;strong&gt;mandatory&lt;/strong&gt; block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;agent&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Specify where the Jenkins build job should run. agent can be at pipeline level or stage level. It’s mandatory to define an agent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Possible values-&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;any&lt;/strong&gt; – Run Job or Stage on any available agent.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
     agent any
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;none&lt;/strong&gt; – Don’t allocate any agent globally for the pipeline. Every stage should specify their own agent to run.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
     agent none
}   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;label&lt;/strong&gt; – Run the job in agent which matches the label given here. Remember &lt;a href="https://www.lambdatest.com/blog/what-is-jenkins/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-10062021&amp;amp;utm_term=Praveen" rel="noopener noreferrer"&gt;Jenkins CI/CD&lt;/a&gt; can work on Master/Agent architecture. Master nodes can delegate the jobs to run in Agent nodes. Nodes on creation given a name &amp;amp; label to identify them later.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;E.g All linux nodes can be labeled as linux-machine&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
       agent {
           label 'linux-machine'
       }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;docker&lt;/strong&gt; – Run the job in given Docker container&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A sample can be found here at &lt;a href="https://github.com/iamvickyav/jenkins-declarative-pipeline-notes/blob/master/declarative-syntax-samples.md#agent" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  stages
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;stages&lt;/strong&gt; block constitutes different executable stage blocks. At least one stage block is mandatory inside stages block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
       agent {
           label 'linux-machine'
       }
     stages {
     }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  stage
&lt;/h2&gt;

&lt;p&gt;stage block contains the actual execution steps. Stage block has to be defined within stages block. It’s mandatory to have at least one stage block inside the stage block. Also its mandatory to name each stage block &amp;amp; this name will be shown in the &lt;strong&gt;Stage View&lt;/strong&gt; after we run the job.&lt;/p&gt;

&lt;p&gt;In below example, the stage is named as “ &lt;strong&gt;build step&lt;/strong&gt; ”&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
       agent {
           label 'linux-machine'
       }
     stages {
         stage('build step') {
         }
     }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A sample can be found here at &lt;a href="https://github.com/iamvickyav/jenkins-declarative-pipeline-notes/blob/master/declarative-syntax-samples.md#stage" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  steps
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;steps&lt;/strong&gt; block contains the actual build step. It’s mandatory to have at least one step block inside a stage block.&lt;/p&gt;

&lt;p&gt;Depending on the Agent’s operating system (where Jenkins job runs), we can use shell, bat, etc., inside the steps command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
     agent any
     stages {
         stage('build step') {
              steps {
                 echo "Build stage is running"
              }
         }
     }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Scripted Pipeline in Jenkins job&lt;/p&gt;

&lt;p&gt;Sample can be found here at &lt;a href="https://github.com/iamvickyav/jenkins-declarative-pipeline-notes/blob/master/declarative-syntax-samples.md#steps" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  parameters
&lt;/h2&gt;

&lt;p&gt;The parameters directive provides a way for Jenkins job to interact with Jenkins CI/CD users during the running of the build job.&lt;/p&gt;

&lt;p&gt;parameter can be of the following types – &lt;strong&gt;string, text, booleanParam, choice&lt;/strong&gt; &amp;amp; &lt;strong&gt;password&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;string&lt;/strong&gt; – Accepts a value of String type from Jenkins user.&lt;/p&gt;

&lt;p&gt;E.g.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;string(name: ‘NAME’, description: ‘Please tell me your name?’)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;text&lt;/strong&gt; – Accepts multi line value from Jenkins user E.g.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;text(name: ‘DESC’, description: ‘Describe about the job details’)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;booleanParam&lt;/strong&gt; – Accepts a true/false value from Jenkins user E.g.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;booleanParam(name: ‘SKIP_TEST’, description: ‘Want to skip running Test cases?’)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;choice&lt;/strong&gt; – Jenkins user can choose one among the choices of value provided E.g.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;choice(name: ‘BRANCH’, choices: [‘Master’, ‘Dev’], description: ‘Choose the branch’)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;password&lt;/strong&gt; – Accepts a secret like password from Jenkins user E.g.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;password(name: ‘SONAR_SERVER_PWD’, description: ‘Enter SONAR password’)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s look at a sample on how to use parameters directive-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
    agent any
    parameters {
        string(name: 'NAME', description: 'Please tell me your name?')

        text(name: 'DESC', description: 'Describe about the job details')

        booleanParam(name: 'SKIP_TEST', description: 'Want to skip running Test cases?')

        choice(name: 'BRANCH', choices: ['Master', 'Dev'], description: 'Choose branch')

        password(name: 'SONAR_SERVER_PWD', description: 'Enter SONAR password')
    }
    stages {
        stage('Printing Parameters') {
            steps {
                echo "Hello ${params.NAME}"

                echo "Job Details: ${params.DESC}"

                echo "Skip Running Test case ?: ${params.SKIP_TEST}"

                echo "Branch Choice: ${params.BRANCH}"

                echo "SONAR Password: ${params.SONAR_SERVER_PWD}"
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-9.06.10-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-9.06.10-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If a parameters directive is used in the pipeline, Jenkins CI/CD can sense that it needs to accept the user’s input while running the job. Hence Jenkins will change the &lt;strong&gt;Build now&lt;/strong&gt; link in the left side menu to &lt;strong&gt;Build with parameters&lt;/strong&gt; link.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-01-31-at-2.13.34-PM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-01-31-at-2.13.34-PM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we click on the &lt;strong&gt;Build with Parameters&lt;/strong&gt; link, Jenkins CI/CD will let us pass values for the parameters we configured in the declarative pipeline.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FBuild-with-Parameters-1024x465.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FBuild-with-Parameters-1024x465.png" alt="Build with Parameters"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we enter each parameter’s values, we can hit the &lt;strong&gt;build&lt;/strong&gt; button to run the job.&lt;/p&gt;

&lt;h2&gt;
  
  
  script
&lt;/h2&gt;

&lt;p&gt;script block helps us run &lt;strong&gt;Groovy&lt;/strong&gt; code inside the Jenkins declarative pipeline.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
    agent any
    parameters {
        string(name: 'NAME', description: 'Please tell me your name')
        choice(name: 'GENDER', choices: ['Male', 'Female'], description: 'Choose Gender')
    }
    stages {
        stage('Printing name') {
            steps {
                script {
                    def name = "${params.NAME}"
                    def gender = "${params.GENDER}"
                    if(gender == "Male") {
                        echo "Mr. $name"    
                    } else {
                        echo "Mrs. $name"
                    }
                }
            }
        }
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-9.07.04-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-9.07.04-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;script&lt;/strong&gt; block is wrapped inside the &lt;strong&gt;steps&lt;/strong&gt; block. In the above example, we are printing the name passed as parameter suffixed with Mr. or Mrs. based on the Gender chosen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-01-31-at-2.31.06-PM-1024x239.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-01-31-at-2.31.06-PM-1024x239.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We used &lt;strong&gt;build with parameters&lt;/strong&gt; to pass params at the time of running the job.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-01-31-at-2.31.22-PM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-01-31-at-2.31.22-PM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  environment
&lt;/h2&gt;

&lt;p&gt;Key value pairs which helps passing values to job during job runtime from outside of Jenkinsfile. It’s one way of externalizing configuration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example-&lt;/strong&gt; Usually, &lt;a href="https://www.lambdatest.com/blog/jenkins-freestyle-project/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-10062021&amp;amp;utm_term=Praveen" rel="noopener noreferrer"&gt;Jenkins jobs&lt;/a&gt; will run in a separate server. We may not be sure where the installation path of JAVA or JMeter is that server. Hence these are ideal candidates to be configured in Environment variables &amp;amp; passed during job run.&lt;/p&gt;

&lt;h3&gt;
  
  
  Method 1 : Configure Environment Variable in Jenkins CI/CD portal
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Open Jenkins Server URL (&lt;code&gt;http://localhost:8080&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Click on Manage Jenkins from the left sidebar menu.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-9.08.04-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-9.08.04-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Click on &lt;strong&gt;Configure System&lt;/strong&gt; under System Configuration.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-9.08.25-AM-1024x272.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-9.08.25-AM-1024x272.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Scroll down to the &lt;strong&gt;Global Properties&lt;/strong&gt; section. This is where we will add our Environment variables.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Click on the &lt;strong&gt;Add&lt;/strong&gt; button under Environment Variables &amp;amp; enter the Key &amp;amp; value.&lt;/p&gt;

&lt;p&gt;We have added the Java installation path under the variable name &lt;strong&gt;JAVA_INSTALLATION_PATH&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Funnamed.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Funnamed.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; Click on &lt;strong&gt;Save&lt;/strong&gt; Button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Refer Environment variable in Jenkinsfile&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
We can refer to the Environment variables in declarative pipeline using the &lt;code&gt;${} syntax&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
    agent any
    stages {
        stage('Initialization') {
            steps {
                echo "${JAVA_INSTALLATION_PATH}"
            }
        }
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-9.10.17-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-9.10.17-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Method 2 : Creating &amp;amp; Referring Environment Variable in Jenkinsfile
&lt;/h3&gt;

&lt;p&gt;We can create key value pairs of environment variables under &lt;strong&gt;environment&lt;/strong&gt; block. It’s an &lt;strong&gt;optional&lt;/strong&gt; block under pipeline.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
    agent any
    environment { 
        DEPLOY_TO = 'production'
    }
    stages {
        stage('Initialization') {
            steps {
                echo "${DEPLOY_TO}"
            }
        }
    }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.00.02-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.00.02-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Method 3 : Initialize Environment variables using sh scripts in Jenkinsfile
&lt;/h3&gt;

&lt;p&gt;Let’s say we need the timestamp when the job gets run for logging purposes. We can create an Environment variable which can hold the timestamp. But how to initialize it ?&lt;/p&gt;

&lt;p&gt;We can use the shell script to fetch the current timestamp and assign it to the Environment variable.&lt;/p&gt;

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

&lt;p&gt;The following command will print date &amp;amp; time in shell&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;  date '+%A %W %Y %X' 
Tuesday 03 2021 22:03:31
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets see how to use the above command to initialize the Environment variable in Jenkinsfile.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
    agent any
    stages {
        stage('Initialization') {
            environment { 
                   JOB_TIME = sh (returnStdout: true, script: "date '+%A %W %Y %X'").trim()
            }
            steps {
                sh 'echo $JOB_TIME'
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.00.26-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.00.26-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;returnStdout:&lt;/strong&gt; true makes sh step returning the output of the command so you can assign it to a variable.&lt;/p&gt;

&lt;p&gt;Sample can be found here at &lt;a href="https://github.com/iamvickyav/jenkins-declarative-pipeline-notes/blob/master/declarative-syntax-samples.md#environment-variables" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;credentials() is a special method that can be used inside the environment block. This method helps loading the credentials defined at Jenkins configuration.&lt;/p&gt;

&lt;p&gt;Lets see it with an example. First lets configure credential in Jenkins CI/CD-&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating Credential in Jenkins portal&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Open Jenkins Server URL (&lt;code&gt;http://localhost:8080&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Click on &lt;strong&gt;Manage Jenkins&lt;/strong&gt; from the left sidebar menu.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.01.34-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.01.34-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Click on &lt;strong&gt;Manage&lt;/strong&gt; Credentials under &lt;strong&gt;Security&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.01.59-AM-1024x263.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.01.59-AM-1024x263.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Click on the &lt;strong&gt;Global&lt;/strong&gt; hyperlink.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage6.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Click on Add &lt;strong&gt;Credentials&lt;/strong&gt; from the left side menu.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.02.32-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.02.32-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For demonstration, let me use the following values&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Kind – Username with password&lt;/li&gt;
&lt;li&gt;Scope – Global&lt;/li&gt;
&lt;li&gt;Username – admin&lt;/li&gt;
&lt;li&gt;Password – root123&lt;/li&gt;
&lt;li&gt;ID – MY_SECRET&lt;/li&gt;
&lt;li&gt;Description – Secret to access server files&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage9-1-1024x396.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage9-1-1024x396.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; Click the &lt;strong&gt;OK&lt;/strong&gt; button. Now our credentials are configured.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Referring credential in Jenkinsfile&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can use the special method called &lt;strong&gt;credentials()&lt;/strong&gt; to load credentials we configured. We need to use the ID we used while configuring credentials to load a particular credential.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example-&lt;/strong&gt; credentials(‘MY_SECRET’)&lt;/p&gt;

&lt;p&gt;To refer to the username, append the word &lt;strong&gt;_USR&lt;/strong&gt; to the variable we assigned credentials() output &amp;amp; append the word &lt;strong&gt;_PSW&lt;/strong&gt; to get the password.&lt;/p&gt;

&lt;p&gt;Example- Lets load the credential at &lt;strong&gt;MY_CRED&lt;/strong&gt; variable using the &lt;strong&gt;credentials(‘MY_SECRET’)&lt;/strong&gt; method. We need to append &lt;strong&gt;_USR ($MY_CRED_USR)&lt;/strong&gt; &amp;amp; &lt;strong&gt;_PSW ($MY_CRED_PSW)&lt;/strong&gt; to MY_CRED variable to get the username &amp;amp; password.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
    agent any
  environment { 
    MY_CRED = credentials('MY_SECRET') 
    }
    stages {
        stage('Load Credentials') {
            steps {
                echo "Username is $MY_CRED_USR"
                echo "Password is $MY_CRED_PSW"
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.03.09-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.03.09-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Interestingly, Jenkins print username &amp;amp; password as **** to avoid accidental leakage of credentials.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage13.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage13.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  when
&lt;/h2&gt;

&lt;p&gt;Acts like if condition to decide whether to run the particular stage or not . Its an &lt;strong&gt;optional&lt;/strong&gt; block.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;when&lt;/strong&gt; block
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
     agent any
     stages {
         stage('build') {
              when {
                  branch 'dev'             
              }
              steps {
                 echo "Working on dev branch"
              }
         }
     }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.03.58-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.03.58-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;when block using &lt;strong&gt;Groovy expression&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
     agent any
     stages {
         stage('build') {
              when {
                  expression {
                     return env.BRANCH_NAME == 'dev';
                  }             
              }
              steps {
                 echo "Working on dev branch"
              }
         }
     }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.04.39-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.04.39-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;when block with &lt;strong&gt;environment variables&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
    agent any
    environment { 
        DEPLOY_TO = 'production'
    }
    stages {
        stage('Welcome Step') {
                when { 
    environment name: 'DEPLOY_TO', value: 'production'
}
            steps { 
                echo 'Welcome to LambdaTest'
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.04.57-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.04.57-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;when block with &lt;strong&gt;multiple conditions &amp;amp; all conditions should be satisfied&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
    agent any
    environment { 
        DEPLOY_TO = 'production'
    }
    stages {
        stage('Welcome Step') {
            when { 
                allOf { 
                    branch 'master'; 
                    environment name: 'DEPLOY_TO', value: 'production'
                } 
            }
            steps { 
                echo 'Welcome to LambdaTest'
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.05.27-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.05.27-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;when block with &lt;strong&gt;multiple conditions &amp;amp; any of the given conditions should be satisfied&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
pipeline {&lt;br&gt;
    agent any&lt;br&gt;
    environment { &lt;br&gt;
        DEPLOY_TO = 'production'&lt;br&gt;
    }&lt;br&gt;
    stages {&lt;br&gt;
        stage('Welcome Step') {&lt;br&gt;
            when { &lt;br&gt;
                anyOf { &lt;br&gt;
                    branch 'master';&lt;br&gt;
                    branch 'staging' &lt;br&gt;
                } &lt;br&gt;
            }&lt;br&gt;
            steps { &lt;br&gt;
                echo 'Welcome to LambdaTest'&lt;br&gt;
            }&lt;br&gt;
        }&lt;br&gt;
    }&lt;br&gt;
}&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.05.50-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.05.50-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sample can be found here at &lt;a href="https://github.com/iamvickyav/jenkins-declarative-pipeline-notes/blob/master/declarative-syntax-samples.md#when" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  tools
&lt;/h2&gt;

&lt;p&gt;This block lets us add pre configured tools like Maven or Java to our job’s PATH. It’s an &lt;strong&gt;optional&lt;/strong&gt; block.&lt;/p&gt;

&lt;p&gt;To use any tool, they have to be pre-configured under the &lt;strong&gt;Global Tools Configuration&lt;/strong&gt; section. For this example, let’s see how to configure Maven. You can also refer to our &lt;a href="https://www.lambdatest.com/blog/selenium-maven-jenkins-integration/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-10062021&amp;amp;utm_term=Praveen" rel="noopener noreferrer"&gt;Jenkins Maven integration tutorial&lt;/a&gt; for more information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Open Jenkins Server URL (&lt;code&gt;http://localhost:8080&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Click on &lt;strong&gt;Manage Jenkins&lt;/strong&gt; from the left sidebar menu.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.01.34-AM-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.01.34-AM-1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt; : Click on &lt;strong&gt;Global Tools Configuration&lt;/strong&gt; under System Configuration.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.06.40-AM-1024x256.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.06.40-AM-1024x256.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Scroll down to the &lt;strong&gt;Maven&lt;/strong&gt; section &amp;amp; click on &lt;strong&gt;Maven Installations&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.07.12-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.07.12-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Click on the &lt;strong&gt;Add Maven&lt;/strong&gt; button. Enter the following values in the configuration.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Name – Maven 3.5.0&lt;/li&gt;
&lt;li&gt;MAVEN_HOME – Enter the maven installation path in local&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage10-1024x276.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage10-1024x276.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Alternatively we can download Maven from Internet instead of pointing to the local installation path by enabling the Install Automatically checkbox.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; Click on &lt;strong&gt;Add Installer&lt;/strong&gt; button &amp;amp; choose &lt;strong&gt;Install from Apache&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage12-1024x348.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage12-1024x348.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt; Choose the Maven version to download. We have chosen the Maven version &lt;strong&gt;3.6.3&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage11-1024x314.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage11-1024x314.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8:&lt;/strong&gt; Click on the &lt;strong&gt;Save&lt;/strong&gt; button.&lt;/p&gt;

&lt;p&gt;Refer to Maven tool in Pipeline in tools block with the name we used while configuring in Global Tools Configuration (MAVEN_PATH in this example).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
pipeline {&lt;br&gt;
    agent any&lt;br&gt;
    tools {&lt;br&gt;
        maven 'MAVEN_PATH' &lt;br&gt;
    }&lt;br&gt;
    stages {&lt;br&gt;
         stage('Load Tools') {&lt;br&gt;
              steps {&lt;br&gt;
                 sh "mvn -version"&lt;br&gt;
              }&lt;br&gt;
         }&lt;br&gt;
     }&lt;br&gt;
}&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.08.09-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.08.09-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sample can be found here at &lt;a href="https://github.com/iamvickyav/jenkins-declarative-pipeline-notes/blob/master/declarative-syntax-samples.md#tools" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Console Output-&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Run the job &amp;amp; we should see the mvn -version command response in console output-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage14.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2Fimage14.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Similarly we can also configure &amp;amp; use tools like Java, Gradle, Git etc from tools block in pipeline code.&lt;/p&gt;

&lt;h2&gt;
  
  
  parallel
&lt;/h2&gt;

&lt;p&gt;parallel blocks allow us to &lt;strong&gt;run multiple stage blocks concurrently&lt;/strong&gt;. It’s ideal to parallelize stages which can run independently. We can define agents for each stage within a parallel block, so each stage will run on its own agent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example-&lt;/strong&gt; When we want to run a piece of script in windows agent &amp;amp; another script in linux agent as part of the build, we can make them run concurrently using parallel blocks.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
pipeline {&lt;br&gt;
    agent any&lt;br&gt;
    stages {&lt;br&gt;
           stage('Parallel Stage') {&lt;br&gt;
              parallel {&lt;br&gt;
                stage('windows script') {&lt;br&gt;
                    agent {&lt;br&gt;
                        label "windows"&lt;br&gt;
                    }&lt;br&gt;
                    steps {&lt;br&gt;
                            echo "Running in windows agent"&lt;br&gt;
        bat 'echo %PATH%'&lt;br&gt;
                    }&lt;br&gt;
                }&lt;br&gt;
                stage('linux script') {&lt;br&gt;
                    agent {&lt;br&gt;
                        label "linux"&lt;br&gt;
                    }&lt;br&gt;
                    steps {&lt;br&gt;
                       sh "Running in Linux agent"&lt;br&gt;
                    }&lt;br&gt;
                }&lt;br&gt;
             }&lt;br&gt;
        }&lt;br&gt;
    }&lt;br&gt;
}&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Sample can be found here at &lt;a href="https://github.com/iamvickyav/jenkins-declarative-pipeline-notes/blob/master/declarative-syntax-samples.md#parallel" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  post
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;post&lt;/strong&gt; block contains additional actions to be performed on completion of the pipeline execution. It can contain one or many of the following conditional blocks – always, changed, aborted, failure, success, unstable etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;post block conditions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;always –&lt;/strong&gt; run this post block irrespective of the pipeline execution status&lt;br&gt;&lt;br&gt;
&lt;strong&gt;changed –&lt;/strong&gt; run this post block only if the pipeline’s execution status is different from the previous build run. E.g., the build failed at an earlier run &amp;amp; ran successfully this time.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;aborted –&lt;/strong&gt; if the build is aborted in the middle of the run. Usually due to manual stopping of the build run&lt;br&gt;&lt;br&gt;
&lt;strong&gt;failure –&lt;/strong&gt; if the build status is failure&lt;br&gt;&lt;br&gt;
&lt;strong&gt;success –&lt;/strong&gt; if the build ran successfully&lt;br&gt;&lt;br&gt;
&lt;strong&gt;unstable –&lt;/strong&gt; build is successful but not healthy. E.g. On a particular build run, test cases ran successfully, but test coverage % is less than expected, then the build can be marked as unstable&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
pipeline {&lt;br&gt;
     agent any&lt;br&gt;
     stages {&lt;br&gt;
         stage('build step') {&lt;br&gt;
              steps {&lt;br&gt;
                 echo "Build stage is running"&lt;br&gt;
              }&lt;br&gt;
         }&lt;br&gt;
     }&lt;br&gt;
     post {&lt;br&gt;
         always {&lt;br&gt;
             echo "You can always see me"&lt;br&gt;
         }&lt;br&gt;
         success {&lt;br&gt;
              echo "I am running because the job ran successfully"&lt;br&gt;
         }&lt;br&gt;
         unstable {&lt;br&gt;
              echo "Gear up ! The build is unstable. Try fix it"&lt;br&gt;
         }&lt;br&gt;
         failure {&lt;br&gt;
             echo "OMG ! The build failed"&lt;br&gt;
         }&lt;br&gt;
     }&lt;br&gt;
}&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.09.29-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.09.29-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sample can be found here at &lt;a href="https://github.com/iamvickyav/jenkins-declarative-pipeline-notes/blob/master/declarative-syntax-samples.md#post" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Marking build as Unstable
&lt;/h2&gt;

&lt;p&gt;There are scenarios where we don’t want to mark build as failure but want to mark build as unstable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example-&lt;/strong&gt; When test case coverage doesn’t cross the threshold we expect, we can mark the build as &lt;strong&gt;UNSTABLE&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
pipeline {&lt;br&gt;
    agent any&lt;br&gt;
    tools {&lt;br&gt;
        maven 'MAVEN_PATH'&lt;br&gt;
        jdk 'jdk8'&lt;br&gt;
    }&lt;br&gt;
    stages {&lt;br&gt;
        stage("Tools initialization") {&lt;br&gt;
            steps {&lt;br&gt;
                sh "mvn --version"&lt;br&gt;
                sh "java -version"&lt;br&gt;
            }&lt;br&gt;
        }&lt;br&gt;
        stage("Checkout Code") {&lt;br&gt;
            steps {&lt;br&gt;
                git branch: 'master',&lt;br&gt;
                url: "https://github.com/iamvickyav/spring-boot-data-H2-embedded.git"&lt;br&gt;
            }&lt;br&gt;
        }&lt;br&gt;
        stage("Building Application") {&lt;br&gt;
            steps {&lt;br&gt;
               sh "mvn clean package"&lt;br&gt;
            }&lt;br&gt;
        }&lt;br&gt;
        stage("Code coverage") {&lt;br&gt;
           steps {&lt;br&gt;
               jacoco(&lt;br&gt;
                    execPattern: '**/target/**.exec',&lt;br&gt;
                    classPattern: '**/target/classes',&lt;br&gt;
                    sourcePattern: '**/src',&lt;br&gt;
                    inclusionPattern: 'com/iamvickyav/**',&lt;br&gt;
                    changeBuildStatus: true,&lt;br&gt;
                    minimumInstructionCoverage: '30',&lt;br&gt;
                    maximumInstructionCoverage: '80')&lt;br&gt;
               }&lt;br&gt;
           }&lt;br&gt;
        }&lt;br&gt;
 }&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.09.53-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.09.53-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sample can be found here at &lt;a href="https://github.com/iamvickyav/jenkins-declarative-pipeline-notes/blob/master/declarative-syntax-samples.md#mark-build-as-unstable-based-on-code-coverage" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;jacoco()&lt;/strong&gt; is a special method which helps us configure Jacoco reports including the minimum &amp;amp; maximum coverage threshold. In the above example, min coverage (minimumInstructionCoverage) check is set as 30 &amp;amp; max coverage (maximumInstructionCoverage) check is set as 80.&lt;/p&gt;

&lt;p&gt;So if the code coverage is-&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Less than 30 –&lt;/strong&gt; Build will be marked as Failure.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Between 30 &amp;amp; 80 –&lt;/strong&gt; Build will be marked as Unstable.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Above 80 –&lt;/strong&gt; Build will be marked as Success.&lt;/p&gt;

&lt;h2&gt;
  
  
  triggers
&lt;/h2&gt;

&lt;p&gt;Instead of triggering the build manually, we can configure build to run in certain time intervals using the triggers block. We can use the special method called cron() within triggers block to configure the build schedule.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding cron&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Cron configuration contains 5 fields representing minute (0-59), hour (0-23), day of the month (1-31), month (1-12), day of the week (0-7)&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Every 15 minutes – H/15 * * * *&lt;br&gt;&lt;br&gt;
Every 15 minutes but only between Monday &amp;amp; Friday – H/15 * * * 1-5&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
pipeline {&lt;br&gt;
    agent any&lt;br&gt;
    triggers {&lt;br&gt;
        cron('H/15 * * * *')&lt;br&gt;
    }&lt;br&gt;
    stages {&lt;br&gt;
        stage('Example') {&lt;br&gt;
            steps {&lt;br&gt;
                echo 'Hello World'&lt;br&gt;
            }&lt;br&gt;
        }&lt;br&gt;
    }&lt;br&gt;
}&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.10.18-AM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F04%2FScreenshot-2021-02-13-at-10.10.18-AM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sample can be found here at &lt;a href="https://github.com/iamvickyav/jenkins-declarative-pipeline-notes/blob/master/declarative-syntax-samples.md#triggers-sample" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;In this blog, we have done an in-depth dive into Jenkins Declarative pipeline examples and their usage. Instead of configuring build steps using UI in a remote Jenkins portal, we would always recommend you to prefer creating Jenkinsfile with Declarative pipeline syntax. Jenkinsfile, since part of the application’s source code, will provide more control over CI/CD steps to developers. That’s the best way to make the most of Jenkins CI/CD and all the features it has to offer!&lt;/p&gt;

&lt;p&gt;Happy building &amp;amp; testing!&lt;/p&gt;

</description>
      <category>jenkins</category>
      <category>cicd</category>
      <category>selenium</category>
      <category>devops</category>
    </item>
    <item>
      <title>How To Use Shared Libraries In A Jenkins Pipeline?</title>
      <dc:creator>Abeer Mishra</dc:creator>
      <pubDate>Wed, 28 Apr 2021 07:41:09 +0000</pubDate>
      <link>https://forem.com/aboywithscar/how-to-use-shared-libraries-in-a-jenkins-pipeline-4e7</link>
      <guid>https://forem.com/aboywithscar/how-to-use-shared-libraries-in-a-jenkins-pipeline-4e7</guid>
      <description>&lt;p&gt;As Agile methodology picks pace, tools that enable faster time to deliver software got more prominence. &lt;a href="https://www.lambdatest.com/learning-hub/jenkins?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-28042021&amp;amp;utm_term=Praveen" rel="noopener noreferrer"&gt;Jenkins&lt;/a&gt;, arguably the widely used DevOps automation tool, helps companies achieve the full benefits of Agile methodology. For most developers &amp;amp; testers, Jenkins is not something new. It actually became part and parcel of their job description. In this article, let’s discuss how to use Jenkins effectively by using Jenkins Shared Library.&lt;/p&gt;

&lt;p&gt;For beginners on Jenkins, I would recommend reading our article &lt;a href="https://www.lambdatest.com/blog/jenkins-pipeline-tutorial/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-28042021&amp;amp;utm_term=Praveen" rel="noopener noreferrer"&gt;Best Jenkins Pipeline Tutorial&lt;/a&gt; For Beginners before continuing to read this Jenkins pipeline shared library tutorial.&lt;/p&gt;

&lt;h2&gt;
  
  
  Jenkinsfile
&lt;/h2&gt;

&lt;p&gt;In the world of Jenkins, a pipeline is the smallest unit every Jenkins user interacts with. Jenkins pipeline can be defined either by using a Jenkinsfile or GUI (Graphical user interface). We recommend Jenkinsfile over GUI, as GUI may prove ineffective for complex requirements.&lt;/p&gt;

&lt;p&gt;Jenkinsfile is just a text file where we write pipeline code to define the Jenkins pipeline. It can be checked into source control like Git along with our project source code. In most cases, every application will have its own Jenkinsfile to build, test &amp;amp; deploy&lt;/p&gt;

&lt;p&gt;There are two ways of writing a Jenkinsfile – One is called Scripted Pipeline, where syntax for pipeline is strictly Groovy. Another is a relatively new way of writing Jenkinsfile called Declarative Pipeline.&lt;/p&gt;

&lt;p&gt;For starters,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If Jenkinsfile starts with the word node, then it’s a Scripted pipeline.&lt;/li&gt;
&lt;li&gt;If Jenkinsfile starts with the word pipeline, then it’s a Declarative pipeline. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We would recommend using Declarative Pipeline as it offers more advantages over Scripted Pipeline.&lt;/p&gt;

&lt;h2&gt;
  
  
  Jenkins Shared Library
&lt;/h2&gt;

&lt;p&gt;In today’s Microservices world, large monolith applications are broken down into small applications &amp;amp; deployed separately. Interestingly, most of these applications have the same steps to build, test &amp;amp; deploy the application. So instead of repeating those steps for every application, we can actually create a shared library, which can be used across applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Use Jenkins Shared Library?
&lt;/h3&gt;

&lt;p&gt;Let’s say we have five different Spring Boot applications in our Microservice architecture. All of them need to be built using Maven, run Unit &amp;amp; Integration tests to ensure the integrity of code, packed as a JAR/WAR file &amp;amp; pushed to the artifactory.&lt;/p&gt;

&lt;p&gt;Typically, all five applications need their own Jenkinsfile, but the content of the Jenkinsfiles is going to be mostly the same. Jenkins Shared Library avoids this repetition of pipeline code by creating a shared library.&lt;/p&gt;

&lt;p&gt;In brief, here are steps to create &amp;amp; use the Jenkins shared library:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a separate git repo for the Jenkins pipeline library &amp;amp; push the shared library code to that repo.&lt;/li&gt;
&lt;li&gt;Integrate the shared library repo in Jenkins under the Manage Jenkins section.&lt;/li&gt;
&lt;li&gt;Create Jenkinsfile in the project. In that Jenkinsfile, Import &amp;amp; use the shared library.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Creating Jenkins Shared Library
&lt;/h3&gt;

&lt;p&gt;Jenkins Shared Libraries are usually pushed into a separate Git repository &amp;amp; checked out by Jenkins job during the job run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps to create Jenkins shared library:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Create vars folder&lt;/p&gt;

&lt;p&gt;Create a separate project directory. Inside the project directory, create a directory called vars, which will host the shared library’s source code (usually in files with extension .groovy)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Create Groovy file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vars 
| --- welcomeJob.groovy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Create call() function inside Groovy file&lt;/p&gt;

&lt;p&gt;When a shared library is referred from the Jenkins job, Jenkins, by default, will invoke the call() function within our Groovy file. Consider the call() function like the main() method in Java. We can also specify parameters for the call() function if we want to.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def call(String name = 'User') {
        echo "Welcome, ${name}."
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the name is the parameter. Default value ‘User’ will be assigned to the name in case the parameter is not passed by Jenkinsfile.&lt;/p&gt;

&lt;p&gt;Now commit &amp;amp; push the contents of the vars folder to a remote git repository.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure Shared Library in Jenkins
&lt;/h3&gt;

&lt;p&gt;Now it’s time to configure the Shared Library in Jenkins.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps to configure Jenkins pipeline library:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Open &lt;strong&gt;Jenkins&lt;/strong&gt; in your browser. (if local, &lt;code&gt;http://localhost:8080/&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Click on &lt;strong&gt;manage jenkins&lt;/strong&gt; on the left side menu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Click on &lt;strong&gt;configure system&lt;/strong&gt;. Scroll down until you find the &lt;strong&gt;Global Pipeline Libraries&lt;/strong&gt; section.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Under the &lt;strong&gt;Library&lt;/strong&gt; section, configure values as below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Name (remember, we will refer to this shared library from Jenkinsfile using this name).&lt;/li&gt;
&lt;li&gt;Default version (branch name of our Shared Library git repo).&lt;/li&gt;
&lt;li&gt;Under the Retrieval method, choose Modern SCM.&lt;/li&gt;
&lt;li&gt;Under Source Code Management, choose Git.

&lt;ul&gt;
&lt;li&gt;Enter your Pipeline Shared Libraries repo URL under Project Repository&lt;/li&gt;
&lt;li&gt;Configure credentials if your repo requires credentials to checkout code&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Click on the &lt;strong&gt;save&lt;/strong&gt; button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2FSource-Code-Management-1024x498.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2FSource-Code-Management-1024x498.png" alt="Source Code Management"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Sample configuration for Global Pipeline Libraries&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now that our shared library is configured in Jenkins, let’s create a new Jenkins job to utilize this Jenkins pipeline library.&lt;/p&gt;

&lt;h3&gt;
  
  
  Referring Jenkins Shared Library from Pipeline
&lt;/h3&gt;

&lt;p&gt;Now, let’s refer to the Jenkins shared library from the pipeline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps to refer Jenkins pipeline library:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; In Jenkins, click on &lt;strong&gt;New Item&lt;/strong&gt; on the left side menu, enter Jenkins job name &amp;amp; choose the &lt;strong&gt;pipeline&lt;/strong&gt; as style &amp;amp; click on the &lt;strong&gt;OK&lt;/strong&gt; button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2FJenkins-pipeline-library.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2FJenkins-pipeline-library.png" alt="Jenkins pipeline library"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Inside the job, scroll down to the &lt;strong&gt;pipeline&lt;/strong&gt; section. Here we need our Jenkinsfile, which refers to the Shared Library. Loading Jenkinsfile into Jenkins job can be done via two approaches.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Approach 1 : Jenkinsfile – Manual approach (Not preferred for production)&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Under the &lt;strong&gt;pipeline&lt;/strong&gt; section, you can see a &lt;strong&gt;script&lt;/strong&gt; textbox where we can manually copy, paste the contents of our Jenkinsfile.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Jenkinsfile
@Library('first-shared-lib') _
welcomeJob ‘lambdatest’
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; _ (underscore) is a must after the @Library annotation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;@Library&lt;/strong&gt; will import the shared library to our Jenkins job. (Remember &lt;strong&gt;first-shared-lib&lt;/strong&gt; is the name we gave while configuring shared libraries in Manage Jenkins. Refer to the previous section of this article).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;welcomeJob&lt;/strong&gt; will invoke the &lt;strong&gt;call()&lt;/strong&gt; function in &lt;strong&gt;welcomeJob.groovy&lt;/strong&gt; created under &lt;strong&gt;vars&lt;/strong&gt; folder. The ‘lambdatest’ string will be sent as a parameter to the call() function.&lt;br&gt;&lt;br&gt;
 &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fimage3-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fimage3-2.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click on the &lt;strong&gt;save&lt;/strong&gt; button.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Approach 2 : Jenkinsfile – Refer from Git repository (Preferred Approach)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of manually copy-pasting Jenkinsfile content, we can refer to Jenkinsfile committed in a Git repo.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; In Jenkins job, under the &lt;strong&gt;pipeline&lt;/strong&gt; section, choose &lt;strong&gt;pipeline script from SCM&lt;/strong&gt; for &lt;strong&gt;Definition&lt;/strong&gt;. Configure Git repo URL &amp;amp; credentials in case the repo needs authentication for code checkout.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fpipeline-script-from-SCM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fpipeline-script-from-SCM.png" alt="pipeline script from SCM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Click on the &lt;strong&gt;Save&lt;/strong&gt; button.&lt;/p&gt;

&lt;p&gt;We recommend Approach 2 to load Jenkinsfile into the Jenkins job.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Click on &lt;strong&gt;Build Now&lt;/strong&gt; button on the left side menu to trigger the build.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fimage2-3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fimage2-3.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Once the build is complete, check the logs by clicking on the &lt;strong&gt;Console Output&lt;/strong&gt; from the left side menu.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2FConsole-Output.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2FConsole-Output.png" alt="Console Output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should see the Welcome, lambdatest message in the Console Output.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fimage14-1024x567.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fimage14-1024x567.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So we have successfully created &amp;amp; used a Jenkins shared library that prints the Welcome message. But what is the real use of this Jenkins pipeline library feature? Surely it’s not created just to print Welcome messages.&lt;/p&gt;
&lt;h3&gt;
  
  
  Jenkins Shared Library with Java/Spring Boot Application
&lt;/h3&gt;

&lt;p&gt;Let’s take the example we discussed earlier in this article – Microservices architecture with five Spring Boot applications, with each of them having its Jenkinsfile.&lt;/p&gt;

&lt;p&gt;Here is the sample Jenkinsfile to build, test &amp;amp; pack a Spring Boot application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
       agent any
       tools {
           maven 'Maven 3.5.0'
           jdk 'jdk8'
       }
       stages {
           stage("Tools initialization") {
               steps {
                   sh "mvn --version"
                   sh "java -version"
               }
           }
           stage("Checkout Code") {
               steps {
                   git branch: 'master',
                       url: "https://github.com/iamvickyav/spring-boot-data-H2-embedded.git"
               }
           }
           stage("Cleaning workspace") {
               steps {
                   sh "mvn clean"
               }
           }
           stage("Running Testcase") {
              steps {
                   sh "mvn test"
               }
           }
           stage("Packing Application") {
               steps {
                   sh "mvn package -DskipTests"
               }
           }
       }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In brief, the above pipeline code will first load tools like Java &amp;amp; Maven, then checkout code from Git repo, clean up the workspace, then run the test case &amp;amp; finally pack the application as a JAR.&lt;/p&gt;

&lt;p&gt;If you notice, other than the Git repo URL, the rest of the steps are applicable for any Spring Boot application. Instead of creating five different Jenkinsfiles, let’s create one Jenkins pipeline library &amp;amp; share it across all Spring Boot applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  Moving Common Pipeline steps to Jenkins Shared Library
&lt;/h3&gt;

&lt;p&gt;Let’s create a new shared library called &lt;strong&gt;jenkinsForJava&lt;/strong&gt; by creating jenkinsForJava.groovy under the vars directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vars
| --- welcomeJob.groovy
| --- jenkinsForJava.groovy

// jenkinsForJava.groovy
def call(String repoUrl) {
  pipeline {
       agent any
       tools {
           maven 'Maven 3.5.0'
           jdk 'jdk8'
       }
       stages {
           stage("Tools initialization") {
               steps {
                   sh "mvn --version"
                   sh "java -version"
               }
           }
           stage("Checkout Code") {
               steps {
                   git branch: 'master',
                       url: "${repoUrl}"
               }
           }
           stage("Cleaning workspace") {
               steps {
                   sh "mvn clean"
               }
           }
           stage("Running Testcase") {
              steps {
                   sh "mvn test"
               }
           }
           stage("Packing Application") {
               steps {
                   sh "mvn package -DskipTests"
               }
           }
       }
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We moved our pipeline logic to the call() method in jenkinsForJava.groovy. Instead of hard coding the repoUrl, we made it dynamic by accepting the URL from the call() function’s parameter.&lt;/p&gt;

&lt;p&gt;Now commit &amp;amp; push the vars/jenkinsForJava.groovy file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Update Jenkinsfile in Spring Boot Application to use Shared Library
&lt;/h2&gt;

&lt;p&gt;Let’s update the Jenkinsfile present in the root directory of the Spring Boot project with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Library('first-shared-lib') _
jenkinsForJava 'https://github.com/iamvickyav/spring-boot-data-H2-embedded.git'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As the call() function in jenkinsForJava.groovy requires the Git repo URL, we passed it as a parameter here.&lt;/p&gt;

&lt;p&gt;_ &lt;strong&gt;Note:&lt;/strong&gt; By referring to jenkinsForJava shared library, Jenkinsfile in all our Spring Boot applications got shortened to just two lines – one for @Library import &amp;amp; the other for calling jenkinsForJava Shared Library._&lt;/p&gt;

&lt;p&gt;Now commit &amp;amp; push the changes in Jenkinsfile to the remote repo.&lt;/p&gt;

&lt;p&gt;Create a new Job for Spring Boot Application by following steps mentioned in Approach 2 – Jenkinsfile – Refer from Git repository (Preferred Approach) section.&lt;/p&gt;

&lt;p&gt;Refer to the below screenshot for the final state of the job&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fimage6-1-1024x618.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fimage6-1-1024x618.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run the job by clicking on &lt;strong&gt;Build Now&lt;/strong&gt; from the left side menu after saving the job changes. You can see the build running in multiple stages, one after the other in the Stage View.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fimage5-1024x264.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fimage5-1024x264.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Accessing LambdaTest from Jenkins Shared Library
&lt;/h2&gt;

&lt;p&gt;Let’s consider the following maven project, which contains Selenium Test cases to test the &lt;a href="https://lambdatest.github.io/sample-todo-app/" rel="noopener noreferrer"&gt;Sample To-Do App&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;src/test/java/com/lambdatest/LambdaTest.java&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.lambdatest

import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class LambdaTest {

   public RemoteWebDriver driver = null;
   String username = "";
   String accessKey = "";

   @BeforeTest
   public void setUp() throws Exception {
       DesiredCapabilities capabilities = new DesiredCapabilities();
       capabilities.setCapability("platform", "Windows 10");
       capabilities.setCapability("browserName", "Chrome");
       capabilities.setCapability("version", "87.0");
       capabilities.setCapability("resolution","1024x768");
       capabilities.setCapability("build", "First Test");
       capabilities.setCapability("name", "Sample Test");
       capabilities.setCapability("network", true);       capabilities.setCapability("visual", true);        capabilities.setCapability("video", true);        capabilities.setCapability("console", true);
       try {
           username = System.getProperty("username");
           accessKey = System.getProperty("accessKey");
           driver= new RemoteWebDriver(new URL("https://"+username+":"+accessKey+"@hub.lambdatest.com/wd/hub"), capabilities);
       } catch (MalformedURLException e) {
           System.out.println("Invalid grid URL");
       }
   }

   @Test(enabled = true)
   public void testScript() throws Exception {
       try {
           driver.get("https://lambdatest.github.io/sample-todo-app/");
           driver.findElement(By.name("li1")).click();
           driver.findElement(By.name("li2")).click();
           driver.findElement(By.id("sampletodotext")).clear();
           driver.findElement(By.id("sampletodotext")).sendKeys("Yey, Let's add it to list");
           driver.findElement(By.id("addbutton")).click();
           driver.quit();
       } catch (Exception e) {
           System.out.println(e.getMessage());
       }
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We want to run this test in LambdaTest’s cloud. Hence, we configured &lt;strong&gt;RemoteWebDriver&lt;/strong&gt; with URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://"+username+":"+accessKey+"@hub.lambdatest.com/wd/hub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;_ &lt;strong&gt;Note:&lt;/strong&gt; Sign Up on the &lt;a href="https://www.lambdatest.com/" rel="noopener noreferrer"&gt;https://www.lambdatest.com/&lt;/a&gt; to get your username &amp;amp; accesskey._&lt;/p&gt;

&lt;h3&gt;
  
  
  Running Test in LambdaTest Cloud from Local
&lt;/h3&gt;

&lt;p&gt;To execute the test in LambdaTest Cloud from your local, use the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;gt; mvn -Dusername=&amp;lt;USERNAME&amp;gt; -DaccessKey=&amp;lt;ACCESSKEY&amp;gt; test&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Running Test in LambdaTest Cloud from Jenkins
&lt;/h3&gt;

&lt;p&gt;You need to create LambdaTest Credentials in Jenkins Server:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open Jenkins URL (&lt;a href="http://localhost:8080" rel="noopener noreferrer"&gt;http://localhost:8080&lt;/a&gt; if local) &amp;amp; click on manage jenkins on the left side menu.&lt;/li&gt;
&lt;li&gt;Click on Manage Credentials.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fimage11-2-1024x259.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fimage11-2-1024x259.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Enter the Global credentials section &amp;amp; click on Add Credentials.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fimage4-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fimage4-2.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Configure Username &amp;amp; Password with username &amp;amp; accessKey taken from LambdaTest site, respectively. Add credentials should look like something below:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fimage10-1-1024x340.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fimage10-1-1024x340.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create JenkinsSharedLibrary to run test case on LambdaTest Cloud&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create jenkinsLambdaTest.groovy under vars folder
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vars
| --- welcomeJob.groovy
| --- jenkinsForJava.groovy
| --- jenkinsLambdaTest.groovy

def call(String repoUrl) {
   pipeline{
       agent any
       tools {
           maven 'Maven 3.5.0'
           jdk 'jdk8'
       }
       environment {
           LAMBDA_TEST_CRED = credentials('lambdatest-site-cred')
       }
       stages {
           stage("Tools initialization") {
               steps {
                       sh "mvn --version"
                       sh "java -version"
                   }
               }
           stage("Checkout Code") {
               steps {
                   git branch: 'main',
                   url: "${repoUrl}"
               }
           }
           stage("Running Testcase") {
               steps {
                   sh "mvn -Dusername=${LAMBDA_TEST_CRED_USR} -DaccessKey=${LAMBDA_TEST_CRED_PSW} test"
               }
           }
       }
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;We used environment block in pipeline code to load the credentials we created under the Manage Credentials section.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;environment {
                LAMBDA_TEST_CRED = credentials('lambdatest-site-cred')
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The entire credential is loaded into the LAMBDA_TEST_CRED variable.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;_USR&lt;/strong&gt; is appended with &lt;strong&gt;LAMBDA_TEST_CRED&lt;/strong&gt; to access username &amp;amp; &lt;strong&gt;_PSW&lt;/strong&gt; is appended with &lt;strong&gt;LAMBDA_TEST_CRED&lt;/strong&gt; to access password (accessKey for LambdaTest portal).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;So our final mvn test command looks like below:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mvn -Dusername=${LAMBDA_TEST_CRED_USR} -DaccessKey=${LAMBDA_TEST_CRED_PSW} test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create Jenkinsfile to use Shared Jenkins Library&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create &lt;strong&gt;Jenkinsfile&lt;/strong&gt; in source code repo with the following content
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Library('first-shared-lib') _
jenkinsLambdaTest 'https://github.com/iamvickyav/lambdatest-sample-repo.git'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Now create a new job in Jenkins with pipeline as Job type &amp;amp; configure the pipeline section to refer to the Github repo.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fimage13.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Fimage13.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click on the &lt;strong&gt;Save&lt;/strong&gt; button &amp;amp; run the job by hitting &lt;strong&gt;Build now&lt;/strong&gt; link from the left side menu. You should see test progress in the Jenkins &lt;strong&gt;Stage view&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Funnamed.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2Funnamed.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You should also see the test report in LambdaTest cloud.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2FLambdaTest-Dashboard-Full-1024x481.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F03%2FLambdaTest-Dashboard-Full-1024x481.png" alt="LambdaTest Dashboard Full"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;To summarize, in this Jenkins pipeline shared library tutorial we have discussed what is Jenkins shared library, when &amp;amp; how we can use it. Creating Jenkins jobs using GUI is the right place to start learning Jenkins. But it’s just the baby steps. We should not rely on GUI to create our project-related work instead, we should use Jenkinsfile to create our jobs. But it’s also important to learn how to use Jenkinsfile efficiently. Jenkins shared Library is just the first step in that direction.&lt;/p&gt;

&lt;p&gt;I hope you found this article useful. Please let us know your feedback in the comment section below.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>cicd</category>
      <category>jenkins</category>
      <category>integration</category>
    </item>
    <item>
      <title>Selenium SendKeys : All You Need To Know</title>
      <dc:creator>Abeer Mishra</dc:creator>
      <pubDate>Thu, 11 Mar 2021 07:33:23 +0000</pubDate>
      <link>https://forem.com/aboywithscar/selenium-sendkeys-all-you-need-to-know-h95</link>
      <guid>https://forem.com/aboywithscar/selenium-sendkeys-all-you-need-to-know-h95</guid>
      <description>&lt;p&gt;Selenium automation is not just about navigating and clicking through the links. Yes, you can use it to switch tabs, find broken links, or even &lt;a href="https://www.lambdatest.com/blog/locators-in-selenium-webdriver-with-examples/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-11032021&amp;amp;utm_term=Praveen"&gt;drag and drop&lt;/a&gt; directly. But there is a lot more to it. An essential aspect of test automation is passing values to the text fields. In this article, we’ll delve into how Selenium helps us pass values to text fields using the Selenium sendKeys() method. Let us start on our journey to learn how to sendkeys in Selenium.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Selenium sendKeys() Method?
&lt;/h2&gt;

&lt;p&gt;Selenium provides sendKeys() method to input content in editable text fields or password fields in a webpage. These fields are like the typical web elements present on the web page that can be identified using any of the &lt;a href="https://www.lambdatest.com/blog/selenium-chromedriver-automation-testing-guide/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-11032021&amp;amp;utm_term=Praveen"&gt;Selenium locators&lt;/a&gt;. You can refer to our article on Selenium locators to learn more about the different locators you can use.&lt;/p&gt;

&lt;p&gt;Let us understand the utility of the sendKeys() method through an example. Consider the below use-case:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open the website &amp;gt; &lt;a href="https://www.lambdatest.com/"&gt;LambdaTest&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Locate the web-element to enter the email address.&lt;/li&gt;
&lt;li&gt;Enter your email address.&lt;/li&gt;
&lt;li&gt;Click on the ‘Start Free Testing’ button.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let us now see what the code for the above use-case would look like, and then we will understand the code line-by-line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package sendkeys;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class SendkeysTest {

WebDriver driver;

    //Method to set up the browser and open the dummy website
    @BeforeClass
    public void setUp() {

            System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\drivers\\chromedriver.exe");
            driver = new ChromeDriver();
            driver.get("https://www.lambdatest.com");
            driver.manage().window().maximize();
    }

    @Test
    public void testSendkeys() {
            //Locate the email and use sendkeys to pass the email to the field
            driver.findElement(By.id("useremail")).sendKeys("----your email id----");

            //Locate the Start Free Testing button and click it
            driver.findElement(By.xpath("//*[@id='testing_form']//button")).click();
    }


    @AfterClass
    public void burnDown() {
            driver.quit();
    }

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

&lt;/div&gt;



&lt;p&gt;Let us first understand the code above and then see the execution part.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The code under @BeforeClass method-&lt;/strong&gt; The method setUp() contains the generic code to instantiate the &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-11032021&amp;amp;utm_term=Praveen"&gt;ChromeDriver&lt;/a&gt; and navigate to the LambdaTest] website. The page is then maximized.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The code under @AfterClass method-&lt;/strong&gt; Similar to the setUp method, the burnDown() method simply closes the browser instance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The code under the main &lt;a class="comment-mentioned-user" href="https://dev.to/test"&gt;@test&lt;/a&gt;
 method-&lt;/strong&gt; This is the method consisting of our test case. We simply locate the text field where we have to enter the email ID and then pass on the string (which is our email ID) to the sendKeys() method. Next, we locate the ‘ &lt;strong&gt;Start Free Testing&lt;/strong&gt; ’ button and click the same. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The code to use the Selenium sendKeys() method can also be written as shown below-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement emailField = driver.findElement(by.id(“useremail”));
emailField.sendKeys(“---your email id---”);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is just the bifurcation of the web element and then passing the string value to the text box.&lt;/p&gt;

&lt;p&gt;On running the above test, you will see that the browser actions are performed, and your email is entered into the email ID text field.&lt;br&gt;&lt;br&gt;
Did you see how easy the Selenium sendKeys() method is?&lt;/p&gt;
&lt;h2&gt;
  
  
  Using Selenium sendKeys To Erase Text
&lt;/h2&gt;

&lt;p&gt;Next, let us consider a scenario where we need to verify that we are able to clear or delete the string entered in the text field. To achieve this case, we will use the Selenium clear() method, which simply erases whatever text is entered in the text field.&lt;/p&gt;

&lt;p&gt;Consider the below code for the same-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package sendkeys;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class SendkeysTest {

WebDriver driver;

    //Method to set up the browser and open the dummy website
    @BeforeClass
    public void setUp() {

            System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\drivers\\chromedriver.exe");
            driver = new ChromeDriver();
            driver.get("https://www.lambdatest.com");
            driver.manage().window().maximize();
    }

    @Test
    public void testSendkeys() {
            //Locate the email and use sendkeys to pass the email to the field
            WebElement email = driver.findElement(By.id("useremail"));
            email.sendKeys("---your email id---");

            // Erase the text entered in the email id field
            email.clear();
    }


    @AfterClass
    public void burnDown() {
            driver.quit();
    }

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

&lt;/div&gt;



&lt;p&gt;The code is the same as we explained earlier, but the only addition is the &lt;em&gt;clear()&lt;/em&gt; method used for the email web element. This clear method would erase the text entered in the text field, and you can further enter the text using the &lt;em&gt;sendKeys()&lt;/em&gt; method as per your requirement.&lt;/p&gt;

&lt;p&gt;Now that we have seen how to &lt;em&gt;sendKeys()&lt;/em&gt; in Selenium with its implementation, we hope you understand it better. We have also seen how we can erase the string or text already entered in the text field using the &lt;em&gt;clear()&lt;/em&gt; method. We will now explore some other options to enter text in the text field without using sendKeys().&lt;/p&gt;

&lt;h2&gt;
  
  
  How Can We Type In Selenium Without Using sendKeys?
&lt;/h2&gt;

&lt;p&gt;Although sendKeys() works almost every time, there might be a case where the text input box is disabled, and you need to pass some text to the field. In such scenarios, sendKeys() would not work, and you might have to try some alternate approach. Before we move onto the use case, remember that this is not the recommended way to test as the UI blocks you from entering any text in a field. Just for the sake of understanding our use case, let us consider such a scenario.&lt;/p&gt;

&lt;p&gt;Now, you might be wondering if not Selenium sendKeys, then what? One of the most effective ways to send input to text fields is to use the JavaScriptExecutor, which we will discuss below.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using The JavaScriptExecutor
&lt;/h3&gt;

&lt;p&gt;We will now use JavaScriptExecutor to locate the text box and then pass the text value to it. Let us see how the code for it would look like-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;JavascriptExecutor jse = ((JavascriptExecutor)driver);          
WebElement email = driver.findElement(By.id("useremail"));
jse.executeScript("arguments[0].value='---your email id---';", email);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As can be seen from the above code, we are merely passing the text box’s arguments as a script for the JavaScriptExecutor and not using sendKeys(). Try using these code lines in our example above by replacing the sendKeys() code and seeing that you will get the same results as with the sendKeys() method.&lt;/p&gt;

&lt;p&gt;Now that you understand how to sendKeys() in Selenium let us now see how the LambdaTest &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-11032021&amp;amp;utm_term=Praveen"&gt;Selenium Grid cloud&lt;/a&gt; can efficiently execute your tests across different system configurations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing Selenium sendKeys On LambdaTest Grid
&lt;/h2&gt;

&lt;p&gt;It is highly likely that you have to run your automation suite across multiple browsers and OS configuration. LambdaTest Grid provides you an easy solution to execute your tests across multiple combinations by leveraging capabilities. These capabilities can be generated directly from the LambdaTest capabilities generator and integrated into your Selenium test.&lt;/p&gt;

&lt;p&gt;Note that we will use the same example used above for execution on LambdaTest Grid cloud for one browser, but you can use the same test to perform cross browser testing by changing the capabilities and using Data Provider, as explained in our article on &lt;a href="https://www.lambdatest.com/blog/speed-up-automated-parallel-testing-in-selenium-with-testng/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-11032021&amp;amp;utm_term=Praveen"&gt;parallel testing&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package sendkeys;
import java.awt.AWTException;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class SendkeysTest {


            public String username = "--- your user name ---";
            public String accesskey = "--- your access key ---";
            public static RemoteWebDriver driver = null;
            public String gridURL = "@hub.lambdatest.com/wd/hub";
            boolean status = false;
    //Method to set up the browser and open the dummy website
    @BeforeClass
    public void setUp() {

            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("browserName", "chrome");
            capabilities.setCapability("version", "81.0");
            capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will get any available one
            capabilities.setCapability("build", "LambdaTestProject");
            capabilities.setCapability("name", "LambdaTestSendKeysProject");
            capabilities.setCapability("network", true); // Enables network logs
            capabilities.setCapability("visual", true); // Enables step by step screenshot
            capabilities.setCapability("video", true); // Enables video recording
            capabilities.setCapability("console", true); // Captures 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());
            }
            driver.get("https://www.lambdatest.com");
    }

    @Test
    public void testSendkeys() throws AWTException {


            //Locate the email and use sendkeys to pass the email to the field

            WebElement email = driver.findElement(By.id("useremail"));
            email.sendKeys("abc@abc.com");


            //Locate the Start Free Testing button and click it
            driver.findElement(By.xpath("//*[@id='testing_form']//button")).click();


    }


    @AfterClass
    public void burnDown() {
            driver.quit();
    }

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

&lt;/div&gt;



&lt;p&gt;You may change the capabilities settings as per your requirements and execute the test. You will see that the LambdaTest platform provides you a beautiful user interface of the test results, including a video of the execution. You can find these results under the Automation Logs tab in the &lt;a href="https://automation.lambdatest.com/"&gt;Automation dashboard&lt;/a&gt; as shown below-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L7uehP5B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/01/Automation-dashboard.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L7uehP5B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2021/01/Automation-dashboard.png" alt="Automation dashboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See how seamless Selenium automation can be by leveraging the capabilities of LambdaTest Grid cloud? Now, go ahead and try running a test case of your own that uses the sendKeys() method and leverages the capabilities of LambdaTest.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;We understood what the Selenium sendKeys() method is and how it can be used in Selenium automation.&lt;/li&gt;
&lt;li&gt;We saw how the clear() method could be used to clear off any string that is already present or entered in a text field.&lt;/li&gt;
&lt;li&gt;We then saw how we could use the JavaScriptExecutor to enter text or string in a text field if we do not use the sendKeys() method.&lt;/li&gt;
&lt;li&gt;Finally, we ran our test on the LambdaTest Grid, which helps us execute our tests in parallel across 2000+ browsers and operating systems.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We hope you found this article informative; we would love to hear what you think. Don’t forget to leave your comments below.&lt;/p&gt;

&lt;p&gt;Happy Testing!&lt;/p&gt;

</description>
      <category>selenium</category>
      <category>automation</category>
      <category>testing</category>
    </item>
    <item>
      <title>Nightwatch Vs Protractor: Which Testing Framework Is Right For You?</title>
      <dc:creator>Abeer Mishra</dc:creator>
      <pubDate>Tue, 09 Feb 2021 07:43:03 +0000</pubDate>
      <link>https://forem.com/aboywithscar/nightwatch-vs-protractor-which-testing-framework-is-right-for-you-1oc4</link>
      <guid>https://forem.com/aboywithscar/nightwatch-vs-protractor-which-testing-framework-is-right-for-you-1oc4</guid>
      <description>&lt;p&gt;Do you know the test automation market is all set to hit &lt;a href="https://www.globenewswire.com/news-release/2020/11/24/2132570/0/en/Automation-Testing-Market-to-hit-USD-35-Bn-by-2026-Global-Market-Insights-Inc.html"&gt;$35 billion by 2026&lt;/a&gt;? And when it comes to cross browser testing, JavaScript leads from the front? Javascript is probably the best alternative for Selenium automation, considering its protocol transformation to the W3C standard. In order to make the most of it, the first step is to choose the best test automation frameworks. Among all the JavaScript testing frameworks, two frameworks are most popular- Nightwatch and Protractor.&lt;/p&gt;

&lt;p&gt;This article will be comparing Nightwatch vs Protractor and help you choose the perfect JavaScript testing frameworks. Let us start by diving deeper into each framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Nightwatch.js?
&lt;/h2&gt;

&lt;p&gt;Nightwatch.js is a free automation test framework for websites and web apps. It is written in Node.js and also utilizes the W3C WebDriver API. Nightwatch is an end-to-end testing (E2E) solution that aims to simplify writing automation tests with Javascript for browser apps, web-based apps, and websites. It is one of the most popular test automation frameworks that functions by communicating over a restful HTTP API amid a WebDriver server (like Selenium Server or ChromeDriver).&lt;/p&gt;

&lt;p&gt;Nightwatch relies on Selenium and offers various assertions and commands within the framework to carry out operations on the Document Object Model (DOM) elements. The protocol is clearly defined by the W3C WebDriver specification (mainly originated from JSON Wire protocol). The newest version accessible in the market is 1.0.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Is Nightwatch.js So Popular?
&lt;/h3&gt;

&lt;p&gt;Before we dive into Nightwatch.js features, pros, and cons, it is significant to understand the reasons behind this testing framework’s fame. Nightwatch.js facilitates end-to-end functional browser tests in a pure Node.js environment, which allows testing of web apps independent from third party software.&lt;/p&gt;

&lt;p&gt;The key reason for robust and lightweight test automation frameworks like Nightwatch is facilitating a single integrated solution for app tests. As this automated testing framework is built on Node.js, it has several benefits over any other Selenium test automation tool. The browser tests powered by Nightwatch.js remove the dependency upon third party software, which improves data integrity amongst varied system components.&lt;/p&gt;

&lt;h3&gt;
  
  
  Crucial Features Of Nightwatch.js
&lt;/h3&gt;

&lt;p&gt;To compare Nightwatch vs Protractor, we must understand the features of both of these &lt;a href="https://www.lambdatest.com/blog/top-javascript-automation-testing-framework/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-9022021&amp;amp;utm_term=Praveen"&gt;JavaScript testing frameworks&lt;/a&gt;. First, let us dive deep into the core features offered by Nightwatch.js:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;In-Built Command-line Test Runner:&lt;/strong&gt; Nightwatch comes with an in-built test runner suite with Grunt’s support for performing the test automation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Selenium Server:&lt;/strong&gt; It comes with a capacity to control the separate Selenium server automatically by offering a built-in JUnit XML reporting feature.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smart Testing Strategy:&lt;/strong&gt; Nightwatch has an exceptional feature to run the tests effectively and can be performed in numerous ways like sequentially, parallelly, or tags and groups.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Assertions, XPath, &amp;amp; CSS:&lt;/strong&gt; Various assertions and commands for Document Object Model (DOM) operations, XPath and CSS selectors, and can be used to recognize the page’s elements. That’s what makes this framework flexible and easy to extend, particularly while executing the app-specific assertions and commands.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloud Services:&lt;/strong&gt; It offers excellent support for cross browser tests with Selenium JavaScript. It allows easy integration with many well-known cloud-based Selenium test automation providers such as LambdaTest.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Continuous Integration (CI):&lt;/strong&gt; It provides excellent assistance for CI and can be used to incorporate the testing with the continuous build processing systems like TeamCity, Jenkins, etc., and supports software developers to build and test software continually.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Apart from all the attributes mentioned above, it is also famous for having an easy and straightforward syntax, making it simpler to write the tests rapidly and effectively using XPath locator and Node.js CSS selectors in Selenium.&lt;/p&gt;

&lt;h3&gt;
  
  
  Core Advantages Of Nightwatch
&lt;/h3&gt;

&lt;p&gt;Nightwatch is one of the most popular test automation frameworks for websites and web apps. The core benefits of using Nightwatch as the preferred JavaScript testing framework are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Built-in command-line test runner.&lt;/li&gt;
&lt;li&gt;The syntax is easy to understand.&lt;/li&gt;
&lt;li&gt;Flexible assertions and commands that are easy, quite easy to extend.&lt;/li&gt;
&lt;li&gt;Can control individual Selenium servers in a separate child procedure. This automated framework automatically also handles WebDriver services (GeckoDriver, Safari, Edge).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nightwatch is advantageous for end-to-end test automation as it allows us to write all-inclusive tests in &lt;a href="https://www.lambdatest.com/blog/nodejs-best-practices/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-9022021&amp;amp;utm_term=Praveen"&gt;Node.js&lt;/a&gt; effortlessly and rapidly. It makes the entire process of test automation and continuous integration much more seamless. Nightwatch lets us configure the Selenium test suite and enables parallel testing that additionally controls the build time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Choose Nightwatch Over Other JavaScript Testing Frameworks?
&lt;/h2&gt;

&lt;p&gt;Selenium is the most in-demand automated testing framework as it offers support for cross browser testing, numerous programming languages and is also used in both the mobile app and web app tests. However, Nightwatch completely utilizes JavaScript as the programming language for comprehensive tests, which has the listed benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Improvise test structuring&lt;/li&gt;
&lt;li&gt;Robust configuration&lt;/li&gt;
&lt;li&gt;Enables configuration with Cucumber for building a robust &lt;a href="https://www.lambdatest.com/blog/behaviour-driven-development-by-selenium-testing-with-gherkin/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-9022021&amp;amp;utm_term=Praveen"&gt;Behaviour Driven Development&lt;/a&gt; (BDD) setup&lt;/li&gt;
&lt;li&gt;Lightweight framework&lt;/li&gt;
&lt;li&gt;Incorporates with cloud servers&lt;/li&gt;
&lt;li&gt;Excellent performance of the automation implementation&lt;/li&gt;
&lt;li&gt;Minimum practice and minimum maintenance of code&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How Does Nightwatch.js Work?
&lt;/h2&gt;

&lt;p&gt;This test automation framework mainly connects over a restful API protocol (defined by the W3C WebDriver AP). It requires a restful HTTP API with a JavaScript WebDriver server (such as Selenium JavaScript WebDriver server.)&lt;/p&gt;

&lt;p&gt;To execute any operation, i.e., either an assertion or command, Nightwatch typically requires sending fewer than two requests. It functions as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first and foremost request locates the necessary elements with the given CSS selector or XPath expression.&lt;/li&gt;
&lt;li&gt;However, the second request takes the constituent and carries out the definite operation of assertion or command.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites For Nightwatch.js&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Node.js&lt;/strong&gt; – You need to have Node.js installed on your computer before installing this test automation framework. To check if you have Node.js pre-installed on your system, simply type:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;node -v&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You will notice the Node.js version. This must also install the node package manager (npm). To confirm it, type the following:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm -v&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The npm version will be prompted.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;WebDriver-&lt;/strong&gt; This test automation framework supports major browsers, i.e, Firefox, Chrome, Safari, and Internet Explorer. For your Nightwatch.js testing to implement on your chosen browser, you need to find the web driver for that precise browser. You can set up the browser either through npm or through the web pages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Selenium WebDriver for popular browsers can be downloaded from the links given below:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;BROWSER&lt;/th&gt;
&lt;th&gt;DOWNLOAD LOCATION&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Firefox&lt;/td&gt;
&lt;td&gt;&lt;a href="https://github.com/mozilla/geckodriver/releases"&gt;https://github.com/mozilla/geckodriver/releases&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Chrome&lt;/td&gt;
&lt;td&gt;&lt;a href="http://chromedriver.chromium.org/downloads"&gt;http://chromedriver.chromium.org/downloads&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Internet Explorer&lt;/td&gt;
&lt;td&gt;&lt;a href="https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver"&gt;https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Microsoft Edge&lt;/td&gt;
&lt;td&gt;&lt;a href="https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/"&gt;https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;To run your tests on several browsers you may use a &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-9022021&amp;amp;utm_term=Praveen"&gt;cloud Selenium Grid&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installing Nightwatch Via npm-&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We commence off with standard npm installation of the package using the following command-&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ npm install nightwatch --save-dev&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;There are some significant things which you require to manually install:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Browser Driver (ChromeDriver)&lt;/li&gt;
&lt;li&gt;Selenium Server&lt;/li&gt;
&lt;li&gt;Java Development Kit (JDK) (&amp;gt;v7)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You also require a &lt;code&gt;nightwatch.json&lt;/code&gt; configuration file to allow this test framework to know how it must run.&lt;/p&gt;

&lt;p&gt;Once you have installed all the required tools, you can start running your tests using this command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;nightwatch *.spec.ts&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Nightwatch – Pros &amp;amp; Cons
&lt;/h2&gt;

&lt;p&gt;In this section of Nightwatch vs Protractor comparison, we will look into the pros and cons of using Nightwatch as your preferred JavaScript testing framework.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros Of Using Nightwatch&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A clean syntax lets you write tests rapidly. &lt;/li&gt;
&lt;li&gt;Allows use of CSS as well as XPath selectors to locate elements.&lt;/li&gt;
&lt;li&gt;It works seamlessly with cloud-based testing platforms like LambdaTest.&lt;/li&gt;
&lt;li&gt;CI (Continuous Integration) support – Integrates your testing with systems like Teamcity, Hudson, &lt;a href="https://www.lambdatest.com/blog/what-is-jenkins/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-9022021&amp;amp;utm_term=Praveen"&gt;Jenkins&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons Of Using Nightwatch&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Since it comes with its own test automation framework and therefore, it offers less flexibility to your own unit tests.&lt;/li&gt;
&lt;li&gt;Lack of proper support.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that we have understood what Nightwatch is, it is time to dive deeper into Protractor. This will give us a deeper insight into the Nightwatch vs Protractor comparison.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Protractor?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/protractor-tutorial-end-to-end-testing-for-angularjs/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-9022021&amp;amp;utm_term=Praveen"&gt;Protractor&lt;/a&gt; is one of the crucial automated and JavaScript testing frameworks. It is most commonly used as an end-to-end behavior-driven testing tool, specifically for AngularJS. It functions as a Solution integrator combining robust technologies and tools such as WebDriver, Jasmine, Cucumber, Mocha, Selenium, etc. The Protractor framework’s objective is not merely to test AngularJS apps but also to write automated regression testing for normal web apps. Google Developers originally developed it for supporting Angular apps, and later it was launched as a free framework.&lt;/p&gt;

&lt;p&gt;Currently, Protractor supports both Non-Angular and Angular apps. It is one of the most popular JavaScript testing frameworks and is written on top of Webdriver.js. Thus, in addition to Angular-specific traits, the entire feature set supported in Selenium Webdriver is maintained by it. It gets a little tricky to identify web elements in the AngularJS app, and Selenium WebDriver often fails with HTML attributes like ng-model or ng-controller. This is where Protractor has the upper hand as it helps control those components and test the actual functionality.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Is Protractor So Popular?
&lt;/h3&gt;

&lt;p&gt;Protractor acts as an e2e test framework for both non-Angular and Angular apps that don’t use CSS elements. Automating web apps built on AngularJS by making use of this tool is a crucial step forward for companies in their efforts to automate the business process. It does not require you to add sleeps and waits. As the webpage completes pending steps, Protractor executes the subsequent moves of the test case by automatically linking with the AngularJS app. Additionally, it is quite simple to install page objects.&lt;/p&gt;

&lt;p&gt;This angular framework does not execute WebDriver commands till action is required, e.g., installing page objects so that script can operate on-page elements without affecting the HTML. Protractor also assists in Angular-specific locator strategies as well as native WebDriver locator tactics.&lt;/p&gt;

&lt;h3&gt;
  
  
  Crucial Features Of Protractor
&lt;/h3&gt;

&lt;p&gt;In this section of the Nightwatch vs Protractor blog, we will understand Protractor’s most crucial features. It has the following core features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Supports Angular-Specific Locators:&lt;/strong&gt; It is one of the best automated JavaScript testing frameworks that introduced us with angular precise locators like ng-repeat, ng-bind, ng-model, etc. Needless to say, it offers great support for such locators. You do not need to generate complicated XPath for angular locators. In this framework, those locators are all set for you, so you can simply utilize by.repeater, by.model, etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Supports Both Angular &amp;amp; Non-Angular Apps:&lt;/strong&gt; It has extensive support for Angular; however, it also supports non-Angular apps. Even if one section of your app is non-Angular and another fraction of it is Angular, this test automation framework is your safest bet for comprehensive automated tests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Supports Cross Browser Tests:&lt;/strong&gt; You can effortlessly execute your scripts in several browsers such as Edge, Chrome, IE11, Safari, and Firefox. Configuring such &lt;a href="https://www.lambdatest.com/feature?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-9022021&amp;amp;utm_term=Praveen"&gt;browser compatibility testing&lt;/a&gt; is easy and doesn’t take much effort and time with Protractor.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Supports Parallel Execution:&lt;/strong&gt; It also supports parallel test execution. When you have an enormous number of test cases lined up, and every test case requires sequential execution, this feature comes in handy.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Supports Headless Browser:&lt;/strong&gt; The kind of browser is devoid of the UI. This test framework also lets you run your test cases in headless browser modes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Supports Extensibility:&lt;/strong&gt; As it is a node.js app, you can use an extensive range of packages that are accessible in the node. Therefore you can expand this framework or add new traits by setting up node packages. For instance, if one necessitates an HTML report, one could simply use Jasmine HTML Reporter. Similarly, for cleaning up the code, we can set up tslint or eslint, or you can set up node packages of your preference.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Supports Various Assertion Libraries:&lt;/strong&gt; It also supports various assertion libraries such as Mocha, Jasmine, or you can even make use of your tailor libraries. However, by default, for assertions, it uses the Jasmine framework.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Supports Cloud Testing:&lt;/strong&gt; Cloud test platforms enable you to execute our specs on various browsers (Safari, Firefox, Chrome, etc.) and several operating systems (Mac, Windows, Mobile, Linux, etc.). It is supported by several cloud-based test platforms like LambdaTest.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Supports CI/CD:&lt;/strong&gt; Once your automated scripts are in place, you do not have to manually monitor and run them. Each time a new code goes to the repository, these tests automatically run and get you the report. Protractor can be integrated with tools like Azure DevOps, Jenkins, or TFS to automate the procedure. It also supports CI/ CD. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Core Advantages Of Protractor
&lt;/h3&gt;

&lt;p&gt;Next up in this Nightwatch vs Protractor blog, we will be looking at reasons to consider while switching from other test automation frameworks to Protractor. This open-source E2E JavaScript testing framework provides the following benefits −&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This open-source tool is simple to set up or install.&lt;/li&gt;
&lt;li&gt;Functions well with Jasmine framework for creating the test.&lt;/li&gt;
&lt;li&gt;Supports TDD (test-driven development).&lt;/li&gt;
&lt;li&gt;Supports parallel testing via manifold browsers.&lt;/li&gt;
&lt;li&gt;Comprises automatic waits that means you don’t require to add waits &amp;amp; sleeps to your script explicitly.&lt;/li&gt;
&lt;li&gt;Provides the entire benefits of Selenium WebDriver and auto-synchronization.&lt;/li&gt;
&lt;li&gt;Offers remarkable testing speed as compared to other tools.&lt;/li&gt;
&lt;li&gt;Offers built-in support for Angular.js components like by.repeater, by.exactRepeater, by.binding, by.model, by.excatBinding, by.options, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why Choose Protractor Over Other JavaScript Testing Frameworks?
&lt;/h2&gt;

&lt;p&gt;We are all aware of the fact that almost every kind of app is using JavaScript for software development today. A QA engineer’s job turns very tricky when JavaScript enhances in size and becomes complicated because of the rising number of JS-based apps. A majority of the time, it turns into a challenging situation due to an inability to locate the web elements in AngularJS apps using expanded HTML syntax or using Selenium WebDriver or JUnit.&lt;/p&gt;

&lt;p&gt;Selenium WebDriver is unable to search AngularJS web components. This is because AngularJS apps use some expanded HTML elements like ng-model, ng-controller, ng-repeater, etc., which aren’t counted in Selenium locators.&lt;/p&gt;

&lt;p&gt;Therefore, the significance of Protractor comes into play as this framework can easily control and manage those extended HTML components in AngularJS web apps. While most frameworks concentrate on executing unit testing for AngularJS apps, Protractor is used to perform tests of the app’s real functionality&lt;/p&gt;

&lt;h2&gt;
  
  
  How Does Protractor Work?
&lt;/h2&gt;

&lt;p&gt;This framework is one of the select few JavaScript testing frameworks built on top of WebdriverJS. It is a Selenium-based test framework which allows Protractor to integrate with Selenium WebDrivers and server like SafariDriver, GeckoDriver, ChromeDriver, etc. to imitate the user activities.&lt;/p&gt;

&lt;p&gt;Subsequently, it also offers support for several assertions frameworks like Mocha, Jasmine, etc. This assertion framework allows you to verify or validate the values; in turn, the testing will be marked as fail or pass. In simple words, Protractor, Selenium Server, WebdriverJS, Assertion Framework, and Browser Driver give the infrastructure to write and execute our E2E (end-to-end) testing&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites For Protractor&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Node.js-&lt;/strong&gt; To perform testing, you need to have Node.js installed. One needs to download the Protractor package by making use of npm that mainly comes with Node.js. Verify the Node.js version you need by running &lt;code&gt;node -v&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Afterward, it is better to scrutinize the compatibility notes in the Protractor README to make certain your Node.js version is perfectly compatible with this framework. However, by default, this framework uses &lt;a href="http://jasmine.github.io/"&gt;Jasmine&lt;/a&gt; for its test interface.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installing the package&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install -g protractor&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In contrast to Nightwatch, one does not have to install Selenium manually as it comes in-built in Protractor. But, it does require ensuring the browser driver versions are latest and updated. Use this command-&lt;/p&gt;

&lt;p&gt;&lt;code&gt;webdriver-manager update&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The protractor.dev.conf.js configuration file is also required.&lt;/p&gt;

&lt;p&gt;For performing the testing, we have to begin the Selenium server firstly earlier than we are capable to run Protractor.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;webdriver-manager start&lt;/code&gt;&lt;br&gt;&lt;br&gt;
&lt;code&gt;protractor protractor.dev.conf.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In hindsight of the Nightwatch vs Protractor comparison, the setup procedure is somewhat simpler than Nightwatch.&lt;/p&gt;

&lt;h2&gt;
  
  
  Protractor – Pros &amp;amp; Cons
&lt;/h2&gt;

&lt;p&gt;Before moving on to the final comparison between Nightwatch vs Protractor, let us take a look at what Protractor has to offer. Listed below are the pros and cons-&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros Of Using Protractor&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Protractor smartly supports TDD (test-driven development).&lt;/li&gt;
&lt;li&gt;Supports parallel testing via manifold browsers.&lt;/li&gt;
&lt;li&gt;Provides the advantage of auto-synchronization.&lt;/li&gt;
&lt;li&gt;Provides rapid testing speed when compared to other tools or libraries. &lt;/li&gt;
&lt;li&gt;Supports CI/ CD.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons Of Using Protractor&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does not support mobile applications.&lt;/li&gt;
&lt;li&gt;Debugging is complicated and tricky.&lt;/li&gt;
&lt;li&gt;You must know JavaScript to get well-versed with Protractor.&lt;/li&gt;
&lt;li&gt;This framework is a &lt;a href="https://www.protractortest.org/#/infrastructure"&gt;wrapper around WebdriverJs&lt;/a&gt;. So if there is any concern with WebdriverJs, it might also be an issue with Protractor.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Comparing Nightwatch Vs Protractor
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MQ-d4jt6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ucarecdn.com/04565e6a-c912-44af-a786-105442ec3762/" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MQ-d4jt6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ucarecdn.com/04565e6a-c912-44af-a786-105442ec3762/" alt="1.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;When it comes to choosing between Nightwatch vs Protractor, it is a tough call to take. Using Protractor with Selenium is better if one needs to carry out full E2E testing that opens a browser and executes a DOM manipulation. Besides, Protractor is particularly better for angular applications. On the other hand, in test automation frameworks like Nightwatch, asserts are prepared automatically. It also creates a test report automatically plus keeps it in a directory.&lt;/p&gt;

&lt;p&gt;Remember that Protractor also offers an impressive set of features, especially when some components are not easy to detect and require an element explorer. If you are working on Angular, the project is not big, and Chrome is the prime browser—look no more! You can make use of Protractor. As Protractor is rooted in WebDriver, cross browser testing would not be any problem at all. Additionally, you can use cloud-based cross browser testing platforms like &lt;a href="https://www.lambdatest.com/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-9022021&amp;amp;utm_term=Praveen"&gt;LambdaTest&lt;/a&gt; to take advantage of a Selenium grid cloud for test execution. It lets you perform tests on a combination of 2000+ browser and operating systems.&lt;/p&gt;

&lt;p&gt;Before selecting a framework, understand the development technique and testing criterion. Once done, pick out the framework that suits your requirements. We hope this will help you pick the right test automation framework.&lt;br&gt;&lt;br&gt;
Happy testing!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>testing</category>
      <category>selenium</category>
    </item>
    <item>
      <title>21 Of The Best Jenkins Alternatives For Developers</title>
      <dc:creator>Abeer Mishra</dc:creator>
      <pubDate>Mon, 04 Jan 2021 09:34:52 +0000</pubDate>
      <link>https://forem.com/aboywithscar/21-of-the-best-jenkins-alternatives-for-developers-4n77</link>
      <guid>https://forem.com/aboywithscar/21-of-the-best-jenkins-alternatives-for-developers-4n77</guid>
      <description>&lt;p&gt;When it comes to &lt;a href="https://www.lambdatest.com/blog/27-best-ci-cd-tools/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-4122020&amp;amp;utm_term=Praveen"&gt;CI/CD tools&lt;/a&gt;, we’re all too familiar with Jenkins. It has been a popular choice among Java developers for continuous integration and continuous development approach. It is a super-effective tool to build and test projects, thereby making easy integration possible continuously. Also, it is an open-source tool that provides multiple plugins.&lt;/p&gt;

&lt;p&gt;However, Jenkins isn’t the only CI/CD tool out there. You can pick a Jenkins alternative as you’ve got a lot of options!&lt;/p&gt;

&lt;p&gt;Now, the question is, with so many choices, how do you pick the best alternative to Jenkins? Well, to make it easier for you, we have created a list of 21 of the best Jenkins alternatives. Keep reading to learn about them.&lt;/p&gt;

&lt;p&gt;_ &lt;strong&gt;Note:&lt;/strong&gt; The following list of Jenkins alternatives isn’t in any particular order. Its hierarchy does not reflect importance or value in any way, shape, or form._&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wQh-Md46--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/gitlab.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wQh-Md46--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/gitlab.png" alt="gitlab"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://about.gitlab.com/"&gt;GitLab&lt;/a&gt; CI/CD tool is a part of GitLab and a powerful alternative to Jenkins. It is an open-source web interface that can be used to apply all the continuous methods like integration, delivery, and deployment to your project without any third-party application. It provides a user-friendly interface along with distributed version control services.&lt;/p&gt;

&lt;p&gt;Some of the top features that make it one of the best alternatives to Jenkins are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Just like Jenkins, it is an open-source tool too.&lt;/li&gt;
&lt;li&gt;You can test your build in parallel, thereby reducing time.&lt;/li&gt;
&lt;li&gt;It allows docker integration and helps in automating release and application delivery.&lt;/li&gt;
&lt;li&gt;It provides better support.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Atlassian Bamboo
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kGIcAzo5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/bamboo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kGIcAzo5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/bamboo.png" alt="bamboo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.atlassian.com/software/bamboo"&gt;Bamboo&lt;/a&gt; is a product of Atlassian, and it’s a useful tool for continuous integration, development, and deployment. It runs builds and tests and efficiently integrates with JIRA to update issues and commits and connect test results for an end to end visibility within the team. It supports multiple technologies like AWS, Amazon S3 buckets, Git, SVN, Mercurial, etc.&lt;/p&gt;

&lt;p&gt;Some of the key features of Bamboo includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It can be used to run parallel batch tests.&lt;/li&gt;
&lt;li&gt;It provides seamless integration with JIRA, BitBucket, and Fisheye.&lt;/li&gt;
&lt;li&gt;It is effortless to set up.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. CircleCI
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jo0EAv7n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/CircleCI.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jo0EAv7n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/CircleCI.png" alt="CircleCI"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://circleci.com/"&gt;CircleCI&lt;/a&gt;is a flexible tool with easy maintenance and can run in almost any environment. Every commit leads to automatic build execution. To add to it, if any new build is triggered, any queued or running build is automatically canceled.&lt;/p&gt;

&lt;p&gt;Besides, it provides features like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Integration with GitHub, Bitbucket, and GitHub Enterprise.&lt;/li&gt;
&lt;li&gt;It splits tests among multiple containers, thereby reducing build time.&lt;/li&gt;
&lt;li&gt;It provides SSH support so that users can access the Virtual Machine via SSH and run commands.&lt;/li&gt;
&lt;li&gt;Very easy to maintain as it allows for automatic upgrades.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. TeamCity
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G5mkDmHH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/TeamCity.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G5mkDmHH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/TeamCity.png" alt="TeamCity"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.jetbrains.com/teamcity/"&gt;TeamCity&lt;/a&gt; is also known as the “Intelligent CI Server” because of its ease of use and integration. It offers different installation packages for different operating systems. It is a powerful tool developed from JetBrains, which allows building, and running tests even before changes are committed, hence keeping the code clean.&lt;/p&gt;

&lt;p&gt;Some of its features that make it one of the best Jenkins alternatives are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is well documented and provides easy installation.&lt;/li&gt;
&lt;li&gt;It provides integration with tools like Docker, JIRA, etc.&lt;/li&gt;
&lt;li&gt;It offers well-defined APIs available for extension.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. Travis CI
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dhzx4UCj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/Travis-CI.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dhzx4UCj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/Travis-CI.png" alt="Travis CI"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://travis-ci.org/"&gt;Travis CI&lt;/a&gt; is a continuous integration and testing CI/CD tool. It is free of cost for open source projects and provides seamless integration with GitHub. It supports more than 20 languages, like Node.js, PHP, Python, etc. along with Docker.&lt;/p&gt;

&lt;p&gt;Some of the key features of Travis CI includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Very easy to set up with broad user community support.&lt;/li&gt;
&lt;li&gt;No project is merged before tests are passed successfully.&lt;/li&gt;
&lt;li&gt;You can easily customize the build environment as per your requirements.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6. BuildMaster
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6_9Ppb6h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/BuildMaster.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6_9Ppb6h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/BuildMaster.png" alt="BuildMaster"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://inedo.com/buildmaster"&gt;BuildMaster&lt;/a&gt; by Inedo is one of the best Jenkins alternatives that offers continuous integration on different platforms. With BuildMaster, you can manage your apps and deploy them to the environment without any hassle. Moreover, it doesn’t require extensive expertise to set up the pipelines.&lt;/p&gt;

&lt;p&gt;Some of its features include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create release management platforms that can be self-managed.&lt;/li&gt;
&lt;li&gt;Automated gates prevent the release of untested software.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  7. Bitrise
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UgZeRG6X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/Bitrise.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UgZeRG6X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/Bitrise.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.bitrise.io/"&gt;Bitrise&lt;/a&gt;comes as a platform as a service (PaaS) for continuous integration and continuous delivery in mobile applications. Each build runs on its virtual machine, and at the end of the build, the data is scrapped. It offers a free plan and allows integration with services like Slack, HockeyApp, etc.&lt;/p&gt;

&lt;p&gt;Also, it provides features like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Apps are delivered without any manual intervention.&lt;/li&gt;
&lt;li&gt;It integrates with major third-party testing and deployment services.&lt;/li&gt;
&lt;li&gt;It allows quick setup having service integration with a lot of services.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  8. Spinnaker
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yHLulW2k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/Spinnaker.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yHLulW2k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/Spinnaker.png" alt="Spinnaker"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://spinnaker.io/"&gt;Spinnaker&lt;/a&gt; is an open-source platform developed by Netflix for continuous delivery. It is powerful and provides integration with major cloud providers. It supports multiple hosting technologies like Docker, Kubernetes, etc. It is useful for cloud-focused approaches.&lt;/p&gt;

&lt;p&gt;Some of the key features of Spinnaker includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Powerful and flexible pipeline management system.&lt;/li&gt;
&lt;li&gt;It provides integrations to the major cloud providers like Google Cloud Platform, AWS, Microsoft Azure, and Oracle Cloud.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  9. UrbanCode
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8GNwBWGM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/UrbanCode.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8GNwBWGM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/UrbanCode.png" alt="UrbanCode"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An IBM product, &lt;a href="https://www.urbancode.com/product/deploy/"&gt;UrbanCode&lt;/a&gt;, is a continuous integration application that provides multiple features like visibility, traceability, and auditing bundled in a single package. It enables you to deliver applications faster. Irrespective of the environment, you can quickly deploy applications to data centers, cloud, or virtual environments with no error.&lt;/p&gt;

&lt;p&gt;Some of its features that make it a preferred Jenkins alternative are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It minimizes deployment errors.&lt;/li&gt;
&lt;li&gt;Drag and drop feature in the editor makes it convenient to use.&lt;/li&gt;
&lt;li&gt;Increased frequency to deliver applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  10. Buddy
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6kb7BrwR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/Buddy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6kb7BrwR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/Buddy.png" alt="Buddy"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Buddy, also known as Buddy Works, is a continuous integration and delivery software with an interactive user interface, making for a perfect Jenkins alternative. It helps to build, test, and deploy applications faster quickly. You can get your CI/CD pipeline running in just a few minutes’ configurations.&lt;/p&gt;

&lt;p&gt;Besides, it provides feature like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It offers on-premise solutions.&lt;/li&gt;
&lt;li&gt;It provides support for multiple languages.&lt;/li&gt;
&lt;li&gt;One can customize the build and test environment as per requirements.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  11. Drone.io
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NGMqxpP9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/Drone.io_.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NGMqxpP9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/Drone.io_.png" alt="Droneio"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://drone.io/"&gt;Drone&lt;/a&gt; is considered one of the best Jenkins alternatives when it comes to integrating and deploying for busy development teams. It is a continuous self-service integration and delivery platform. It provides you the ability to customize multiple features on the go. It integrates easily with GitHub, GitLab, Bitbucket, and GitHub Enterprise.&lt;/p&gt;

&lt;p&gt;Some of its top features include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It supports multiple languages and operating systems.&lt;/li&gt;
&lt;li&gt;It provides plugins for pre-configured steps.&lt;/li&gt;
&lt;li&gt;Every build is executed in an isolated container.&lt;/li&gt;
&lt;li&gt;It provides auto-scaling with a single binary file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  12. AWS CodePipeline
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fM0EqDm3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/AWS-CodePipeline.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fM0EqDm3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/AWS-CodePipeline.png" alt="AWS CodePipeline"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aws.amazon.com/codepipeline/"&gt;AWS CodePipeline&lt;/a&gt; is a continuous integration and continuous delivery service that easily and quickly automates your release pipelines for updates. Every time you change the code, AWS CodePipeline will build, test, and deploy your application. Also, it can be easily integrated with GitHub.&lt;/p&gt;

&lt;p&gt;Some of its features that make it an ideal Jenkins alternative are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Follows the pay for what you use approach. You need not block your money or pay any fees. You only pay for what you are using.&lt;/li&gt;
&lt;li&gt;It provides a workflow that can be configured as per your release stages.&lt;/li&gt;
&lt;li&gt;It offers parallel execution, thereby increasing the workflow speed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  13. CruiseControl
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--chma_xoc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/CruiseControl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--chma_xoc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/CruiseControl.png" alt="CruiseControl"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://cruisecontrol.sourceforge.net/"&gt;CruiseControl&lt;/a&gt; is a continuous integration tool, and it provides a framework that can be extended to create customized build processes. Though written in Java, it can be used in different projects with the help of builders provided by it. It can integrate with different source control systems.&lt;/p&gt;

&lt;p&gt;Some of the key features of CruiseControl includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Provide remote management support.&lt;/li&gt;
&lt;li&gt;You can build multiple projects on a single server.&lt;/li&gt;
&lt;li&gt;Provides email and messaging notifications.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  14. Integrity
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--W2Saslf0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/intrgrity.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--W2Saslf0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/intrgrity.png" alt="intrgrity"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://integrity.github.io/"&gt;Integrity&lt;/a&gt; is a continuous integration server that builds your code and runs your test as soon as a commit happens. A report is then generated, and the users or the team is notified. The only limitation is that it can be used only with GitHub but can be mirrored with other SCM.&lt;/p&gt;

&lt;p&gt;Some of its features include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It supports multiple notification mechanisms.&lt;/li&gt;
&lt;li&gt;It works fine with GitHub Repos, public and private.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  15. Shippable
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4RBexso---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/Shippable-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4RBexso---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/Shippable-1.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.shippable.com/"&gt;Shippable&lt;/a&gt; provides an easy way to set up continuous integration and delivery for applications. It optimizes DevOps operations and provides ready-to-use build images. It provides analytics to help you improve. It also offers machine-level isolation to secure the workflows.&lt;/p&gt;

&lt;p&gt;Some of the key features of Shippable includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enable Continuous Improvement with rich analytics and insights.&lt;/li&gt;
&lt;li&gt;Secures your workflows with Role-Based Access Control (RBAC)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  16. CodeShip
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J6NkdX2s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/CodeShip.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J6NkdX2s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/CodeShip.png" alt="CodeShip"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codeship.com/"&gt;CodeShip&lt;/a&gt; is a hosted continuous integration and continuous delivery platform found by CloudBees. It provides fast feedback and customized environments to build applications. It provides integration with almost anything and is good at helping you scale as per your needs. It comes free for up to 100 monthly builds.&lt;/p&gt;

&lt;p&gt;Besides, it provides feature like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Parallel execution for fast feedback and minimum to no wait times.&lt;/li&gt;
&lt;li&gt;Easy to configure.&lt;/li&gt;
&lt;li&gt;It provides support for headless browsers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  17. Buildkite
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YlJox8mE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/Buildkite.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YlJox8mE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/Buildkite.png" alt="Buildkite"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://buildkite.com/"&gt;Buildkite&lt;/a&gt; enables you to run continuous integration pipelines on your infrastructure. It provides fast and secure integration. It allows you to run multiple builds with maximum control. It has an interface that provides visibility of your pipelines, which you can monitor.&lt;/p&gt;

&lt;p&gt;Some of its features include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It provides unlimited language support.&lt;/li&gt;
&lt;li&gt;It provides chat support for quick resolutions.&lt;/li&gt;
&lt;li&gt;It offers easy integration with tools like Slack, HipChat, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  18. GoCD
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bBsmmKyG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/GoCD.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bBsmmKyG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/GoCD.png" alt="GoCD"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.gocd.org/"&gt;GoCD&lt;/a&gt; comes as a continuous open-source integration and continuous delivery server with an end-to-end map showing the path to production in a single view. You can integrate it with popular environments like Kubernetes, Docker, and many more. It has advanced features of traceability wherein you can easily debug a broken pipeline.&lt;/p&gt;

&lt;p&gt;Some of its features that make it a capable Jenkins alternative are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It has a great support community.&lt;/li&gt;
&lt;li&gt;Easy to upgrade even when plugins are integrated.&lt;/li&gt;
&lt;li&gt;It provides fast feedback.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  19. Semaphore CI
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Hcsa65g2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/Semaphore-CI.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Hcsa65g2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/Semaphore-CI.png" alt="Semaphore CI"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://semaphoreci.com/"&gt;Semaphore&lt;/a&gt; provides you features for continuous integration and delivery by removing technical challenges. You need not depend on hiring staff specifically for deployments. You only need to define a workflow, and there you go with building a great application.&lt;/p&gt;

&lt;p&gt;Some of the main features of Semaphore CI includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It provides flexible pipelines for complex projects.&lt;/li&gt;
&lt;li&gt;It offers parallel testing for faster movement.&lt;/li&gt;
&lt;li&gt;Debugging capabilities for quick resolutions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  20. Microtica
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Rk_2FoDF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/Microtica.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Rk_2FoDF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/Microtica.png" alt="Microtica"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://microtica.com/"&gt;Microtica&lt;/a&gt; is a DevOps tool for automation with a complete software delivery process. It allows you to use reusable pieces of code to help you build infrastructure in no time. With Microtica’s pipeline workflow, you can get an overview of the build process at any given time. It’s not just all. It also allows you to automate sleep cycles, thus reducing AWS cost drastically.&lt;/p&gt;

&lt;p&gt;Also, it provides features like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It allows you to deploy microservices with Kubernetes in no-time.&lt;/li&gt;
&lt;li&gt;Reduce AWS costs for non-production environments&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  21. AppVeyor
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1o9PesCz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/AppVeyor.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1o9PesCz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/11/AppVeyor.png" alt="AppVeyor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.appveyor.com/"&gt;AppVeyor&lt;/a&gt; provides continuous integration and delivery services for any platform. You can quickly build, test, and deploy your applications in a fast manner. It supports GitHub, Bitbucket, Kiln, etc. Each build executes in an isolated and clean environment.&lt;/p&gt;

&lt;p&gt;Some of its features include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The console output makes it easy to debug the failure.&lt;/li&gt;
&lt;li&gt;It provides faster builds with virtual machines and pseudo access.&lt;/li&gt;
&lt;li&gt;It integrates with any source control tool.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;With so many options, you can easily pick an alternative to Jenkins. However, while going for any of the Jenkins alternatives, you need to check how well they can be integrated into your QA workflow to fulfill your needs. Do you know tools like Jenkins and most of its alternatives can be integrated well with &lt;a href="https://www.lambdatest.com/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-4122020&amp;amp;utm_term=Praveen"&gt;cross browser testing&lt;/a&gt; (CBT) tools like LambdaTest to ensure optimal user experience across all browsers and browser versions? Well, now, you do!&lt;/p&gt;

&lt;p&gt;We genuinely hope this guide has helped you find the best Jenkins alternative for your CI/CD needs. It took us a lot of time to narrow down the options so that you can save your research time, so if you did find this list valuable, we’d be grateful if you could share it on your LinkedIn or Twitter.&lt;/p&gt;

&lt;p&gt;And if it didn’t help you, we would like to know how to make it better. So, please let us know your honest feedback in the comments below.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>jenkins</category>
      <category>automation</category>
      <category>developer</category>
    </item>
    <item>
      <title>Here Are The Top Browsers For Cross Browser Testing In 2020</title>
      <dc:creator>Abeer Mishra</dc:creator>
      <pubDate>Thu, 10 Dec 2020 09:58:40 +0000</pubDate>
      <link>https://forem.com/aboywithscar/here-are-the-top-browsers-for-cross-browser-testing-in-2020-4mb4</link>
      <guid>https://forem.com/aboywithscar/here-are-the-top-browsers-for-cross-browser-testing-in-2020-4mb4</guid>
      <description>&lt;p&gt;We all know that user experience matters; it’s the key to delighting our customers. So, whether you are managing a live website or building a new one, you need to ensure a uniform user experience across all browsers and browser versions. Since web browsers don’t render the websites the same way, it becomes essential to perform cross browser testing and check website compatibility on different browsers.&lt;/p&gt;

&lt;p&gt;By performing &lt;a href="https://www.lambdatest.com/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-10122020&amp;amp;utm_term=Praveen"&gt;cross browser testing&lt;/a&gt;, you can ensure that the website behaves as intended across all the browsers. A website comprises the latest web technologies and languages such as HTML, CSS, Python, SQL, PHP, and JavaScript. All these web techs combine to give a complete look and function of the website. When these websites run on different web browsers, browsers execute the website code and display it to the users. But each browser interacts with websites uniquely and interprets the web components based on their arrangement to represent the website accordingly.&lt;/p&gt;

&lt;p&gt;To ensure such uniformity across all the browsers can be tedious as you have to consider testing websites on different browsers and browser versions before making it live for the users. However, there is a better way of handling this while performing cross browser compatibility testing. The first step towards this should be to choose the most relevant browsers for testing. Now you must be wondering how to do that. Well, this blog will answer that. Let’s get to it, shall we?&lt;/p&gt;

&lt;h2&gt;
  
  
  How To Select Right Browsers For Compatibility Testing?
&lt;/h2&gt;

&lt;p&gt;We all know that website is super important for every business these days. In fact, it is tough to find a successful business that doesn’t have a website. And we also know that first impression matters, and websites play an essential role in creating the first impression in your business. Therefore, it is crucial to perform &lt;a href="https://www.lambdatest.com/feature?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-10122020&amp;amp;utm_term=Praveen"&gt;browser compatibility testing&lt;/a&gt; to ensure that the website you designed for your brand works well in all types of browsers in different conditions.&lt;/p&gt;

&lt;p&gt;The question arises, which are the most crucial web browsers you need to test your websites on. To answer this, you need to analyze the most critical browser and versions on the following basis:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Basis of Popularity:&lt;/strong&gt; Select the most commonly used browsers on popular platforms like Windows, Android, and iOS. In this way, you can increase the test coverage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Basis of Website Analysis:&lt;/strong&gt; Analyze your website traffic through tools like Google Analytics and try to further breakdown based on browser, OS, and device. This will help you to understand which combination is most popular among your target audience.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;Any combination that has over 5% of traffic must be on your priority list.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Do you think you are testing your website on the right browsers? Well, to figure that, you need to take into consideration the geographical location of your visitors, devices they use, and the browser version they prefer. Now you must be wondering how to start or which browser you need to begin testing on. Well, you can start with the popular browsers. Given below are popular browsers in 2020 to articulate and modify your cross browser testing approach this year.&lt;/p&gt;

&lt;p&gt;Let’s check the stats:&lt;/p&gt;

&lt;h2&gt;
  
  
  Familiarize Yourself With Browser Support Worldwide
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WuR7lpnD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WuR7lpnD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/1.png" alt="Browser Support Worldwide"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chrome – 64.77%&lt;/li&gt;
&lt;li&gt;Safari – 17.61%&lt;/li&gt;
&lt;li&gt;Firefox – 4.31%&lt;/li&gt;
&lt;li&gt;Samsung Internet – 3.33%&lt;/li&gt;
&lt;li&gt;Opera – 1.96%&lt;/li&gt;
&lt;li&gt;UC Browser – 1.81%&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As you can see from the image above, Google Chrome wins the market share among the browsers this year, with 64.77% of the user, making it the most popular browser just like the previous year. So, it is clear that you need to include Chrome in your testing strategy for sure. However, that does not mean that you can neglect other browsers like Safari that takes an overall 17.61% user base, making it the second most used browser.&lt;/p&gt;

&lt;p&gt;Firefox is third with 4.31%, Samsung Internet fourth with 3.33%, Opera in fifth place with 1.96% users, and then UC Browser having 1.81% user base. Then comes the rest of the browsers like Microsoft Edge, Opera, Internet Explorer, etc. Though there are browsers that might not be popular globally, they can be critical to your business. For example, outdated browsers like IE and legacy edge need to be included in your browser list if your customers are using it.&lt;/p&gt;

&lt;p&gt;It is significant to understand that technologies and business trends keep changing. One example of that change is Microsoft Edge moving to Chromium that will influence future web standards. Before Microsoft edge became Chromium, browser testers would skip the inbuilt testing browsers by Microsoft. After subsequent changes, it became smart to include the new Edge browser to keep up with the current web standards.&lt;/p&gt;

&lt;p&gt;Considering browser versions is equally important while you are prioritizing the browser list. For example, considering Chrome as the most popular browser, you can include Chrome for Android and Chrome 80.0 in your priority list as they have the highest share among all versions of Chrome for Desktop and Android.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hnBEvKcb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/browser-verssion-market.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hnBEvKcb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/browser-verssion-market.png" alt="browser verssion market"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above stats show the browser market share irrespective of the platforms being used. If you consider the platforms such as desktop, mobile, tablets, etc. the stats will change.&lt;/p&gt;

&lt;h2&gt;
  
  
  Browser Popularity On Different Devices Worldwide
&lt;/h2&gt;

&lt;p&gt;We have discussed before how &lt;a href="https://www.lambdatest.com/feature?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-10122020&amp;amp;utm_term=Praveen"&gt;browser compatibility&lt;/a&gt; is different on different devices. Now, let’s see the most popular browser based on the device being used.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--w9zDoakI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/unnamed-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--w9zDoakI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/unnamed-2.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see that Mobile is leading as the most used platform worldwide with 51.24% of market share as compared to Desktop and Tablet, which are 46.02% and 2.74%, respectively. Therefore, it is imperative to consider the popular browsers on mobile devices for cross browser testing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mobile
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7wB_bECB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/Mobile-browser-market.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7wB_bECB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/Mobile-browser-market.png" alt="Mobile browser market"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chrome – 62.6%&lt;/li&gt;
&lt;li&gt;Safari – 23.83%&lt;/li&gt;
&lt;li&gt;Samsung Internet – 6.5%&lt;/li&gt;
&lt;li&gt;UC Browser – 3.37%&lt;/li&gt;
&lt;li&gt;Opera – 1.65%&lt;/li&gt;
&lt;li&gt;Firefox – 0.44%&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;62.6% of users prefer Chrome for mobile browsing, making it the number one mobile browser. Safari browser ranks second with 23.83%, therefore including this browser is a must for targeting the mobile device audiences.&lt;/p&gt;

&lt;p&gt;Next, we have Samsung Internet with a 6.5% score, and then comes the UC Browser and Opera with 3.37% and 1.65% users, respectively. You can consider including all these browsers while testing your website on mobile browsers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Desktop
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8n783oC0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/Desktop-browser-market.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8n783oC0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/Desktop-browser-market.png" alt="Desktop browser market"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chrome – 69%&lt;/li&gt;
&lt;li&gt;Safari – 8.84%&lt;/li&gt;
&lt;li&gt;Firefox – 8.82%&lt;/li&gt;
&lt;li&gt;Edge Legacy – 3.26%&lt;/li&gt;
&lt;li&gt;IE – 3.06%&lt;/li&gt;
&lt;li&gt;Others – 7.02%&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When it comes to desktop browsers, the first three positions go to Chrome, Safari, and Firefox, with almost 69%, 8.84%, and 8.82% market share. Edge and Internet Explorer take the fourth and fifth positions. Hence, it will be beneficial to keep these browsers in your plan for browser testing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tablets
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GZu2mmhd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GZu2mmhd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/t.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Safari – 49.33%&lt;/li&gt;
&lt;li&gt;Chrome – 36.4%&lt;/li&gt;
&lt;li&gt;Android – 11.96%&lt;/li&gt;
&lt;li&gt;Firefox – 0.69%&lt;/li&gt;
&lt;li&gt;Opera – 0.54%&lt;/li&gt;
&lt;li&gt;Others – 1.09%&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Safari is the most used browser on tablets, with a market share of 49.33%. Chrome tends to lead the market for overall browser use but stands second on Table with a 36.4% user base. Hence, it is clear from this example why it is crucial to consider every device while performing browser testing.&lt;/p&gt;

&lt;p&gt;Imagine you did not test the Safari browser enough, thinking that the Chrome browser is the most popular. In that case, you are neglecting the user-experience of all the Tablet users of your websites. If any of the features are not working fine in Safari, it will not work for all of the Tablet users, creating negative impacts on your business.&lt;/p&gt;

&lt;h2&gt;
  
  
  Browser Popularity In The Continental Regions On All Platforms
&lt;/h2&gt;

&lt;p&gt;Do you know that user behavior and preference for choosing a browser change when we compare different geographies? Well, now, you do! Which makes it crucial to understand your users, especially if you target specific geography for your business.&lt;/p&gt;

&lt;h3&gt;
  
  
  United States Of America
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wxEKoKTc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/United-States-Of-America.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wxEKoKTc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/United-States-Of-America.png" alt="United States Of America"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chrome – 47.1%&lt;/li&gt;
&lt;li&gt;Safari – 36.47%&lt;/li&gt;
&lt;li&gt;Firefox – 4.14%&lt;/li&gt;
&lt;li&gt;Edge Legacy – 2.79%&lt;/li&gt;
&lt;li&gt;IE – 2.77%&lt;/li&gt;
&lt;li&gt;Samsung Internet – 2.36%&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Chrome and Safari are the two most essential browsers in the United States Of America, as we can see from the image above that 83.57% of users trust these two browsers. Taking a look at this chart can immensely help you to make the browser testing strategy here. We all should note that the user base here prefers legacy browsers like Edge and Internet Explorer too.&lt;/p&gt;

&lt;p&gt;With Microsoft Edge becoming Chromium, it can bring an enormous change in this region’s stat. Compared to other continents, graphs are quite different here; therefore, select your browsers accordingly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;Please keep in mind; these stats depict the overall popularity of the browser, including all the platforms in which users operate them, whether it is Mobile, Desktop, Tablet, etc. Therefore, you need to give priority to these browsers based on the running platforms as well.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Europe
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5QEEF2Yn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/eu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5QEEF2Yn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/eu.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chrome – 61.31%&lt;/li&gt;
&lt;li&gt;Safari – 18.33%&lt;/li&gt;
&lt;li&gt;Firefox – 7.14%&lt;/li&gt;
&lt;li&gt;Samsung Internet – 3.87%&lt;/li&gt;
&lt;li&gt;Opera – 2.28%&lt;/li&gt;
&lt;li&gt;Edge Legacy – 2.23%&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Chrome is the most popular browser here; with a 61.31% share, it holds first place. Firefox is the second popular browser in Europe, although the difference here is that stats are relatively high compared to other regions with 18.33%.&lt;/p&gt;

&lt;p&gt;There is not much change in the European market for the browser except that the Samsung Internet and Opera are now a little forward in share and other browsers like Yandex at the very end. Internet Explorer is quite behind in Europe, but as we know, the market keeps changing every day, and we can expect some changes here as well after Microsoft Edge became Chromium.&lt;/p&gt;

&lt;h3&gt;
  
  
  Asia
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wnzxv1Bj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/aa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wnzxv1Bj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/aa.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chrome – 71.09%&lt;/li&gt;
&lt;li&gt;Safari – 11.06%&lt;/li&gt;
&lt;li&gt;UC Browser – 4.04%&lt;/li&gt;
&lt;li&gt;Samsung Internet – 3.7%&lt;/li&gt;
&lt;li&gt;Firefox – 2.88%&lt;/li&gt;
&lt;li&gt;Opera – 1.82%&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/which-browsers-are-important-for-your-cross-browser-testing/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-10122020&amp;amp;utm_term=Praveen"&gt;If you checked the stats last year&lt;/a&gt;, you could notice an immense difference between the UC Browser and Safari this year, which was much less last year, and UC Browser was popular than Safari. Therefore, you can strategize your testing process by giving Safari much more attention. Coming up next in popularity, we have Samsung Internet and Firefox with a small difference in numbers. Microsoft Edge and Internet Explorer are catching up here as well. Hence we have to watch out for these in Asia as well.&lt;/p&gt;

&lt;h3&gt;
  
  
  Africa
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n0tCjmT---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/af.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n0tCjmT---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/af.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chrome – 70.14%&lt;/li&gt;
&lt;li&gt;Safari – 8.77%&lt;/li&gt;
&lt;li&gt;Opera – 7.79%&lt;/li&gt;
&lt;li&gt;Firefox – 4.41%&lt;/li&gt;
&lt;li&gt;Samsung Internet – 4.12%&lt;/li&gt;
&lt;li&gt;UC Browser – 1.25%&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If we skip the all-time popular browser Chrome, we will see that Safari dominates the charts this year, leaving the Opera browser behind. Samsung Internet is now in fifth place, which was much behind last year. Surprisingly, Microsoft Edge and Internet Explorer are in the race after the UC Browser, which can be a great example of how going Chromium is beneficial for them. Although we still have to look forward to how new Edge is going to change the market trend in the coming days. For now, you can focus on these browsers for your target audience in Africa.&lt;/p&gt;

&lt;h3&gt;
  
  
  Oceania
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6vYbmNjb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/oc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6vYbmNjb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/10/oc.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chrome – 52.84%&lt;/li&gt;
&lt;li&gt;Safari – 32.22%&lt;/li&gt;
&lt;li&gt;Firefox – 3.82%&lt;/li&gt;
&lt;li&gt;Samsung Internet – 3.34%&lt;/li&gt;
&lt;li&gt;Edge Legacy – 2.45%&lt;/li&gt;
&lt;li&gt;Edge – 1.57%&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Catching up with North America’s graphs, the Oceania region also has a large user base, to be precise, 32.22% that uses Safari. Therefore, give priority to this browser for your targeted audience of this geographical area. You can keep Firefox and Samsung Internet as the third preference. Catching up with the competition, Edge Legacy and Edge come next with almost 2.45% and 1.57%, respectively.&lt;/p&gt;

&lt;p&gt;From the above statistics of different continents, we can conclude that the user’s preferences vary. Some regions prefer Safari way too much, whereas some have quite similar stats for Safari and Firefox.&lt;/p&gt;

&lt;p&gt;In certain areas, Internet Explorer and Edge come next, while Samsung Internet and Opera have a higher user base in other places. Therefore, you need to change and plan your browser testing strategy accordingly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;By now, you must be clear that Chrome is the most popular browser in all regions. That doesn’t mean you can overlook other popular browsers like Firefox and Safari. The second or the third most crucial browser based on different devices and geography are equally essential for targeting global audiences. Therefore, it becomes imperative to track the sources of your website traffic. When you have that data, you need to ensure that your website works seamlessly on those browsers and browser versions, including the older ones.&lt;/p&gt;

&lt;p&gt;Installing so many browsers on different devices and testing them on those platforms can be very hectic. Therefore, proper planning is a must before browser testing. It would be best to &lt;a href="https://www.lambdatest.com/blog/cross-browser-testing-strategy-explained-in-three-easy-steps/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-10122020&amp;amp;utm_term=Praveen"&gt;strategize your cross browser testing&lt;/a&gt; by breaking down the browsers concerning device and geography. After knowing which browser is more prevalent in a specific device or country, you can test websites on different browsers based on your target audiences. However, to further ease down the cross browser testing effort, you can rely on tools like LambdaTest that provides feature like Geo Location Testing for better coverage along with automation testing, local testing, parallel testing, etc.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>browsers</category>
    </item>
    <item>
      <title>Top 10 Java Testing Frameworks For 2020</title>
      <dc:creator>Abeer Mishra</dc:creator>
      <pubDate>Thu, 24 Sep 2020 09:26:02 +0000</pubDate>
      <link>https://forem.com/aboywithscar/top-10-java-testing-frameworks-for-2020-57i0</link>
      <guid>https://forem.com/aboywithscar/top-10-java-testing-frameworks-for-2020-57i0</guid>
      <description>&lt;p&gt;When we talk about programming in the modern tech world, Java instantly comes to our mind. After all, it is considered as one of the most versatile programming languages. Looking back on its history, Java has always had an extraordinary position in a back-end developer’s heart. A majority of developers enjoy Java due to its platform independency, security, ease of use, variety of accessible resources, and several other essential features. These traits appreciably contributed to the popularity of Java as a programming language – as of 2018, there were &lt;a href="https://adtmag.com/articles/2018/09/24/developer-economics-survey.aspx" rel="noopener noreferrer"&gt;seven million or more Java developers&lt;/a&gt; globally.&lt;/p&gt;

&lt;p&gt;Undoubtedly, Java has positioned itself as one of the admired programming languages for web development projects. Looking back at the results of 2019, Java was positioned in the list of Top 5 Most Popular Technology which, in turn, encouraged the usage of &lt;a href="https://www.lambdatest.com/blog/top-10-java-testing-frameworks/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=PM-24092020&amp;amp;utm_term=PM" rel="noopener noreferrer"&gt;Java testing frameworks&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let’s look at some statistics:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;According to the &lt;a href="https://www.tiobe.com/tiobe-index/" rel="noopener noreferrer"&gt;TIOBE Popularity index&lt;/a&gt;, in 2020 Java was the second most famous programming language across the world. It was also the ‘language of the year’ for 2005, 2015 and got the top position in popularity (since 2001.)&lt;/li&gt;
&lt;li&gt;In 2019, Java was the &lt;a href="https://www.tiobe.com/tiobe-index/" rel="noopener noreferrer"&gt;most popular programming language&lt;/a&gt; globally. It comes with a great system with nine million or more Java developers. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2020%2F09%2Fjava-testing-frameworks.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2020%2F09%2Fjava-testing-frameworks.png" alt="java testing frameworks"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every year, StackOverflow, (one of the largest online communities for software developers) releases its &lt;a href="https://insights.stackoverflow.com/survey/2020#overview" rel="noopener noreferrer"&gt;Developer Survey&lt;/a&gt; for tech enthusiasts across the globe. For the 8th year in a row, JavaScript positioned itself as the most commonly and popularly used programming language.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2020%2F09%2FJavaScript-Testing-Frameworks.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.lambdatest.com%2Fblog%2Fwp-content%2Fuploads%2F2020%2F09%2FJavaScript-Testing-Frameworks.png" alt="JavaScript Testing Frameworks"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Java Testing Frameworks To Use In 2020
&lt;/h2&gt;

&lt;p&gt;Java unit testing frameworks provide programmers with a standardized, sophisticated, and extensible means to build a web application or any other software. It comprises a massive collection of packages that supply pre-written code. Depending on your choice of testing frameworks for Java, they incorporate libraries, compilers, tools, and APIs.&lt;/p&gt;

&lt;p&gt;Moreover, extensive Java unit testing frameworks always deliver a secured application. So in case of a security gap, one can resolve it within the framework’s website/support with zero trouble. They even offer built-in functions and modules to enable efficiency and speed for the developers and testers.&lt;/p&gt;

&lt;p&gt;What to expect from Java testing frameworks this decade?&lt;/p&gt;

&lt;p&gt;Well, here are the best Java testing frameworks that are likely to make a great difference in 2020.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. JBehave
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://jbehave.org/" rel="noopener noreferrer"&gt;JBehave&lt;/a&gt;is an incredible and one of the best Java testing frameworks that supports BDD (Behaviour-Driven Development). BDD is an evolution of TDD (Test-Driven Development) and ATDD (Acceptance Test-Driven Development).&lt;/p&gt;

&lt;p&gt;Behaviour-Driven Development is intended to make these practices insightful and more accessible for both beginners and specialists. It shifts the terms to behaviour-based from being test-based, and sets itself as a design paradigm, highlighting communication, and automation alike.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JBehave distributions&lt;/p&gt;

&lt;p&gt;Core distributions of Jbehave are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JBehave Web&lt;/li&gt;
&lt;li&gt;JBehave Core&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites For Installing JBehave&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the proper ways to make use of this testing framework for Java is to incorporate it with Eclipse. Indeed, for this, despite JDK1.7 &amp;amp; above as well as any Eclipse IDE (integrated development environment) above indigo, one would require various jar files such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Commons-lang-2.4.jar&lt;/li&gt;
&lt;li&gt;Junit-4.1.0.jar&lt;/li&gt;
&lt;li&gt;Jbehave-core-3.8.jar&lt;/li&gt;
&lt;li&gt;Freemarker-2.3.9.jar&lt;/li&gt;
&lt;li&gt;Plexus-utils-1.1.jar&lt;/li&gt;
&lt;li&gt;Paranamer-2.5.jar&lt;/li&gt;
&lt;li&gt;Org.apache.commons.collections.jar&lt;/li&gt;
&lt;li&gt;Org.apacje.commons.io.jar&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JBehave BDD testing framework is also beneficial in multiple ways.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Products have superior specifications because of the fact that this testing framework for Java features reasoning, and intuitiveness in a detailed way.&lt;/li&gt;
&lt;li&gt;Serves a great purpose for BDD by offering integration among distinct development teams engaged with varied projects yet similar specifics.&lt;/li&gt;
&lt;li&gt;JBehave framework uses a semi-formal language which is a great help for developers. Having a domain vocabulary feature aids in managing consistency in the team structure.&lt;/li&gt;
&lt;li&gt;Even, stakeholders, as well as project managers, get better transparency regarding the QA teams &amp;amp; dev team productivity as the specs have the same format.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There is only one loophole or con of JBehave just like any other BDD testing framework.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;BDD testing framework or tool success rate mostly comes down to significant communication carried out among members working in a project. It can be between the management team, the testers, the developers, and the stakeholders.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Improper communication may lead to unanswered doubts and queries. In the end this can lead to a flaw-filled app or an app not meeting up to client requirements, resulting in a blame game between all the involved parties.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is JBehave One Of The Best Java Testing Frameworks For You?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JBehave- the testing framework for Java works similar to frameworks like Serenity. But, if you plan to create the automated acceptance tests effectively, it is better to incorporate JBehave along with Serenity for utilizing an ideal test experience. The entire concept of Serenity is based on BDD development and it also lets the users write a rich and powerful testing report.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. JUnit
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://junit.org/junit5/" rel="noopener noreferrer"&gt;JUnit&lt;/a&gt; is an open-source regression testing framework that is used mainly by expert software developers to execute unit testing, speed up programming, and improve the quality of code in Java. The key purpose of introducing this framework is to allow Java developers to script and implement repeated test cases. This is amongst the most commonly used Java unit test frameworks.&lt;/p&gt;

&lt;p&gt;JUnit framework is majorly used by experts to test small bunches of code. You can also carry out automated tests of a site by combining Selenium WebDriver with JUnit for Java automated testing. When any fresh code is added, you will be asked to reboot the complete test cases and ensure about zero breakage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Test suites&lt;/li&gt;
&lt;li&gt;Fixtures&lt;/li&gt;
&lt;li&gt;JUnit classes&lt;/li&gt;
&lt;li&gt;Test runners&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites For Installing JUnit&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Based originally on SUnit &amp;amp; written in Smalltalk, this Java unit testing framework is extremely attuned with &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=PM-24092020&amp;amp;utm_term=PM" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt;. The key reason being, it is derived from Java. Some prerequisites, you will need to follow these-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Should have the JDK newest version installed in your system.&lt;/li&gt;
&lt;li&gt;(Optional) Unzip the $JUNIT_HOME/src. jar file.&lt;/li&gt;
&lt;li&gt;Have great know-how and expertise of app growth in an object-oriented language, particularly Java programming.&lt;/li&gt;
&lt;li&gt;Download the new JUnit version &amp;amp; set up the environment.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are various benefits of using JUnit among the available Java testing frameworks.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It can be used for both integration and unit tests as it supports Java 8 features. Bugs can be easily detected in the early phase, ensuing in an unfailing and reliable code.&lt;/li&gt;
&lt;li&gt;Developers or programmers, who work in a test-driven environment, find it extremely useful. They find it easier to read the code and scrutinize any glitches present.&lt;/li&gt;
&lt;li&gt;The development of an anomaly free code as well as a more readable code acts as a confidence augmenter.&lt;/li&gt;
&lt;li&gt;Almost all major IDEs, like Eclipse, NetBeans, Maven, Ant, and IntelliJIDEA, provide JUnit framework integrations. So, you can easily write and start unit testing straight from those IDEs.&lt;/li&gt;
&lt;li&gt;By using the upgraded JUnit version (version 5), one can identify exemption very easily. Plus, they can implement test cases written in the older JUnit version.&lt;/li&gt;
&lt;li&gt;One can also use this unit test framework for Java with Java 5 or other versions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JUnit framework is not capable of implementing dependency tests. Thus, in this state, we necessitate TestNG.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Is JUnit One Of The Best Java Testing Frameworks For You?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JUnit is a commonly used open-source framework based on Java. Both TestNG as well as JUnit do a similar job and their key traits are somehow the same, excluding the dependency test capabilities. The execution procedure of parameterized testing is also distinct in both frameworks.&lt;/p&gt;

&lt;p&gt;Due to the fact that JUnit has been used for an extended period, there is great support from the community. It has been also defined as the standard Java Unit Testing Frameworks by integrating Selenium WebDriver for Java-based applications. Although TestNG has few users and the community is ever-growing. Thus, we are wrapping up with the suggestion that the choice between JUnit or TestNG for a Java test framework entirely depends upon the nature and necessities of specific applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Serenity
&lt;/h3&gt;

&lt;p&gt;Formerly recognized as Thucydides, &lt;a href="http://www.thucydides.info/#/" rel="noopener noreferrer"&gt;Serenity&lt;/a&gt; is one of the most extensively-used open-source Java testing frameworks. Serenity BDD framework assists you to write acceptance criteria, which are cleaner, structured, and manageable. It enhances the functionality of both Selenium WebDriver and JUnit.&lt;/p&gt;

&lt;p&gt;With this specialized framework, you can create descriptive testing reports. Besides, you can map automated testing back to your needs. In general, this automation framework for Java makes Java development services more reliable and effective.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open Source project&lt;/li&gt;
&lt;li&gt;Complete reports on test results &amp;amp; implementation &lt;/li&gt;
&lt;li&gt;Business-readable formatted report for every test&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites For Installing Serenity&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As the automated framework is entirely Java-based, you will certainly need know-how in Java or any other object-oriented programming language. Besides this, your system will necessitate-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JDK 5 or higher version above.&lt;/li&gt;
&lt;li&gt;Maven 3.0 or any updated high version.&lt;/li&gt;
&lt;li&gt;An IDE tool – Eclipse as well as Maven is generally preferred by all programmers or developers as they are painless to work with.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s glance over the benefits of using Serenity.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This automation framework for Java helps the tester to craft test cases for REST services.&lt;/li&gt;
&lt;li&gt;It maintains a balance, rather a margin between the description and understanding of a test case and its implementation approach.&lt;/li&gt;
&lt;li&gt;Users don’t need to pay out extra time to maintain or build their own automated framework.&lt;/li&gt;
&lt;li&gt;Serenity can be integrated with plenty of frameworks such as advanced development frameworks for Java like Spring, other frameworks like Selenium, JBehave, and with project management tools like JIRA.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The con of Serenity is similar to the JBehave framework for Java. Regular communication between the project participants is necessary in order to make the best of the support provided for BDD.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is Serenity One Of The Best Java Testing Frameworks For You?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This Java testing framework is mainly utilized for writing and reporting acceptance criteria. The reports written using Serenity are very effective, useful, advantageous, rich, and very informative than other BDD frameworks like JBehave. It assists programmers to write superior quality automation test case scenarios. Serenity also supports Selenium WebDriver and Rest Assured, making it faster and easier for the QA engineers to write automated acceptance test criteria.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. TestNG
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://testng.org/doc/" rel="noopener noreferrer"&gt;TestNG&lt;/a&gt; is amongst the most popular and powerful Java testing frameworks used for Integration, Functional, and Unit testing. It was created by Cedric Beust in 2004 and has now been updated to version 7. It is a tough competitor of frameworks like the JUnit framework. TestNG is similar to JUnit, yet it is configured with extraordinary annotations and superior functionalities (not supported by Junit).&lt;/p&gt;

&lt;p&gt;The NG in TestNG denotes the ‘next generation.’ TestNG can cover almost every type of software testing, counting end-to-end, unit, integration, and functional testing. Both TestNG and JUnit are Java-based frameworks that allow you to write tests and scrutinize end results. If testing gets succeeded, you will see a green bar, otherwise, a red bar.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Supports dependent methods testing&lt;/li&gt;
&lt;li&gt;Test configuration flexible&lt;/li&gt;
&lt;li&gt;Supports sturdy execution model&lt;/li&gt;
&lt;li&gt;Set in BeanShell for additional flexibility&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites For Installing TestNG&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Java-based framework helps developers with core features like grouping, sequencing, and parameterizing. This makes the newest test cases adaptable and eradicates the loopholes of frameworks used previously. For installing TestNG, you will need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JDK latest version installed in your system.&lt;/li&gt;
&lt;li&gt;Latest version of Eclipse.&lt;/li&gt;
&lt;li&gt;Understanding and practical experience of Java programming language or some other object-oriented programming language.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Despite overcoming the anomaly of the oldest frameworks, there are quite a few benefits of TestNG.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Allows creating, and running parallel testing on multiple code snippets.&lt;/li&gt;
&lt;li&gt;While implementing the test case, you can create an HTML report.&lt;/li&gt;
&lt;li&gt;Test cases can be easily organized and grouped in accordance with priorities. Performing the tests is far easier, simply by putting the framework to run front-end testing or database testing.&lt;/li&gt;
&lt;li&gt;Priorities can be easily set by data parameterizing and by utilizing annotations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TestNG might not be the right fit for you if your project doesn’t need prioritization in the test case. Besides, setting up TestNG requires more time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Is TestNG One Of The Best Java Testing Frameworks For You?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As we already know, JUnit test framework performs all the same functions as TestNG but it has some drawbacks. JUnit is amazing when the test is performed in isolation; however, when there is some kind of dependency, you won’t get any control over which testing is done earlier. TestNG frameworks for Java aid you by letting you execute test cases the way you want to.&lt;/p&gt;

&lt;p&gt;Furthermore, you get added support for &lt;a href="https://www.lambdatest.com/blog/parameterization-in-testng-dataprovider-and-testng-xml-examples/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=PM-24092020&amp;amp;utm_term=PM" rel="noopener noreferrer"&gt;Parameterization In TestNG&lt;/a&gt;. Even though this particular trait is already found in JUnit 4.5, the TestNG framework is more helpful. If any project is complex and you may necessitate 100 or more test cases, it is better to get some extra time and set up a TestNG framework rather than depending completely on other frameworks like JUnit.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Selenide
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://selenide.org/" rel="noopener noreferrer"&gt;Selenide&lt;/a&gt;is a popular and open-source Java testing framework which is powered by Selenium WebDriver. It is a great tool for writing precise, communicative, and stable UI test cases for a Java app. It expands the WebDriver and JUnit functionalities.&lt;/p&gt;

&lt;p&gt;WebDriver is one of the well-admired tools for User Interface testing, yet it is devoid of the trait to deal with a timeout. For instance, testing of web technologies such as Ajax. Selenide framework manages all these issues in an easy manner. Besides, it is simpler to install and learn. You simply need to concentrate on the logic and Selenide will do the rest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Out of the box and all set to use the framework. &lt;/li&gt;
&lt;li&gt;Write less automation code.&lt;/li&gt;
&lt;li&gt;Saves a ton of time.&lt;/li&gt;
&lt;li&gt;Configuration ideal for CI Tool such as Jenkins.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites For Installing Selenide&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As this open-source framework is Java-based, you will need experience in Java or other object-oriented programming languages. In your workstation, you will also need-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JDK 5 or updated version&lt;/li&gt;
&lt;li&gt;Maven 3.0 or other versions installed&lt;/li&gt;
&lt;li&gt;An Integrated Development Environment (IDE) tool – Most commonly, Eclipse is preferred by all developers as the combo of Eclipse &amp;amp; Maven is simpler to work with.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Selenide continues to make a great impact by offering various benefits for test automation teams:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First and foremost of all, it makes your tests precise and stable by solving (nearly) all Ajax/timing problems.&lt;/li&gt;
&lt;li&gt;Brief writing process of test cases that decreases the timeout issues.&lt;/li&gt;
&lt;li&gt;Supports app tests developed using AngularJS.&lt;/li&gt;
&lt;li&gt;Shortens so many commands which were formerly used by other traditional tools of Selenium.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Till now, nobody has found any notable drawback of using Selenide.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is Selenide One Of The Best Java Testing Frameworks For You?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you wish to go for User Interface tests, you will probably look into Selenium WebDriver first. However, Selenium WebDriver can’t solve issues concerning JavaScript’s slow running or Ajax timeout or any dynamic content which consumes extra time in loading. To conquer these problems, we formerly used “sleep” or “wait_until” techniques in the test cases. With specific Java testing frameworks like Selenide, we don’t have to think about those issues any longer.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Gauge
&lt;/h3&gt;

&lt;p&gt;Selenium creators Thoughtworks launched another Java testing framework for carrying automated tests of web apps. &lt;a href="https://gauge.org/" rel="noopener noreferrer"&gt;Gauge&lt;/a&gt;is an open-source and free test automation framework for Java that takes the stress out of acceptance testing with less code involvement. It is one of the frequently used Java testing frameworks in the mobile website testing category of a tech stack.&lt;/p&gt;

&lt;p&gt;Automated tests using this framework for Java can create readable tests with languages of your preference. Similar to Selenium, this test automation framework also offers support for several languages like Ruby, JavaScript, Java, C #, and Python.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simple to use, flexible syntax&lt;/li&gt;
&lt;li&gt;Uses a business-like language&lt;/li&gt;
&lt;li&gt;Supports maximum languages and platforms &lt;/li&gt;
&lt;li&gt;Uncountable plugins&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites For Installing Gauge&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Download and install &lt;a href="https://maven.apache.org/install.html" rel="noopener noreferrer"&gt;Maven&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Operating system versions- Microsoft Windows 10 or higher. &lt;/li&gt;
&lt;li&gt;Memory should be 512 MB of RAM (minimum.)&lt;/li&gt;
&lt;li&gt;Gauge plugin must be configured with your Integrated Development Environment (IDE) or Gauge framework should be installed if in case you are running the test from CMD/Terminal.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Gauge continues to make a significant impact by offering numerous rewards for agile teams throughout the DevOps procedure, including immediate feedback and ease of use. Let’s take a look at other advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Gives a business layer on top of the scripts to make them readable &amp;amp; understandable.&lt;/li&gt;
&lt;li&gt;Simple-to-use, flexible syntax, and support for all types of languages (Java, Javascript, C#, Ruby, Python, etc.) and platforms.&lt;/li&gt;
&lt;li&gt;Lets you create tests in the Integrated Development Environment (IDE) of your choice (IntelliJ, Vi VS Code, Visual Studio, Maven, Gradle, Eclipse,etc.)&lt;/li&gt;
&lt;li&gt;Run parallel testing and create tailored reports intelligently.&lt;/li&gt;
&lt;li&gt;Effortlessly test with big sets of data, while keeping specifics highly precise and readable. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Gauge is completely new, and therefore, users don’t prefer this framework. While the open-source community continues to improve upon it on a daily basis.&lt;/li&gt;
&lt;li&gt;Gauge doesn’t support the safe parallel implementation of specs inside IntelliJ, because of the fact that the driver is static and has to be shared amid the scripts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Is Gauge One Of The Best Java Testing Frameworks For You?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Gauge Java testing framework works great specifically for carrying out cross browser testing. This framework has incredibly revolutionized test automation procedures, allowing even non-technical users to write a test automation framework with ease. It solves real anomalies with test maintenance – thanks to its growing community and contribution of early adopters.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Geb
&lt;/h3&gt;

&lt;p&gt;Based on Groovy, Geb is a testing framework for browsers built as a cherry on the Selenium WebDriver shaped cake. This makes it perfect for automated testing and you can easily perform cross browser testing on all browsers that are supported by WebDriver. Geb test automation framework for Java provides extraordinary traits for screen scraping, web testing, and many more.&lt;/p&gt;

&lt;p&gt;What makes it exceptional is the manner it queries the HTML pages, by giving the jQuery-like syntax. Geb framework also offers built-in support for the &lt;a href="https://www.lambdatest.com/blog/selenium-java-testing-page-object-model/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=PM-24092020&amp;amp;utm_term=PM" rel="noopener noreferrer"&gt;Page Object Model&lt;/a&gt;. Geb can be used for general scraping, scripting, as well as automation. It is equally well suited as an acceptance, web or functional testing solution through integration with test frameworks like TestNG, JUnit, and Spock.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Elegance of jQuery choice&lt;/li&gt;
&lt;li&gt;Licence under the Apache License, Version 2.0.&lt;/li&gt;
&lt;li&gt;Power of WebDriver&lt;/li&gt;
&lt;li&gt;Page Object Modelling robustness&lt;/li&gt;
&lt;li&gt;Articulacy of Groovy&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites For Installing Geb&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You have to download and install &lt;a href="https://maven.apache.org/install.html" rel="noopener noreferrer"&gt;Maven&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Ensure you have Java installed in the system. It is better to &lt;a href="https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html" rel="noopener noreferrer"&gt;install Java 8&lt;/a&gt; or high versions for steady implementation. &lt;/li&gt;
&lt;li&gt;LambdaTest authentication and validation credentials. You can sign up right &lt;a href="https://accounts.lambdatest.com/register" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Replication of LambdaTest &lt;a href="https://github.com/LambdaTest/" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt; for Geb test automation framework.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s look at the advantages of Geb testing framework for Java:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Page Objects form and Groovy DSL of Geb make tests easily readable as they more or less look like plain English.&lt;/li&gt;
&lt;li&gt;Runs the tests with high-speed and saves your cost of testing. Compatible with various browsers like Internet Explorer, HTMLUnit, Firefox, and Chrome.&lt;/li&gt;
&lt;li&gt;Runs the tests in real-time and in real environment- the one that the user would observe. It supports maximum test coverage within the single script.&lt;/li&gt;
&lt;li&gt;It keeps regression testing trouble-free. You can run Geb test cases to check if any active functionality is breaking following a modification or mend in the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Limitation of the Geb is that it executes WebDriver in the Groovy language. Hence, when using Webdriver, only this specific language will be supported. However, if you try to use WebDriver directly, it supports several other languages like Java, Ruby, C#, and Python.&lt;/li&gt;
&lt;li&gt;Geb won’t work great for small projects; it works well for huge tasks. If your web app doesn’t comprise various pages and forms through which the data requires to flow, you might find this framework truly expensive.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Is Geb One Of The Best Java Testing Frameworks For You?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Geb Java testing framework provides smart integration modules for frameworks like Cucumber, TestNG, JUnit, and Spock. However, Spock is a great match with Geb. Using Geb with Spock can give concise, clear, and understandable test specifications with less effort.&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Spock
&lt;/h3&gt;

&lt;p&gt;&lt;a href="http://spockframework.org/" rel="noopener noreferrer"&gt;Spock&lt;/a&gt;is a popular test automation framework for Java. It is written in Groovy and allows testing experts to perform Data-Driven Tests on Java Virtual Machine. Spock provides incredible compatibility to many languages that are supported by JVM. The Spock UI is truly helpful and amazing in comparison to various other Java automation test frameworks.&lt;/p&gt;

&lt;p&gt;One of the best features of Spock is that the code documentation and code readability is orderly and neat, plus it can interpret common English sentences. It is frequently used by software developers to build enterprise apps in Java. Thus, making it the most popular and convenient testing frameworks for Java in 2020.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Originally created in 2008 by Peter Niederwieser&lt;/li&gt;
&lt;li&gt;Superset of the de facto test framework for Java: JUnit &lt;/li&gt;
&lt;li&gt;Spock has its own Mocking &lt;/li&gt;
&lt;li&gt;Tests can be written for any language&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites for Installing Spock&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The latest version of JDK &lt;/li&gt;
&lt;li&gt;The updated version of Eclipse&lt;/li&gt;
&lt;li&gt;Knowledge of Java programming language&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Spock is the most popular test automation framework that provides the following crucial advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Amazing readability, providing compatibility towards plain English sentences compared to other Java automation test frameworks.&lt;/li&gt;
&lt;li&gt;Stubbing and Mocking are very easy and painless than ever with Spock. Besides, both Stubbing and Mocking are in-built.&lt;/li&gt;
&lt;li&gt;Crispier and shorter parameterization.&lt;/li&gt;
&lt;li&gt;Provides surrounding context, hence making it simpler to notice the failure cause.&lt;/li&gt;
&lt;li&gt;Simplistic and communicative Domain-Specific Language (DSL).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is written in Groovy so you should have a fundamental knowledge of Groovy.&lt;/li&gt;
&lt;li&gt;You may find Spock framework to be a bit inconvenient but once you are familiar with it then you won’t start thinking about moving to other Java test frameworks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Is Spock One Of The Best Java Testing Frameworks For You?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes, many consider it to be the best Java testing framework and place it in the top position. Spock is the best test framework for Behaviour-Driven Development because of its powerful DSL, simplistic usage, and intuitive user interface. Particularly if you have some of the applications based on JVM. Spock is inspired by RSpec, jMock, JUnit, Mockito, Vulcans, Groovy, Scala, and other captivating life forms.&lt;/p&gt;

&lt;h3&gt;
  
  
  9. HttpUnit
&lt;/h3&gt;

&lt;p&gt;&lt;a href="http://httpunit.sourceforge.net/" rel="noopener noreferrer"&gt;HttpUnit&lt;/a&gt; is a much-used and open-source software testing framework for performing website testing without any web browser requirement. HttpUnit is extremely suited for the execution of automatic test scripts for web apps. As the name HttpUnit suggests, it can be smartly used for unit tests.&lt;/p&gt;

&lt;p&gt;However, general web layer elements such as servlets, JSP (JavaServer Pages) pages, as well as various other template elements don’t lend themselves to unit tests. Written in Java programming language, it permits test code to process returned pages as XML DOM, text, or containers of tables, links, and forms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Support for cookies&lt;/li&gt;
&lt;li&gt;Support for the HTTPS and HTTP protocols&lt;/li&gt;
&lt;li&gt;Support for HTML responses&lt;/li&gt;
&lt;li&gt;Proxy server support&lt;/li&gt;
&lt;li&gt;Superb JavaScript support&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites For Installing HttpUnit&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;System needs to support Java JDK 1.4 or the latest.&lt;/li&gt;
&lt;li&gt;Add Tidy.jar and httpunit.ja both integrated with HttpUnit, to your classpath. Also, make sure that an XML parser is previously installed.&lt;/li&gt;
&lt;li&gt;If running an older Java version, you must incorporate a JAXP-compliant XML parser in your classpath. &lt;/li&gt;
&lt;li&gt;Most recent release of HttpUnit is obtainable from this &lt;a href="https://sourceforge.net/projects/httpunit/files/" rel="noopener noreferrer"&gt;page&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;HttpUnit testing framework is beneficial in myriad ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The use of this testing framework for Java allows test automation of web apps and as a result, also aids in regression testing.&lt;/li&gt;
&lt;li&gt;One advantage of HTTPUnit is that it is much faster than other test automation frameworks like Selenium.&lt;/li&gt;
&lt;li&gt;Great JavaScript support, allows simulating the activities of the configured browser (IE or Firefox).&lt;/li&gt;
&lt;li&gt;HTTPUnit uses the Rhino JavaScript engine for the core language &amp;amp; provides the execution for the objects precise to implementation in a browser.&lt;/li&gt;
&lt;li&gt;The unit tests of popular JavaScript libraries are integrated in HtmlUnit’s own unit tests, simultaneously based on these unit tests, the libraries like jQuery 1.11.3, MochiKit 1.4.1, MooTools 1.2.1, etc. are acknowledged to function greatly with HtmlUnit.&lt;/li&gt;
&lt;li&gt;Capability to inject code into the current page by HtmlPage.executeJavascript(String yourJsCode).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It’s a good place to start for easy tests, though it will require more and more coding to create complex tests. &lt;/li&gt;
&lt;li&gt;A framework like Selenium is more specific and will allow anyone to use browser-centric behavior and not restrict the apps under test. However, with this specific framework, you will get limited support except for some major browsers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Is HttpUnit One Of The Best Java Testing Frameworks For You?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;HttpUnit is extremely easy to use and requires simple steps to get up and running. It’s great to utilize it to start simple tests, but it will require a high level of coding for creating complex tests. As compared to HTTPUnit, the framework for test automation like Selenium is more than just a library; it equips any person better for extra advanced automated testing.&lt;/p&gt;

&lt;p&gt;As for several Model-View Controller framework-based elements, these are suitable to test with other types of frameworks. For instance, WebWork 2 actions can be unit tested lacking a Web container and Struts actions can be unit tested with StrutsUnit.&lt;/p&gt;

&lt;h3&gt;
  
  
  10. JWebUnit
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://jwebunit.github.io/jwebunit/" rel="noopener noreferrer"&gt;JWebUnit&lt;/a&gt; is a Java-based test framework and is one of the JUnit extensions preferred for Integration, Regression, and Functional testing. It wraps current active frameworks like HTMLUnit and Selenium with a simple test interface. Thus you can instantly test the accuracy of your web apps.&lt;/p&gt;

&lt;p&gt;JWebUnit can be used to execute screen navigation tests. The framework also offers an advanced-level Java application programming interface to navigate a web app with a set of assertions to scrutinize the application’s accuracy. This counts navigation through links, form entrance and submission, justification of table contents, and other usual business web app traits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Top-level Java API to navigate a web application&lt;/li&gt;
&lt;li&gt;Open source java based framework&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites for Installing JWebUnit&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need to install Maven.&lt;/li&gt;
&lt;li&gt;The current stable version of JWebUnit is 3.3. It requires Java 1.7.&lt;/li&gt;
&lt;li&gt;Simply add the plugin you want as a dependency: two available plugins are, HtmlUnit for faster tests &amp;amp; great Javascript support and Webdriver: BETA quality.&lt;/li&gt;
&lt;li&gt;To manage dependencies in Eclipse when using Maven 2 make use of the m2e plugin.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JWebUnit testing framework for Integration, Regression, and Functional testing is also beneficial in myriad ways.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Used to carry out screen navigation testing.&lt;/li&gt;
&lt;li&gt;Provides a superior-level API in order to navigate the web applications.&lt;/li&gt;
&lt;li&gt;The simple navigation with readily available assertions allows quicker test creation than using JUnit or HtmlUnit. &lt;/li&gt;
&lt;li&gt;If anyone wishes to switch from HtmlUnit to other kinds of plugins like Selenium, there is no requirement to rewrite the tests.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Both TestNG as well as JWebUnit, does a similar job and features are quite similar, excluding the dependency tests capabilities.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Is JWebUnit One Of The Best Java Testing Frameworks For You?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Htmlunit is an ideal option for JavaScript support. However, JWebUnit offers app programming interfaces and it is easy to write crisp code using JWebUnit which is often impossible by HttpUnit. JWebUnit has an intuitive API, making it accessible and simple to use even if a person has merely a rough idea of the exact HTML facts of the app screens.&lt;/p&gt;

&lt;p&gt;JWebUnit works fine but sometimes adding a little BDD-flavouring to the mix can turn things for better. Behaviour-driven design or Behaviour-driven development is an incredible way to model user interaction with your app using JWebUnit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;It is almost a necessity for developers to be experts in software testing skills and have an excellent understanding of testing. This is what separates expert Java developers from novice developers. To get closer to perfection, the 10 best Java testing frameworks mentioned above are highly recommended for developers across the world. They will make it supremely easy for you to test an application.&lt;/p&gt;

&lt;p&gt;Apart from choosing the best Java testing frameworks, you must also choose the right &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=PM-24092020&amp;amp;utm_term=PM" rel="noopener noreferrer"&gt;Selenium test automation&lt;/a&gt; platform to suit your project requirement. There are countless frameworks for Java and LambdaTest supports almost all of them. Also, you get to test your website on 2000+ browsers, operating systems, and devices. Use this article as a guide to assess your requirements and pick the framework cleverly to grab the benefits of features provided by Java.&lt;/p&gt;

&lt;p&gt;Happy Testing!!&lt;/p&gt;

</description>
      <category>java</category>
      <category>testing</category>
      <category>programming</category>
      <category>bdd</category>
    </item>
    <item>
      <title>10 Biggest Remote Testing Challenges (&amp; How To Overcome Them)</title>
      <dc:creator>Abeer Mishra</dc:creator>
      <pubDate>Wed, 09 Sep 2020 08:19:05 +0000</pubDate>
      <link>https://forem.com/aboywithscar/10-biggest-remote-testing-challenges-how-to-overcome-them-3pil</link>
      <guid>https://forem.com/aboywithscar/10-biggest-remote-testing-challenges-how-to-overcome-them-3pil</guid>
      <description>&lt;p&gt;In 2019, when &lt;a href="https://www.gartner.com/en/documents/3975352/2020-future-of-work-hidden-trends-rising-demand-for-remo"&gt;Gartner&lt;/a&gt; predicted that working remotely will be on high demand, most businesses didn’t agree with the likelihood. But, guess who is working remotely now?&lt;/p&gt;

&lt;p&gt;After the COVID-19 pandemic hit the world, almost every organization was forced to allow its employees to work from home which made us realize the challenges of working remotely. Although most industries coped up with the remote working process, it was a bit intimidating for software companies. &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=PM-9092020&amp;amp;utm_term=PM"&gt;Software testing&lt;/a&gt; teams were impacted the most due to the location and synchrony constraints. The dependence on physical devices, infrastructure, and the internet makes it even more complicated for remote testing teams to execute tasks and overcome the key challenges of software testing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aPDZteAN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/09/ezgif.com-optimize.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aPDZteAN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/09/ezgif.com-optimize.gif" alt="Remote testing challenges"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;No doubt, remote testing offers the flexibility and freedom to work from home, but QA teams and the IT companies cannot overlook some key challenges of software testing. This blog will explore all the major challenges associated with remote testing and offer guidance about overcoming the challenges of working remotely. Let’s start!&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Challenges Of Remote Testing
&lt;/h2&gt;

&lt;p&gt;In the US alone, there was a significant rise of 159% in remote work between 2005 and 2017 (Source: &lt;a href="https://www.flexjobs.com/blog/post/remote-work-statistics/#:~:text=According%20to%20the%20Remote%20Work,for%20less%20than%20a%20year.%E2%80%9D"&gt;FlexJobs&lt;/a&gt;). We can imagine how drastically these numbers have gone up over the last few months. And so have the challenges of working remotely. Software testers particularly bore the brunt of the suddenness in remote work. Remote testing teams have been scrabbling hard to get back on track and we could not help but notice the key challenges of software testing. After interacting with various testers, who are working remotely, we got to know about the biggest remote testing challenges faced by them. Here they are-&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Lack of Communication
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;“You can never over-communicate enough as a leader, but at a remote company, nothing could be truer. Since you don’t physically see people in-person, information doesn’t spread in the same way. So leaders need to do the heavy lifting for evangelizing the message.”&lt;br&gt;&lt;br&gt;
— Claire Lew&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Lack of communication has turned out to be one of the significant challenges for software teams while working remotely. As per &lt;a href="https://www.forbes.com/sites/nigeldavies/2019/09/11/remote-working-fails-everyone-when-good-communication-isnt-cultural/#6b7f65731ccb"&gt;Forbes&lt;/a&gt;, it has been observed that working remotely makes it more complicated for employers to communicate, especially when it comes to having discussions that involve critical interpretations. Although individuals use effective communication tools like Slack, Teams, or Google Meetup, sometimes it becomes awkward to clarify the tone and urgency of some messages.&lt;/p&gt;

&lt;p&gt;For instance, if your colleagues are working from a different country and they use phrases to describe a problem, chances are you might not get it. That’s why it is crucial to have an effective communication environment, where employees feel comfortable and communicate concisely.&lt;/p&gt;

&lt;p&gt;In our opinion, it is recommended to use video calls while communicating with co-workers to understand things like testing requirements, test scenarios, or tools more precisely.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Teaming Up
&lt;/h3&gt;

&lt;p&gt;While working in the office, there are superiors or team leaders to see what their employees are working on. But, in a distributed testing team, there is no one to look after, and that’s where QAs find it challenging to make changes in application code. Also, your team members cannot see all the changes that you make in a test script, which makes it difficult to understand whether you’re succeeding at your job or not.&lt;/p&gt;

&lt;p&gt;This is one of the key challenges of software testing and that’s where it becomes critical to be in sync with your colleagues. You’ll have to provide continuous updates to your teammates, inform them about the issues that you’re facing, and much more.&lt;/p&gt;

&lt;p&gt;Moreover, you can also inform your team members about the features you have tested, how you have tested them, and what changes you noticed after testing a feature. It will make it easier for your co-workers to understand what you’re working on and what you have achieved so far.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Technical Failures
&lt;/h3&gt;

&lt;p&gt;Remote testing teams use a lot of technological components, such as a system with multiple applications running on it, third-party screen sharing tools, recording tools, and IM clients. But, no matter how reliable configurations your system has, things can always go wrong. For example, you never know when you run into problems with the internet connection, muddy international phone calls, software not running properly on your computer, etc.&lt;/p&gt;

&lt;p&gt;Any of these can delay your work by a considerable time, and you might not be able to get excuses to get over these issues. Thus, it is recommended to test everything a day before you start the testing process. A few things that you could check instantly involve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Screen sharing –&lt;/strong&gt; Make sure it is not interrupted throughout the testing process due to internet connection.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Recordings not working –&lt;/strong&gt; The last thing you would want after recording a testing scenario is that there is no sound in it, so make sure the recordings are working fine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Video recording –&lt;/strong&gt; Test the configuration of the recording tool and make sure it doesn’t stop or fluctuate while running multiple applications in the background.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Internet connection –&lt;/strong&gt; Most of the testing scenarios would be executed over the browser, so check the internet connectivity.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sometimes, a normal technical problem can abruptly end everything in the process, even if you have tested it over a thousand times. Well, we cannot stop technical issues from occurring, but we can prepare ourselves by planning and setting everyone’s expectations ahead of time. The only trick is to stay prepared for all the challenges of working remotely.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Cross-cultural Differences
&lt;/h3&gt;

&lt;p&gt;In most companies, remote testing teams work from different areas and countries. For instance, in my company, two testing members work from the USA, while others work from India. Now, the working culture might be similar here and there, but from where we belong does affect our behavior and understanding.&lt;/p&gt;

&lt;p&gt;Also, it’s not necessary that all your remote testing team members work in the same way as you do. There can be variations in the ways they execute a task or communicate with others. Thus, before moving on to working with a remote testing team, it is crucial to understand their working behavior and nuances.&lt;/p&gt;

&lt;p&gt;Understanding these distinctions is one of the key challenges of software testing. It will help you know the people in a better way, and your remote testing team will be able to function more efficiently.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Productive Collaboration
&lt;/h3&gt;

&lt;p&gt;When you work with a team that is distributed geographically, it becomes hard to collaborate with them continuously. Most testers need to stay in front of their laptop at varied time zones to catch up with their team members, and they end up losing a lot of time.&lt;/p&gt;

&lt;p&gt;One thing is for sure that you cannot have last-minute meetings while working remotely, especially in varied time zones. Thus, it is better to plan ahead by keeping all the time zones in mind so that every team member can join the meeting as per their convenience.&lt;/p&gt;

&lt;p&gt;Besides, you can also opt for a collaboration tool that makes it easier for team members to collaborate closely. For instance, the Screenhero feature of Slack allows two users to see the same screen at the same time. Using such tools is one of the easiest ways to overcome the key challenges of software testing.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Synchronizing Releases
&lt;/h3&gt;

&lt;p&gt;Software testers are responsible for the final release of an application, as they ensure that the application is ready to launch after testing all the components. Also, they need to give continuous updates about the release to the stakeholders as well as other team members involved in the project. But, with remote testing, it becomes a little complicated to give continuous updates about the product release.&lt;/p&gt;

&lt;p&gt;Thus, to avoid any bottlenecks in the release cycle, testers should test early, test often, and share the status with others as soon as possible. This way, you can prepare yourself for future releases in advance. Moreover, you can go with the &lt;a href="https://www.lambdatest.com/blog/guide-to-implement-qaops-framework/"&gt;QAOps principle&lt;/a&gt; of integrating and testing in parallel for the continuous delivery of products.&lt;/p&gt;

&lt;p&gt;Using agile methodologies, you will be able to execute tests early by setting smaller targets. It will also help you analyze the ability and speed of testers at which they accomplish their tasks.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Improper Documentation
&lt;/h3&gt;

&lt;p&gt;Even after working remotely for a while, many remote testing teams still believe in communicating verbally rather than keeping documentation about how the product was developed. This, in turn, can delay the release of the product.&lt;/p&gt;

&lt;p&gt;In order to release your product at the given timeline, it is recommended to use a checklist and follow along. You can create a checklist of all the tasks that need to be carried out by each member while keeping every team member in the loop with full visibility and transparency. So, when there is an issue with any task, you can update the checklist and inform everyone about it.&lt;/p&gt;

&lt;p&gt;Also, if you’re reporting a bug or issue, then specify it clearly, like where it happened and how it happened, to your team. You can also take screenshots to explain the problem in detail. &lt;a href="https://www.lambdatest.com/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=PM-9092020&amp;amp;utm_term=PM"&gt;Cross browser testing&lt;/a&gt; tools like LambdaTest allow you to take screenshots while you test web pages and applications. A special feature called Automated Screenshot Testing lets you do that for over 2000 browsers and operating systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Multitasking
&lt;/h3&gt;

&lt;p&gt;While moderating a remote testing session, testers have to keep their eyes on multiple things like communicating with the user, onscreen behavior, observing questions and queries via IM, total time remaining in the session, the status of executing the task, and much more. Keeping up with all these activities at a single time can be very confusing for any individual.&lt;/p&gt;

&lt;p&gt;Therefore, it is good to have a task management tool in hand that allows you to schedule your tasks and execute them accordingly. By doing so, you will be not only able to moderate remote sessions, but also perform other functions that are crucial for the testing. We further recommend focusing on one task at a time to overcome the most common challenges of working remotely.&lt;/p&gt;

&lt;h3&gt;
  
  
  9. Lack Of Positive Feedback
&lt;/h3&gt;

&lt;p&gt;Let us consider a scenario- When you spend a lot of time performing a test and later found out that it wasn’t supposed to happen this way. Or you’re working from a remote location with a distributed team, and there is no one to give suggestions on your ideas. Has it ever happened to you?&lt;/p&gt;

&lt;p&gt;If yes, then you might understand the importance of feedback. However, not every feedback is provided positively. Let’s say you have developed documentation for testing a specific feature, and your team leader says it looks good.&lt;br&gt;&lt;br&gt;
Later, you realize that the documentation was never published and neither put to any use, which makes you wonder what went wrong. So, you can see that the ‘good’ feedback was actually a no-feedback.&lt;/p&gt;

&lt;p&gt;To get positive feedback on your ideas, you can create a community where everyone can speak of what’s in their mind and how they can implement it effectively. If you think this is not one of the key challenges of software testing, remember what Zig Ziglar said- “&lt;em&gt;People often say motivation doesn’t last. Neither does bathing—that’s why we recommend it daily.&lt;/em&gt;”&lt;/p&gt;

&lt;h3&gt;
  
  
  10. Security &amp;amp; Privacy
&lt;/h3&gt;

&lt;p&gt;Security and privacy are two major concerns of every remote testing team, as the product is in the testing stage and yet to be released to the market. While working remotely, testers need to communicate with their colleagues and stakeholders on a daily basis to give status updates. Also, it is crucial to keep everything confidential before the product release. But, there are always risks involved in losing the internal information to outsiders.&lt;/p&gt;

&lt;p&gt;To avoid loopholes while sharing information with team members, it is recommended to use a cloud-based platform that offers password-protected sharing so that no outside user can access the information that you share with your co-workers.&lt;/p&gt;

&lt;p&gt;Remote working has become a daily activity for most businesses, especially after the outbreak of the COVID-19 pandemic. This has made it hard for remote testers to execute testing tasks, as they face many challenges of working remotely. However, most of these challenges can be resolved by using a cloud-based automated testing platform like &lt;a href="https://www.lambdatest.com/"&gt;LambdaTest&lt;/a&gt; or by following the tips below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tips To Overcome Remote Testing Challenges
&lt;/h2&gt;

&lt;p&gt;In the above section, we saw how tough it can be to manage remote testing while overcoming the key challenges of software testing. Depending on your team, product, and project requirements, the challenges of working remotely can vary greatly. The best way to ease your remote testing processes is to use automation. It allows you to ease up the pressure on the testing team while making it easier for them to find bugs. Automation can be used in multiple ways including &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=PM-9092020&amp;amp;utm_term=PM"&gt;Selenium test automation&lt;/a&gt; and much more-&lt;/p&gt;

&lt;h3&gt;
  
  
  Regression Testing
&lt;/h3&gt;

&lt;p&gt;If you choose the manual approaches, then you already know how much time it would take to execute regression testing. However, if you use automation, it can be done in the minimum time possible while improving the testing team’s productivity and providing quick feedback on the changes.&lt;/p&gt;

&lt;p&gt;Another advantage of using automation for regression testing is that the QA team can continue working on other tasks while keeping the test automation running in the background. With an automated &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=PM-9092020&amp;amp;utm_term=PM"&gt;regression testing strategy&lt;/a&gt;, the QA team doesn’t need to be available at ad-hoc times for testing the changes made by developers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Upgrade to Agile Methodologies
&lt;/h3&gt;

&lt;p&gt;Using agile methodologies is one of the best ways to test remotely; it enables you to test your website at every stage of development with minimum human intervention. Also, having a CI/CD pipeline in the process ensures that the code changes are tested immediately whenever they are integrated into the application interface.&lt;/p&gt;

&lt;p&gt;Continuous testing/integration can be executed at different stages of environments like Development, QA, Staging, and Production.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use Test-Driven Development Approach
&lt;/h3&gt;

&lt;p&gt;The test-driven development approach involves creating test scripts even before developing the feature, which means testers automate the test scripts for components that need to be developed and then integrate it into the system.&lt;/p&gt;

&lt;p&gt;However, in test-driven development, the test might fail again and again if it doesn’t meet the expected behavior of the feature. It will only pass if it starts meeting the predicted behavior of the feature. Also, with test-driven development in place, testers and developers need to work hand-in-hand for better flexibility and productivity.&lt;/p&gt;

&lt;h3&gt;
  
  
  Implement In-Sprint Test Automation
&lt;/h3&gt;

&lt;p&gt;Companies that are using Scrum in their software testing processes need to implement in-sprint test automation for quick results. In-sprint automation not only helps in keeping up with the regression testing, but it also enables testers and developers to focus on other essential tasks. With in-sprint automation, you can also get better results from continuous testing and integration.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use An Automated Testing Tool
&lt;/h3&gt;

&lt;p&gt;If you haven’t started using automation for remote testing yet, then this is the best time to look for an automation testing tool. For starters, you can begin with the open-source Selenium suite, which gives you access to four different tools for automation testing, including [Selenium Grid], WebDriver, IDE, and RC.&lt;/p&gt;

&lt;p&gt;However, &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=PM-9092020&amp;amp;utm_term=PM"&gt;Selenium&lt;/a&gt; is a tricky tool to be used by beginners; only experts having experience in automation testing can use Selenium to its maximum potential. Also, if you’re looking for a tool that is ideal for an entire testing team, then LambdaTest is your best bet.&lt;/p&gt;

&lt;p&gt;LambdaTest enables you to test your web app for multiple scenarios like responsive testing, regression testing, cross browser compatibility testing, and more. Moreover, it allows you to share testing sessions with your team members via screenshots or video recording.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;Working remotely is not a new trend; many companies have been following it already for a long time. But, it was never implemented to an entire workforce. Before the pandemic, development and testing teams were always working from offices even if other team members were working remotely. However, the pandemic has changed the whole situation; companies are now forced to give all their employees work from home. This has become a little challenging for remote testing teams and that is what we have tried to highlight in this blog. In case we have missed out on the challenges of working remotely, let us know what the key challenges of software testing are and how you overcome them.&lt;/p&gt;

&lt;p&gt;Happy testing!&lt;/p&gt;

</description>
      <category>remotetesting</category>
      <category>automationtest</category>
      <category>crossbrowsertesting</category>
      <category>selenium</category>
    </item>
    <item>
      <title>Create TestNG XML File &amp; Execute Parallel Testing</title>
      <dc:creator>Abeer Mishra</dc:creator>
      <pubDate>Fri, 21 Aug 2020 09:16:26 +0000</pubDate>
      <link>https://forem.com/aboywithscar/create-testng-xml-file-execute-parallel-testing-2a4c</link>
      <guid>https://forem.com/aboywithscar/create-testng-xml-file-execute-parallel-testing-2a4c</guid>
      <description>&lt;p&gt;In the previous article, we learned about creating a TestNG project in Eclipse and how to run our first ever Selenium Test Script. Now that you know how to run a TestNG project Eclipse, it is time to dig deeper into TestNG. So far, you’ve run only a single test script, but in practical scenarios, that simply won’t do. When it comes to Selenium test automation, running one test at a time will not be very beneficial. You will have to run multiple test cases to make the most of a Selenium Grid. In this tutorial, let’s dive deep into how we can execute multiple test files from a single file known as the &lt;a href="https://www.lambdatest.com/blog/why-selenium-grid-is-ideal-for-automated-browser-testing/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-21082020&amp;amp;utm_term=Praveen"&gt;&lt;strong&gt;TestNG XML file&lt;/strong&gt;&lt;/a&gt;. We will also see how we can create and execute a parallel testing suite using a TestNG XML file.&lt;/p&gt;

&lt;p&gt;In case you are late to the TestNG tutorial series, here’s a step-by-step guide to install TestNG in Eclipse.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s the purpose of a TestNG XML File?
&lt;/h2&gt;

&lt;p&gt;The entire point of using a TestNG framework is to run tests in parallel, i.e. run multiple tests simultaneously. In Java, you have to create test cases separately and then define the test later in the primary method. On the other hand, TestNG allows you to create multiple test cases simultaneously, and that is where the TestNG XML file comes in. A TestNG XML file eases this task, and we can write various test cases all within single or multiple classes using annotations.&lt;/p&gt;

&lt;p&gt;Uses of TestNG XML file:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Seamless parallel execution&lt;/li&gt;
&lt;li&gt;Executing multiple test cases for various Java class files&lt;/li&gt;
&lt;li&gt;Group execution of test cases &lt;/li&gt;
&lt;li&gt;Supports Parameterisation in TestNG and data-driven testing&lt;/li&gt;
&lt;li&gt;Including or excluding a particular test method&lt;/li&gt;
&lt;li&gt;Includes names of class, folders, and methods &lt;/li&gt;
&lt;li&gt;Clearer test summary with separate HTML and extent reports&lt;/li&gt;
&lt;li&gt;TestNG listeners automatically create logs&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Creating a TestNG XML File
&lt;/h2&gt;

&lt;p&gt;Now that you understand how vital a TestNG XML file is for running parallel tests in a Selenium Grid, it is time to learn how to create a TestNG XML file. Before we begin, let us go back to the first test we created using TestNG in the previous article and perform the following steps. There are two methods to create a TestNG XML file, feel free to use either of them-&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Method 1-&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Right-click on the project folder &amp;amp; towards the bottom of the list, select TestNG and then “Convert to TestNG.”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ANxhP3GK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/Convert-to-TestNG.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ANxhP3GK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/Convert-to-TestNG.png" alt="Convert to TestNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A screen like below would appear. Click on Next.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IM4_FWFx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/testng-tutorial.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IM4_FWFx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/testng-tutorial.png" alt="testng tutorial"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The next window that pops up will have the refactored source code, which would be applicable after you click Finish.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2E1JWk1d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/testng-xml.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2E1JWk1d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/testng-xml.png" alt="testng xml"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A new addition to your project directory would be displayed named as &lt;strong&gt;testng.xml&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WIfgEmmR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/lambdatest-testng.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WIfgEmmR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/lambdatest-testng.png" alt="lambdatest testng"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Double click on testng.xml to open the xml file which looks like below-&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SE59-0yx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/xml-file.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SE59-0yx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/xml-file.png" alt="xml file"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Right-click on Project, then New, and finally select File.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IN6X2fzD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/testngxml.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IN6X2fzD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/testngxml.png" alt="testngxml"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next, enter the following file name “testng.xml” and then click on Finish.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_9Aw2gEz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/unnamed-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_9Aw2gEz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/unnamed-1.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In this step, you will have to enter the XML code manually. That is how the two methods differ from each other. After entering the XML code, you can select a name for your liking suite and class.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is what a basic XML file looks like-&lt;br&gt;
&lt;/p&gt;

&lt;div class="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 name="Suite"&amp;gt;
    &amp;lt;test name="Test"&amp;gt;
         &amp;lt;classes&amp;gt;
             &amp;lt;class name="testng.TestNGTestOne"/&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;Now you can copy the above code (with your choice of names) on the TestNG XML file we’ve created above.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HIZkjwXN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/TestNG-XML-file.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HIZkjwXN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/TestNG-XML-file.png" alt="TestNG XML file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Voila! You have your very first TestNG XML file ready. That is all you have to do to create a TestNG XML file on a Selenium Grid or for Selenium test automation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running a TestNG XML File
&lt;/h2&gt;

&lt;p&gt;The hierarchy of an XML file is quite straightforward. It goes something like this- first &lt;code&gt;&amp;lt; suite &amp;gt;&lt;/code&gt; tag, second &lt;code&gt;&amp;lt; test &amp;gt;&lt;/code&gt; tag and lastly, &lt;code&gt;&amp;lt; classes &amp;gt;&lt;/code&gt; tag. As mentioned above, you can give any name to the suite and test tag, but you have to be careful while naming classes since it is a combination of the Package name and Test name.&lt;/p&gt;

&lt;p&gt;Since suite is the topmost hierarchy, this is where multiple test classes can be placed. For example, we have three test classes, one for opening Google, another for searching on Google, and one to open Gmail. All these three classes can be defined under the same test tag for execution.&lt;/p&gt;

&lt;p&gt;This example will help you understand it better.&lt;/p&gt;

&lt;p&gt;Here, I have created two Java classes- one that opens up Google &amp;amp; verifies its title and another one which again opens Google &amp;amp; searches for a string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First Class File-&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package testNG;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
public class TestNGTestOne {
    WebDriver driver;   
  @Test
  public void f() { 
      System.out.println("Start test");
    //Setting up the chrome driver exe, the second argument is the location where you have kept the driver in your system
      System.setProperty("webdriver.chrome.driver", "E:\\chromedriver.exe");
    //Setting the driver to chrome driver
      driver = new ChromeDriver();
      String url = "https://www.google.com";
      driver.get(url);
      //Capturing the title and validating if expected is equal to actual
      String expectedTitle = "Google";
      String actualTitle = driver.getTitle();
      Assert.assertEquals(actualTitle, expectedTitle);
  }
  @BeforeMethod
  public void beforeMethod() {
          System.out.println("Starting the browser session");
  }
   @AfterMethod
  public void afterMethod() {
      System.out.println("Closing the browser session");
      driver.quit();
  }
 }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Second Class File-&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package testNG;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
 public class TestNGTestTwo {
    WebDriver driver;
      @Test
      public void f() {      
              System.out.println("Start test");
            //Setting up the chrome driver exe, the second argument is the location where you have kept the driver in your system
              System.setProperty("webdriver.chrome.driver", "E:\\chromedriver.exe");
            //Setting the driver to chrome driver
              driver = new ChromeDriver();
              String url = "https://www.google.com";
              driver.get(url);
              //Searching the values on google
              WebElement txtBox = driver.findElement(By.xpath("//input[@class='gLFyf gsfi']"));
              txtBox.sendKeys("Lambda Test");
              txtBox.sendKeys(Keys.ENTER);
              }
      @BeforeMethod
      public void beforeMethod() {       
              System.out.println("Starting the browser session");
      }
      @AfterMethod
      public void afterMethod() { 
              System.out.println("Closing the browser session");
              driver.quit();
      }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next, we will create the TestNG XML file that uses both the above-defined test cases.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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 name="Test Suite"&amp;gt;
  &amp;lt;test name="Google Test"&amp;gt;
    &amp;lt;classes&amp;gt;
    &amp;lt;class name="testNG.TestNGTestOne"/&amp;gt;
    &amp;lt;class name="testNG.TestNGTestTwo"/&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;In the XML above, you can see two class names are written under the test name tag. These are the classes that I would want to run using the TestNG XML file. Also, note that I named my test “Google Test” and suite “Test Suite” respectively. Go ahead and choose any name as per your convenience for these two.&lt;/p&gt;

&lt;p&gt;The next step is to run the project using the XML file. Right-click on the testng.xml file and navigate to “Run As &amp;gt;&amp;gt; TestNG Suite.”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OTq_ZamX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/TestNG-Suite.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OTq_ZamX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/TestNG-Suite.png" alt="TestNG Suite"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By doing this, you would not have to run the classes individually; instead, we will be executing both the classes by a simple click. The output after the execution would look like below-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8NIMreos--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/pasted-image-0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8NIMreos--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/pasted-image-0.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see for yourself that the test classes mentioned in the XML ran successfully, and with it, you can now create your own test suite and run multiple tests all in one go and subsequently get the results.&lt;/p&gt;

&lt;h2&gt;
  
  
  Parallel Testing Using TestNG.XML File On Selenium Grid Cloud
&lt;/h2&gt;

&lt;p&gt;Now that you have executed your TestNG.xml file successfully. It is pivotal to note the changes you need to make into the TestNG.xml for Selenium test automation over a cloud-based Grid. Because at the end of the day you want a more practical approach and configuring hundreds of browsers and operating systems in your nodes doesn’t look feasible enough.&lt;/p&gt;

&lt;p&gt;You can leverage a cloud Selenium Grid such as LambdaTest which provides 2000+ real browsers and operating systems online. That way, you only need to focus on writing better Selenium automation scripts.&lt;/p&gt;

&lt;p&gt;So let me show you how you can leverage testng.xml to run parallel testing with Selenium on LambdaTest.&lt;/p&gt;

&lt;p&gt;We will take a sample to-do application for the demo. The Selenium testing script will go to the Sample to-do application and click on the checkboxes to indicate the items are done and will add them to the list. After adding it would verify if the items are added.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xUmYDBcB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/TestNG-4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xUmYDBcB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/TestNG-4.png" alt="TestNG 4"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let us have a look at our Java test file.&lt;br&gt;
&lt;/p&gt;

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

//TestNG Todo : Sample App
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 TestNGToDo {
  public String username = "examplelambdatest";
  public String accesskey = "1234abcd9876";
  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", "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());
      }
  }

  @Test
  public void testSimple() throws Exception {
     try {
            //Change it to production page
          driver.get("https://lambdatest.github.io/sample-todo-app/");

            //Let's mark done first two items in the list.
            driver.findElement(By.name("li1")).click();
          driver.findElement(By.name("li2")).click();

           // Let's add an item in the list.
            driver.findElement(By.id("sampletodotext")).sendKeys("Yey, Let's add it to list");
          driver.findElement(By.id("addbutton")).click();

            // Let's check whether the items we added are in the list.
          String enteredText = driver.findElementByXPath("/html/body/div/div/div/ul/li[6]/span").getText();
          if (enteredText.equals("Yey, Let's add it to list")) {
              status = true;
          }
      } 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;To make your Selenium test script run over LambdaTest &lt;a href="https://www.lambdatest.com/blog/why-selenium-grid-is-ideal-for-automated-browser-testing/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-21082020&amp;amp;utm_term=Praveen"&gt;Selenium Grid&lt;/a&gt;, you will need to declare a few changes to the script. This would involve specifying your LambdaTest username, your LambdaTest access key and the HubURL in the remote webdriver, for routing your test script to LambdaTest Selenium Grid.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;All of these details can be found on your LambdaTest automation dashboard.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6q78c73R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/LambdaTest-automation-dashboard.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6q78c73R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/LambdaTest-automation-dashboard.png" alt="LambdaTest automation dashboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By far I am sure you’ve realized the importance of using TestNG.xml for running scripts on cloud Selenium Grid. It is simple really, you don’t want to write down hundreds of test files to test the same scenario over hundreds of browser drivers. Which is why you will need a TestNG.xml file which will allow you to run a single test file over numerous combinations of parameters and values specified in it.&lt;/p&gt;

&lt;p&gt;For this purpose, you invoked the Parameters annotations in TestNG. – @org.testng.annotations.Parameters(value={“browser”,”version”,”platform”})&lt;/p&gt;

&lt;p&gt;Now you need to provide values to these parameters in your testng.xml file. Then you will be able to run a single test across several browsers, simultaneously.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//TestNG.xml
&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="LambaTestSuite" parallel="tests"&amp;gt;

  &amp;lt;test name="WIN8TEST"&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.TestNGToDo"/&amp;gt;
    &amp;lt;/classes&amp;gt;
  &amp;lt;/test&amp;gt; &amp;lt;!-- Test --&amp;gt;

  &amp;lt;test name="WIN10TEST"&amp;gt;
  &amp;lt;parameter name="browser" value="chrome"/&amp;gt;
  &amp;lt;parameter name="version" value="79.0"/&amp;gt;
  &amp;lt;parameter name="platform" value="WIN10"/&amp;gt;
    &amp;lt;classes&amp;gt;
      &amp;lt;class name="LambdaTest.TestNGToDo"/&amp;gt;
    &amp;lt;/classes&amp;gt;
  &amp;lt;/test&amp;gt; &amp;lt;!-- Test --&amp;gt;
  &amp;lt;test name="MACTEST"&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 10.13"/&amp;gt;
    &amp;lt;classes&amp;gt;
      &amp;lt;class name="LambdaTest.TestNGToDo"/&amp;gt;
    &amp;lt;/classes&amp;gt;
  &amp;lt;/test&amp;gt; &amp;lt;!-- Test --&amp;gt;

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



&lt;p&gt;If you go to your LambdaTest platform now. You will notice that the same test has been triggered over multiple browsers + operating systems combinations. Just as we specified in our TestNG.xml file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DPT1g67V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/Selenium-test-automation.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DPT1g67V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/08/Selenium-test-automation.png" alt="Selenium test automation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the reason why Parallel testing is one of the most in-demand features of &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-21082020&amp;amp;utm_term=Praveen"&gt;Selenium test automation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A Selenium Grid would really boost up your test build practices. Instead of creating new test cases for individual environments, you can leverage testng.xml to define those environments as parameters and simply run a test on various parameters.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Why break your back when you can run parallel tests on a Selenium Grid cloud?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;LambdaTest provides a cloud Selenium Grid where you can run your Selenium test scripts over 2000+ real browsers in parallel.&lt;/p&gt;

&lt;p&gt;In our upcoming posts, we will learn about TestNG reports and how we can use the different types provided by the framework. Stay tuned and Happy TestNG! 😉&lt;/p&gt;

</description>
      <category>testng</category>
      <category>paralleltesting</category>
      <category>xml</category>
      <category>java</category>
    </item>
    <item>
      <title>Create TestNG Project In Eclipse &amp; Run Selenium Test Script</title>
      <dc:creator>Abeer Mishra</dc:creator>
      <pubDate>Tue, 11 Aug 2020 09:30:46 +0000</pubDate>
      <link>https://forem.com/aboywithscar/create-testng-project-in-eclipse-run-selenium-test-script-7pn</link>
      <guid>https://forem.com/aboywithscar/create-testng-project-in-eclipse-run-selenium-test-script-7pn</guid>
      <description>&lt;p&gt;In the last article, we &lt;a href="https://www.lambdatest.com/blog/how-to-install-testng-in-eclipse-step-by-step-guide/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-11082020&amp;amp;utm_term=Praveen"&gt;installed TestNG in Eclipse&lt;/a&gt; and did some environment set up for the same. Subsequently, we saw how we could convert our existing Java projects into TestNG projects in Eclipse. In this article, we will create a TestNG project from scratch and write our very first test script using TestNG. We will begin by setting up a TestNG project first and then move on to writing the scripts.&lt;/p&gt;

&lt;p&gt;Before getting started, we will quickly list down the prerequisites for getting started with a TestNG project, so that you can continue without any hiccups. Here’s what you need to have installed in your system-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.eclipse.org/downloads/"&gt;Eclipse&lt;/a&gt; IDE&lt;/li&gt;
&lt;li&gt;Download &lt;a href="https://www.selenium.dev/downloads/"&gt;Selenium WebDriver and Client&lt;/a&gt; for Java. – Visit the official website and hit the download button for Java file. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fhd0IEBf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/testng-project.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fhd0IEBf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/testng-project.png" alt="testng-project"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Download and extract these Selenium bindings. We will be using these to add External JAR files later in this Selenium TestNG tutorial.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create TestNG Project In Eclipse
&lt;/h2&gt;

&lt;p&gt;First of all, you will need to launch Eclipse and then follow the steps below to create a new TestNG project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Navigate to File &amp;gt; New &amp;gt; Java Project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m-m8dAMq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/Java-Project.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m-m8dAMq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/Java-Project.png" alt="Java Project"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Give your project a name for example, ‘ &lt;strong&gt;LambdaTestNG&lt;/strong&gt; ’ and click on Next.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OP4fDeqN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/LambdaTestNG.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OP4fDeqN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/LambdaTestNG.png" alt="LambdaTestNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; On the next screen, you will see the Java settings for your new project. To make it a TestNG project just navigate to the &lt;strong&gt;Libraries&lt;/strong&gt; tab and click on the &lt;strong&gt;Add Library&lt;/strong&gt; button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H6l4pyAX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/TestNG1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H6l4pyAX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/TestNG1.png" alt="TestNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Choose &lt;strong&gt;TestNG&lt;/strong&gt; from the list of libraries and click &lt;strong&gt;Next&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wuwiJYOl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/run-testng-project.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wuwiJYOl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/run-testng-project.png" alt="run-testng-project"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Now, you will see TestNG added to your project libraries. Click on &lt;strong&gt;Finish&lt;/strong&gt; and you are all set with your testNG project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BGNzs2W_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/project-libraries.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BGNzs2W_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/project-libraries.png" alt="project libraries"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your Java project has been created successfully and you will be able to see it by clicking on the Package Explorer button on the left panel.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gjbaRS7Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/pasted-image-0-4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gjbaRS7Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/pasted-image-0-4.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding Selenium JAR files To Selenium TestNG Project
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Next, you need to add the &lt;strong&gt;Selenium API JAR&lt;/strong&gt; files to your TestNG project “LambdaTestNG”. Right-click on the Project and then hit the &lt;strong&gt;Properties&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aKc2o3Rd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/Selenium-API-JAR.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aKc2o3Rd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/Selenium-API-JAR.png" alt="Selenium API JAR"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Now, you need to perform JAR selection from the Selenium Java language bindings which you downloaded in your systems. Navigate or choose the path where you have downloaded the Selenium Java language bindings. Add all the JAR files (even the ones inside the libs folder).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gcCqXtw4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/Selenium-Java-language.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gcCqXtw4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/Selenium-Java-language.png" alt="Selenium Java language"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; After adding all JAR files, hit the button to &lt;strong&gt;Apply and Close&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SjFi82BQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/Apply-and-Close.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SjFi82BQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/Apply-and-Close.png" alt="Apply and Close"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Awesome, now you will notice a folder for Referenced Libraries in the project &lt;strong&gt;LambdaTestNG&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2s78bsue--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/unnamed.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2s78bsue--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/unnamed.png" alt="LambdaTestNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With these steps, your java project is now all set to execute TestNG, the only thing you will have to do is import the Selenium libraries and browser driver(make sure to use the driver compatible with your system browser version) to run Selenium code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a TestNG class in Eclipse
&lt;/h2&gt;

&lt;p&gt;Creating a TestNG class is as easy as creating a Java class. All you need to do is follow the steps mentioned below and have your first testNG class ready.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Navigate to src from the project folder and right-click the same. You will see TestNG as an option in the dropdown towards the bottom. Click on it and you will now see two sub-options to either create a TestNG class or convert the class to TestNG. As we are creating a new TestNG class, you need to select the first option.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ats8ITrA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/TestNG-class-in-Eclipse.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ats8ITrA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/TestNG-class-in-Eclipse.png" alt="TestNG class in Eclipse"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Generally, the source folder name is auto-filled but if it is not, you can simply browse through the same. Next, you can give any name to your class, for example, ‘ &lt;strong&gt;TestNGTestOne&lt;/strong&gt; ’ and its package. For now, we will keep the basic annotations selected &lt;strong&gt;@BeforeMethod&lt;/strong&gt; and &lt;strong&gt;@AfterMethod&lt;/strong&gt;. However, Annotations can be configured at a later stage as well depending upon your test scenario. If you wish to configure them now, you can refer to the TestNG annotations tutorial.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--W3GZfHh8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/TestNGTestOne.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--W3GZfHh8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/TestNGTestOne.png" alt="TestNGTestOne"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; You will now see a class( &lt;strong&gt;TestNGTestOne.java&lt;/strong&gt; ) in your project directory with default methods, viz f(), as well as beforeMethod() and afterMethod() that you can see were checked in the screenshot above.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cX4YAlFN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/TestNGTestOnejava.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cX4YAlFN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/TestNGTestOnejava.png" alt="TestNGTestOnejava"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You are now all set to write code in your first TestNG class, but before doing so let me quickly brief you about the TestNG annotations that we can see in the class we just created.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a class="comment-mentioned-user" href="https://dev.to/test"&gt;@test&lt;/a&gt;
 annotation implies that the method is a test method and any code written under it constitutes to be a test case.&lt;/li&gt;
&lt;li&gt;@BeforeMethod implies that the method beneath should be running before the test method.&lt;/li&gt;
&lt;li&gt;@AfterMethod, just as the name suggests implies that the method should run after the test method.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we will write our first script using Selenium and TestNG.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing Our First Test Case Using Selenium and TestNG
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Test Scenario:&lt;/strong&gt; We will write a simple test script wherein we will just open up a browser, navigate to Google, verify the title, and then quit the browser session. You will see the utility of the @BeforeMethod and @AfterMethod annotations as well.&lt;/p&gt;

&lt;p&gt;Here is the java test file “ &lt;strong&gt;TestNGTestOne.java&lt;/strong&gt; ”.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package testNG;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;

public class TestNGTestOne {

    WebDriver driver;

  @Test
  public void f() {
    //Setting up the chrome driver exe, the second argument is the location where you have kept the driver in your system
      System.setProperty("webdriver.chrome.driver", "E:\\Softwares\\chromedriver.exe");

    //Setting the driver to chrome driver
      driver = new ChromeDriver();
      String url = "https://www.google.com";
      driver.get(url);
      //Capturing the title and validating if expected is equal to actual
      String expectedTitle = "Google";
      String actualTitle = driver.getTitle();
      Assert.assertEquals(actualTitle, expectedTitle);
    }
  @BeforeMethod
  public void beforeMethod() {
      System.out.println("Starting the browser session");
  }

  @AfterMethod
  public void afterMethod() {
      System.out.println("Closing the browser session");
      driver.quit();
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Running Selenium TestNG Script
&lt;/h3&gt;

&lt;p&gt;Right-click on the test script and navigate to &lt;strong&gt;Run As &amp;gt;&amp;gt; TestNG Test&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--20A1hKBw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/TestNG-Script.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--20A1hKBw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/TestNG-Script.png" alt="TestNG Script"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After running the test script, as shown above, you can verify the results of the test. This can be seen either on the TestNG reports or the console itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  TestNG Reports and Results
&lt;/h2&gt;

&lt;p&gt;As we mentioned above, once you have executed the test shown above you will be able to see its corresponding results either in the Eclipse Console or under TestNG reports under the test-output folder that gets created automatically as soon as you run your first test in the project directory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Results through Console&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You have two options to view your results via the eclipse console which are displayed as two tabs viz, Console and Results of running class &lt;code&gt;&amp;lt; your class name &amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Console–&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j5Y-yQv4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/TestNG-Reports.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j5Y-yQv4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/TestNG-Reports.png" alt="TestNG Reports"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TestNG Results–&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CdJ9Ii3v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/TestNG-Results.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CdJ9Ii3v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/TestNG-Results.png" alt="TestNG Results"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Results through TestNG Reports&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;TestNG offers a rich space for detailed reports of your test scripts that are visible under the test-output folder. We shall discuss briefly it as it is a huge topic altogether. These reports can be seen here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hgABr6bI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/TestNG-Reports-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hgABr6bI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2020/07/TestNG-Reports-1.png" alt="TestNG Reports"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see there are a number of different reports that can be seen and used for subsequent reporting. We shall discuss more about these reports in our upcoming posts. For now, you can go back to any website you like and practice creating a basic test script using the TestNG framework &amp;amp; cover up the basics as shown in this article. In the next post, we will jump on to understand more about the TestNG XML file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus Pointer: Use A Cloud Selenium Grid For Parallel Testing
&lt;/h2&gt;

&lt;p&gt;Kudos on creating the TestNG project in Eclipse and running the Selenium TestNG script. Right now you have triggered the Selenium TestNG script using a &lt;strong&gt;Selenium WebDriver&lt;/strong&gt; in your own machine but that isn’t a scalable approach. It’s okay if you’re a novice at Selenium testing. However, after some time your test suites are bound to get bigger as you may have to run automated browser testing over dozens or maybe hundreds of browsers + OS combinations.&lt;/p&gt;

&lt;p&gt;Doing so with Selenium WebDriver can consume a lot of time and effort because the tests will be queued and executed one after another.&lt;/p&gt;

&lt;p&gt;This is where you can leverage a &lt;strong&gt;Selenium Grid&lt;/strong&gt; which can allow you to run these test cases in parallel. So read this &lt;a href="https://www.lambdatest.com/blog/selenium-grid-setup-tutorial/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-11082020&amp;amp;utm_term=Praveen"&gt;Selenium Grid tutorial&lt;/a&gt; and fasttrack your Selenium testing experience like a pro!&lt;/p&gt;

&lt;p&gt;If you’re already familiar with Selenium Grid and have it set up in your system, even then there are going to be scale issues. You will need to expand the Selenium Grid with new devices and browsers that would be launched in the market. And that would require a lot of investment in hardware and maintenance of your local Selenium Grid. Which is why it is recommended to use a cloud Selenium Grid like LambdaTest.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zb_-7UCQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2019/07/pasted-image-0-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zb_-7UCQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.lambdatest.com/blog/wp-content/uploads/2019/07/pasted-image-0-1.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LambdaTest will help you trigger your Selenium test cases over 2000+ real browsers and operating systems. That way, you won’t even have to worry about which browsers are new in the market or maintaining your in-house Selenium infrastructure so you could focus on writing better Selenium testing scripts.&lt;/p&gt;

&lt;p&gt;In order to run your same script on LambdaTest Selenium Grid, you will need to sign up with LambdaTest(Its FREE) and do a couple of changes to your project setup. Run your &lt;a href="https://www.lambdatest.com/support/docs/testng-with-selenium-running-java-automation-scripts-on-lambdatest-selenium-grid/?utm_source=dev&amp;amp;utm_medium=Blog&amp;amp;utm_campaign=Praveen-11082020&amp;amp;utm_term=Praveen"&gt;TestNG scripts on Selenium Grid Cloud&lt;/a&gt;. Happy Testing!&lt;/p&gt;

</description>
      <category>testng</category>
      <category>selenium</category>
      <category>java</category>
      <category>eclipse</category>
    </item>
  </channel>
</rss>
