<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bonnie</title>
    <description>The latest articles on DEV Community by Bonnie (@bonnie4554).</description>
    <link>https://dev.to/bonnie4554</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%2F994678%2F90935f15-3312-42b5-baa8-685ec46ae12d.png</url>
      <title>DEV Community: Bonnie</title>
      <link>https://dev.to/bonnie4554</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bonnie4554"/>
    <language>en</language>
    <item>
      <title>How to Use Node.js Test Runner: A Detailed Guide</title>
      <dc:creator>Bonnie</dc:creator>
      <pubDate>Fri, 17 Jan 2025 09:00:36 +0000</pubDate>
      <link>https://dev.to/bonnie4554/how-to-use-nodejs-test-runner-a-detailed-guide-824</link>
      <guid>https://dev.to/bonnie4554/how-to-use-nodejs-test-runner-a-detailed-guide-824</guid>
      <description>&lt;p&gt;The JavaScript test runner or Node.js test runner helps automate the testing process for websites and web applications by enabling a range of testing techniques, including unit, integration, and end-to-end testing.&lt;/p&gt;

&lt;p&gt;The Node.js test runner automates running tests and offers feedback on the results to help identify and resolve bugs during the stages of software development effectively.&lt;/p&gt;

&lt;p&gt;In this blog, we look at how to leverage Node.js test runner for automated testing while exploring methods such as mocking and parallel testing alongside test hooks.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Node.js Test Runner?
&lt;/h2&gt;

&lt;p&gt;Programming languages like Python, Ruby, and Go had a built-in test runner, but JavaScript did not have one. All test runners in the JavaScript ecosystem, such as Mocha, Jest, and Jasmine, were built as third-party packages.&lt;/p&gt;

&lt;p&gt;All this changed when Node.js released an experimental built-in test runner in Node.js version 18 and made the test runner stable in Node.js version 20.&lt;/p&gt;

&lt;p&gt;The test runner offers several features, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Assertion library&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test hooks&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mocking functionality&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Code coverage&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test reporters&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Asynchronous testing&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why Use Node.js Test Runner?
&lt;/h2&gt;

&lt;p&gt;The native test runner in Node.js provides several advantages for &lt;a href="https://www.lambdatest.com/learning-hub/javascript-automation-testing" rel="noopener noreferrer"&gt;JavaScript automation testing&lt;/a&gt;. Outlined below are some of the benefits of utilizing this test runner:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The test runner streamlines the testing process for developers and testers by saving time in deciding which tool to use, as it is integrated within Node.js itself.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The built-in assertion library in the Node.js test runner simplifies the process of writing tests and obtaining test results without the need to install other assertion libraries.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The test runner includes a feature for code coverage to make sure that all sections of the code are tested by pinpointing the parts that have not been tested yet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The native test runner has a feature called watch mode that allows it to monitor changes in test files and their dependencies. If any changes are detected, the test runner will automatically rerun the tests affected by the modification.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Testing using Node.js enables the use of mocks, stubs, and spies that are important for testing individual components in isolation from the entire software.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to Get Started With Node.js Test Runner?
&lt;/h2&gt;

&lt;p&gt;In this part of the blog post, you will learn how to start using the Node.js built-in test runner and run your testing script successfully.&lt;/p&gt;

&lt;p&gt;To get started, follow these instructions;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Make sure to use Node.js version 20 or above because the test runner has been completely integrated into the core of Node.js since the release of version 20.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a TestRunner directory and launch it using your Integrated Development Environment (IDE). For instance, in this scenario, we have used VS Code.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Run the following command in the terminal to set up a Node.js project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create two new folders named src and tests in the TestRunner directory.&lt;/p&gt;

&lt;p&gt;Update the test script in your package.json file with the following code snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    "scripts": {
        "test": "node --test TestRunner/tests/"
      },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install Selenium WebDriver by running the command below:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;

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

&lt;p&gt;Run the below-given command to install ChromeDriver:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
    npm install chromedriver&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Create a new started.test.js file in the tests folder. Then, add the following code to the file:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
    const { Builder, By, Key, until } = require("selenium-webdriver");&lt;br&gt;
    const assert = require("assert").strict;&lt;br&gt;
    const { test } = require("node:test");&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  let driver;


  test("Setup WebDriver for Google Search Test Suite", async (t) =&amp;gt; {
    driver = await new Builder().forBrowser("chrome").build();
  });


  test("Navigate to Google and verify title", async (t) =&amp;gt; {
    await driver.get("http://www.google.com");
    const title = await driver.getTitle();
    assert.strictEqual(title, "Google");
  });


  test("Cleanup after Google Search Test Suite", async (t) =&amp;gt; {
    await driver.quit();
  });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;The above code imports the required functions from &lt;em&gt;node:test&lt;/em&gt; and &lt;em&gt;node:assert&lt;/em&gt; and describes a simple test that navigates to Google and verifies the title.&lt;/p&gt;

&lt;p&gt;Run the below-given command to execute the test:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
    node tests/started.test.js&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using describe() and it() Blocks
&lt;/h2&gt;

&lt;p&gt;In Node.js test runner, you can use &lt;em&gt;describe()&lt;/em&gt; and &lt;em&gt;it()&lt;/em&gt; blocks to run tests. The &lt;em&gt;describe()&lt;/em&gt; block is used to declare a suite that organizes and groups related tests together, while the &lt;em&gt;it()&lt;/em&gt; block is used to declare a test.&lt;/p&gt;

&lt;p&gt;The benefit of using &lt;em&gt;describe()/it()&lt;/em&gt; blocks is that it provides a way to organize your tests into blocks of related functionality or features. This is useful for larger test suites, where you want to keep tests neatly organized and logically grouped.&lt;/p&gt;

&lt;p&gt;Inside a &lt;em&gt;describe()&lt;/em&gt; block, you can have multiple &lt;em&gt;test()&lt;/em&gt; or &lt;em&gt;it()&lt;/em&gt; blocks that define specific test cases. You can also nest &lt;em&gt;describe()&lt;/em&gt; blocks within each other to create sub-groups of tests for more detailed organization.&lt;/p&gt;

&lt;p&gt;You can write tests using &lt;em&gt;describe()&lt;/em&gt; and &lt;em&gt;it()&lt;/em&gt; blocks, as shown below.&lt;/p&gt;

&lt;p&gt;Create a describeit.test.js file within the tests directory and insert the provided code snippet below:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
    describe("Form Input Test", async () =&amp;gt; {&lt;br&gt;
      let driver;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  await it("Setup WebDriver", async () =&amp;gt; {
    driver = await new Builder().forBrowser("chrome").build();
  });


  await it("should input values in a form and check their sum", async () =&amp;gt; {
    await driver.get("https://www.lambdatest.com/selenium-playground/simple-form-demo");


    await driver.findElement(By.id("sum1")).sendKeys(2);
    await driver.findElement(By.id("sum2")).sendKeys(3);
    await driver.findElement(By.xpath("//button[normalize-space()='Get Sum']")).click();


    let sum = await driver.wait(until.elementLocated(By.id("addmessage")),10000);
    let sumNo = await sum.getText();
    assert.strictEqual(sumNo, "5");
  });


  await it("Cleanup: Close the browser", async () =&amp;gt; {
    await driver.quit();
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Run the below-given command to execute the test:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
    node tests/describeit.test.js&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Skipping Tests
&lt;/h2&gt;

&lt;p&gt;The Node.js test runner also allows you to skip tests. You can skip tests if they are flaky, the feature being tested is under active development, the test is dependent on unavailable external dependencies, or tests are on deprecated features.&lt;/p&gt;

&lt;p&gt;Individual tests can be skipped by passing the skip option to the test or by calling the test context’s &lt;em&gt;skip()&lt;/em&gt; annotation. Annotations to avoid running the test in the built-in test runner consist of indicators, like &lt;em&gt;skip:true&lt;/em&gt;, &lt;em&gt;skip;’This test is skipped’&lt;/em&gt;, &lt;em&gt;t.skip()&lt;/em&gt;, and &lt;em&gt;t.skip(“This test is skipped”)&lt;/em&gt; as illustrated in this example.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a skipping.test.js file within the tests directory and insert the provided code snippet below.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
    describe("Expected Values To Be Strictly Equal", async () =&amp;gt; {&lt;br&gt;
      let driver;&lt;br&gt;
      driver = await new Builder().forBrowser("chrome").build();&lt;br&gt;
      it("should be strictly equal", async () =&amp;gt; {&lt;br&gt;
        await driver.get("&lt;a href="http://www.google.com%22" rel="noopener noreferrer"&gt;http://www.google.com"&lt;/a&gt;);&lt;br&gt;
        const title = await driver.getTitle();&lt;br&gt;
        assert.strictEqual(title, "Google");&lt;br&gt;
      });&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  it("skip test option", { skip: true }, async (t) =&amp;gt; {
    await driver.get("http://www.google.com");
    const title = await driver.getTitle();
    assert.strictEqual(title, "Google");
  });


  it(
    "skip test option with message",
    { skip: "This test is skipped" },
    async (t) =&amp;gt; {
      await driver.get("http://www.google.com");
      const title = await driver.getTitle();
      assert.strictEqual(title, "Google");
    }
  );


  it("Calling skip() method", async (t) =&amp;gt; {
    await driver.get("http://www.google.com");
    const title = await driver.getTitle();
    assert.strictEqual(title, "Google");
    t.skip();
  });


  it("Calling skip() method with message", async (t) =&amp;gt; {
    await driver.get("http://www.google.com");
    const title = await driver.getTitle();
    assert.strictEqual(title, "Google");
    t.skip("This test is skipped");
  });


  await it("Cleanup: Close the browser", async () =&amp;gt; {
    await driver.quit();
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run the below-given command to execute the test:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
    node tests/skipping.test.js&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Test Hooks
&lt;/h2&gt;

&lt;p&gt;The Node.js test runner provides different test hooks. Hooks are functions that run immediately before or immediately after a test. The hooks available in the Node.js test runner are &lt;em&gt;before()&lt;/em&gt;, &lt;em&gt;beforeEach()&lt;/em&gt;, &lt;em&gt;after()&lt;/em&gt;, and &lt;em&gt;afterEach()&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Here are some examples of how to use these hooks:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;**before() *Hook&lt;/em&gt;*&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;before()&lt;/em&gt; hook is used to prepare the testing environment where it runs once before all the tests in a &lt;em&gt;describe&lt;/em&gt; block. For example, you can use the &lt;em&gt;before()&lt;/em&gt; hook to set up the WebDriver before all your tests are executed.&lt;/p&gt;

&lt;p&gt;Below is how to use the &lt;em&gt;before()&lt;/em&gt; hook:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a beforehook.test.js file within the tests directory and insert the provided code snippet below:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
    describe("Simple Form Demo Title Test", async () =&amp;gt; {&lt;br&gt;
      let driver;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  before(async () =&amp;gt; {
    driver = await new Builder().forBrowser("chrome").build();
  });


  await it("should Navigate to Simple Form Demo and verify title", async () =&amp;gt; {
    await driver.get("http://www.lambdatest.com/selenium-playground/simple-form-demo");
    const title = await driver.getTitle();
    assert.strictEqual(title, "Selenium Grid Online | Run Selenium Test On Cloud");
  });


  await it("Cleanup: Close the browser", async () =&amp;gt; {
    await driver.quit();
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run the below-given command to execute the test:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
    node tests/beforehook.test.js&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;**beforeEach() *Hook&lt;/em&gt;*&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;beforeEach()&lt;/em&gt; hook runs once before each test, where it is used to isolate tests so they do not affect each other. For example, if you have to visit a specific page URL for a couple of tests, you can use a &lt;em&gt;beforeEach()&lt;/em&gt; hook to open the URL page before each test is executed.&lt;/p&gt;

&lt;p&gt;Below is how to use the &lt;em&gt;beforeEach()&lt;/em&gt; hook:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a beforeEachhook.test.js file within the tests directory and insert the provided code snippet below:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
    describe("Simple Form Demo Test", async () =&amp;gt; {&lt;br&gt;
      let driver;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  before(async () =&amp;gt; {
    driver = await new Builder().forBrowser("chrome").build();
  });


  beforeEach(async () =&amp;gt; {
    await driver.get("https://www.lambdatest.com/selenium-playground/simple-form-demo");
  });


  await it("should Navigate to Simple Form Demo and verify title", async () =&amp;gt; {
    const title = await driver.getTitle();
    assert.strictEqual(title,"Selenium Grid Online | Run Selenium Test On Cloud");
  });


  await it("Should add values to simple form input fields and check their sum", async () =&amp;gt; {
    await driver.findElement(By.id("sum1")).sendKeys(2);
    await driver.findElement(By.id("sum2")).sendKeys(3);
    await driver.findElement(By.xpath("//button[normalize-space()='Get Sum']")).click();


    let sum = await driver.wait(until.elementLocated(By.id("addmessage")),10000);
    let sumNo = await sum.getText();
    assert.strictEqual(sumNo, "5");
  });


  await it("Cleanup: Close the browser", async () =&amp;gt; {
    await driver.quit();
  });
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run the below-given command to execute the test:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
    node tests/beforeEachhook.test.js&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;**after() *Hook&lt;/em&gt;*&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;after()&lt;/em&gt; hook runs once after the execution of all the tests where it is used to perform cleanup actions after all the tests are executed. For example, if you want to close the WebDriver after the tests have been executed, you can use the &lt;em&gt;after()&lt;/em&gt; hook.&lt;/p&gt;

&lt;p&gt;Below is how to use the &lt;em&gt;after()&lt;/em&gt; hook:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a afterhook.test.js file within the tests directory and insert the provided code snippet below:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
    describe("Simple Form Demo Test", async () =&amp;gt; {&lt;br&gt;
      let driver;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  before(async () =&amp;gt; {
    driver = await new Builder().forBrowser("chrome").build();
  });


  beforeEach(async () =&amp;gt; {
    await driver.get(
      "https://www.lambdatest.com/selenium-playground/simple-form-demo"
    );
  });


  await it("should Navigate to Simple Form Demo and verify title", async () =&amp;gt; {
    const title = await driver.getTitle();
    assert.strictEqual(
      title,
      "Selenium Grid Online | Run Selenium Test On Cloud"
    );
  });


  await it("Should add values to simple form input fields and check their sum", async () =&amp;gt; {
    await driver.findElement(By.id("sum1")).sendKeys(2);
    await driver.findElement(By.id("sum2")).sendKeys(3);
    await driver
      .findElement(By.xpath("//button[normalize-space()='Get Sum']"))
      .click();


    let sum = await driver.wait(
      until.elementLocated(By.id("addmessage")),
      10000
    );
    let sumNo = await sum.getText();
    assert.strictEqual(sumNo, "5");
  });


  after(async () =&amp;gt; {
    await driver.quit();
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run the below-given command to execute the test:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
    node tests/afterhook.test.js&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;**afterEach() *Hook&lt;/em&gt;*&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;afterEach()&lt;/em&gt; hook is run once after each test. It is used to perform cleanup actions after each test. For example, if you want to clear cookies after each test, you can use an &lt;em&gt;afterEach()&lt;/em&gt; hook.&lt;/p&gt;

&lt;p&gt;Create a afterEachhook.test.js file within the tests directory and insert the provided code snippet below:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
    const { Builder, By, Key, until } = require("selenium-webdriver");&lt;br&gt;
    const assert = require("assert").strict;&lt;br&gt;
    const {&lt;br&gt;
      describe,&lt;br&gt;
      it,&lt;br&gt;
      before,&lt;br&gt;
      beforeEach,&lt;br&gt;
      after,&lt;br&gt;
      afterEach,&lt;br&gt;
    } = require("node:test");&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;describe("Simple Form Demo Test", async () =&amp;gt; {
  let driver;


  before(async () =&amp;gt; {
    driver = await new Builder().forBrowser("chrome").build();
  });


  beforeEach(async () =&amp;gt; {
    await driver.get(
      "https://www.lambdatest.com/selenium-playground/simple-form-demo"
    );
  });


  await it("should Navigate to Simple Form Demo and verify title", async () =&amp;gt; {
    const title = await driver.getTitle();
    assert.strictEqual(
      title,
      "Selenium Grid Online | Run Selenium Test On Cloud"
    );
  });


  await it("Should add values to simple form input fields and check their sum", async () =&amp;gt; {
    await driver.findElement(By.id("sum1")).sendKeys(2);
    await driver.findElement(By.id("sum2")).sendKeys(3);
    await driver
      .findElement(By.xpath("//button[normalize-space()='Get Sum']"))
      .click();


    let sum = await driver.wait(
      until.elementLocated(By.id("addmessage")),
      10000
    );
    let sumNo = await sum.getText();
    assert.strictEqual(sumNo, "5");
  });


  afterEach(function () {
    driver.manage().deleteAllCookies();
  });


  after(async () =&amp;gt; {
    await driver.quit();
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Run the below-given command to execute the test:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
    node tests/afterEachhook.test.js&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing Mocks
&lt;/h2&gt;

&lt;p&gt;The built-in mocking functionality of the Node.js test runner enables you to mock and substitute functions during testing situations where external dependencies or third-party packages are being used. It is particularly handy when those dependencies are still in the development phase.&lt;/p&gt;

&lt;p&gt;You can use mocking functionality to create spies and stubs. Below is an example that illustrates using mocking functionalities to validate fetching data from an API:&lt;/p&gt;

&lt;p&gt;First, install axios, a promise-based HTTP client for the browser and Node.js, using the below-given command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
    npm install axios&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then, create an index.js file and add the following code:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
    const axios = require("axios");&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MakeRequest {
  constructor() {}
  static async fetchDataFromAPI(id) {
    const { data: todo } = await axios.get(
      "https://jsonplaceholder.typicode.com/todos/1"
    );
    return todo;
  }


  static slugifyTitle(todo) {
    const slug = `${todo.title.replace(/ /g, "-")}${todo.id}`;
    return { ...todo, slug };
  }


  static async addToDB() {
    let todo = await this.fetchDataFromAPI();
    todo = this.slugifyTitle(todo);
    return todo;
  }
}


module.exports = MakeRequest;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The code above implements a &lt;em&gt;MakeRequest&lt;/em&gt; class, which has three functions &lt;em&gt;fetchDataFromAPI()&lt;/em&gt;, &lt;em&gt;slugifyTitle()&lt;/em&gt;, and &lt;em&gt;addToDB()&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Then, create a mock.test.js file and add the following code:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
    // Describing the tests related to mocking&lt;br&gt;
    describe("Mocking Tests", async () =&amp;gt; {&lt;br&gt;
        // Resetting mocks before each test&lt;br&gt;
        beforeEach(() =&amp;gt; mock.restoreAll());&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // Testing fetchDataFromAPI function to return a product
    it("fetchDataFromAPI should return a product", async (t) =&amp;gt; {
      // Mocking the fetchDataFromAPI function to return a predefined product
      mock
        .method(MakeRequest, MakeRequest.fetchDataFromAPI.name)
        .mock.mockImplementation(async () =&amp;gt; {
          return {
            userId: 1,
            id: 1,
            title: "delectus aut autem",
            completed: false,
          };
        });
      // Calling the function and asserting the returned product properties
      const res = await MakeRequest.fetchDataFromAPI();
      assert.strictEqual(res.userId, 1);
      assert.strictEqual(res.completed, false);
    });

    // Testing fetchDataFromAPI function to return a product with a given ID
    it("fetchDataFromAPI should return product with given ID", async (t) =&amp;gt; {
      const id = 3;
      // Mocking the fetchDataFromAPI function to return a product with a given ID
      mock
        .method(MakeRequest, MakeRequest.fetchDataFromAPI.name)
        .mock.mockImplementation(async (id) =&amp;gt; {
          return {
            userId: 1,
            id: id,
            title: "delectus aut autem",
            completed: false,
          };
        });
      // Calling the function with the provided ID and asserting the returned ID
      const res = await MakeRequest.fetchDataFromAPI(id);
      assert.deepEqual(res.id, id);
    });

    // Testing addToDB function to create a slug based on the title
    it("should create a slug based on the title", async (t) =&amp;gt; {
      // Spy on the slugifyTitle method
      const slugSpy = mock.method(MakeRequest, "slugifyTitle");
      // Mocking the fetchDataFromAPI function to return a predefined product
      mock
        .method(MakeRequest, "fetchDataFromAPI")
        .mock.mockImplementation(async () =&amp;gt; {
          return {
            userId: 1,
            id: 1,
            title: "delectus aut autem",
            completed: false,
          };
        });
      // Calling the addToDB function
      await MakeRequest.addToDB();
      // Getting the call information for slugifyTitle method
      const call = MakeRequest.slugifyTitle.mock.calls[0];
      // Asserting the number of calls made to slugifyTitle and fetchDataFromAPI
      assert.deepEqual(slugSpy.mock.calls.length, 1);
      assert.deepEqual(MakeRequest.fetchDataFromAPI.mock.callCount(), 1);
      // Asserting the created slug based on the title
      assert.strictEqual(call.result.slug, `delectus-aut-autem1`);
    });
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In the code above, the &lt;em&gt;fetchDataFromAPI&lt;/em&gt; method is mocked from the &lt;em&gt;MakeRequest&lt;/em&gt; class.&lt;/p&gt;

&lt;p&gt;To prevent the function from making a network request, the &lt;em&gt;mockImplementation()&lt;/em&gt; method is used to return a predefined output, which can be tested for specific values.&lt;/p&gt;

&lt;p&gt;Finally, &lt;em&gt;mock.method()&lt;/em&gt; is used to create a spy to test if the &lt;em&gt;slugifyTitle()&lt;/em&gt; function is called. Also, how many times the function is called, and its output is tested based on the title.&lt;/p&gt;

&lt;p&gt;Run the tests using the below-given command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
    node tests/mock.test.js&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Running Parallel Tests
&lt;/h2&gt;

&lt;p&gt;Node.js test runner allows you to execute multiple tests in parallel and at the same time instead of running them sequentially.&lt;/p&gt;

&lt;p&gt;To run tests in parallel in Node.js test runner, you need to pass the &lt;em&gt;concurrency: true&lt;/em&gt; parameter as the second argument to the &lt;em&gt;describe()&lt;/em&gt; function.&lt;/p&gt;

&lt;p&gt;Below is an example of how to run tests in parallel using Node.js native test runner and Selenium using concurrency parameters.&lt;/p&gt;

&lt;p&gt;Create a parallel.test.js file in the tests folder and add the following code:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
    describe("Ecommerce Site Tests", { concurrency: true }, async () =&amp;gt; {&lt;br&gt;
        let driver;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    before(async () =&amp;gt; {
  driver = await new Builder().forBrowser("chrome").build();

      await driver.get("https://ecommerce-playground.lambdatest.io/");
    });

    await it("should Navigate to ecommerce site and find an item", async () =&amp;gt; {
      const title = await driver.getTitle();
      assert.strictEqual(title, "Your Store");
    });

    await it("should Navigate to ecommerce site and add item to cart", async () =&amp;gt; {
      driver.findElement(By.xpath('//a[normalize-space()="Shop by Category"]')).click();

      driver.findElement(By.xpath('//span[normalize-space()="Phone, Tablets &amp;amp; Ipod"]')).click();

      driver.findElement(By.xpath('//div[@class="carousel-item active"]//img[@title="iPhone"]')).click();
    });

    afterEach(function () {
      driver.manage().deleteAllCookies();
    });

    after(async () =&amp;gt; {
      await driver.quit();
    });
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Run the below-given command to run the test:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
node tests/parallel.test.js&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The above test executions are performed on the local grid. However, to scale your automation testing with Node.js, you can consider using a cloud-based testing approach.&lt;/p&gt;

&lt;p&gt;AI-driven test execution platforms like LambdaTest let you run Node.js tests on a scalable &lt;a href="https://www.lambdatest.com/automation-cloud" rel="noopener noreferrer"&gt;automation cloud&lt;/a&gt; infrastructure, ensuring compatibility and reliability.&lt;/p&gt;

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

&lt;p&gt;In summary, the Node.js test runner offers a lightweight solution for creating and executing automated tests in your web projects. Though it may not include all the functionalities found in popular testing frameworks, its straightforwardness and user-friendly nature make it an excellent option for beginning automated testing.&lt;/p&gt;

&lt;p&gt;This blog discusses the features of the Node.js built-in test runner. It covers how to create tests using the &lt;em&gt;describe()&lt;/em&gt; function and its syntax while making use of hooks for setup and teardown operations, as well as mocking and running tests in parallel threads concurrently for JavaScript code quality assurance and stability enhancement purposes.&lt;/p&gt;

&lt;p&gt;For complex testing situations, you may want to evaluate the default test runner against popular frameworks such as Mocha, Jasmine, or Jest to determine which one best suits your requirements.&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>testing</category>
    </item>
    <item>
      <title>Using React Virtual DOM To Improve Web Application Performance</title>
      <dc:creator>Bonnie</dc:creator>
      <pubDate>Tue, 23 May 2023 12:24:29 +0000</pubDate>
      <link>https://dev.to/testmuai/using-react-virtual-dom-to-improve-web-application-performance-536h</link>
      <guid>https://dev.to/testmuai/using-react-virtual-dom-to-improve-web-application-performance-536h</guid>
      <description>&lt;p&gt;If you don’t know, HTML is the most widely used markup language for creating web pages supported by all major browsers like Google Chrome, Mozilla Firefox, and Safari. HTML elements are represented as a tree data structure on a browser by &lt;a href="https://www.lambdatest.com/blog/document-object-model/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Document Object Model (DOM)&lt;/a&gt;. When there is a change in the HTML document, the entire DOM is updated.&lt;/p&gt;

&lt;p&gt;However, updating the whole DOM each time a change is made can negatively impact the web application’s performance and cause it to slow down.&lt;/p&gt;

&lt;p&gt;This is where a virtual DOM can be leveraged to improve the web application’s performance whenever a change is made to HTML documents.&lt;/p&gt;

&lt;p&gt;This blog on React Virtual DOM covers its advantages over the Core DOM and &lt;a href="https://www.lambdatest.com/blog/shadow-dom-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Shadow DOM&lt;/a&gt;. It explains how to create a Virtual DOM in JavaScript and how it can improve web application performance with dynamic content. The blog also explores how React uses the Virtual DOM and deep dives into running automated tests on a React Virtual DOM web application using Jasmine and &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cloud Selenium Grid.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Perform manual or automated cross &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;browser test&lt;/a&gt; on 3000+ browsers online. Deploy and scale faster with the most powerful cross browser testing tool online.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Virtual DOM?
&lt;/h2&gt;

&lt;p&gt;In simple terms, Virtual DOM is a lightweight in-memory representation of a web page’s user interface (UI) or Core DOM. Many &lt;a href="https://www.lambdatest.com/blog/best-javascript-frameworks/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;JavaScript frameworks&lt;/a&gt; and libraries, such as React, Angular, and Vue.js, use a virtual DOM.&lt;/p&gt;

&lt;p&gt;Since manipulating or updating the Core DOM directly can make a web application slow, especially when there are frequent changes to the user interface, a Virtual DOM is used to improve its performance by avoiding unnecessary updates to the Core DOM.&lt;/p&gt;

&lt;p&gt;When the user interface of a web application using a Virtual DOM is rendered for the first time, a version of a Virtual DOM is created as a copy of the Core DOM and stored in memory. Every time a change is made to the user interface, a new version of Virtual DOM is created.&lt;/p&gt;

&lt;p&gt;Through a process called diffing, a JavaScript library or framework compares the new version of the Virtual DOM to the previous version and only updates the parts of the Core DOM that have changed.&lt;/p&gt;

&lt;p&gt;Assume the user interface, or the Core DOM, is a real house. If you want to change the house, like changing the windows, you have to rebuild the house from the ground up. Rebuilding the house from the ground up every time a change needs to be made can be expensive and time-consuming.&lt;/p&gt;

&lt;p&gt;Now take the small house on the top left below as the plan of the house. If you want to add new windows or change the house, you can ask an architect to draw a new plan with the new changes. Then you give the builders the new plan of the house, which they compare to the old plan to check the changes that need to be made to the house.&lt;/p&gt;

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

&lt;p&gt;After confirming the new changes, they only make the changes to the house without rebuilding it from the ground up.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Advantages of using a Virtual DOM in a web application
&lt;/h2&gt;

&lt;p&gt;Some of the advantages of using a Virtual DOM in a web application are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved Performance&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Better User Experience&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Better CPU and Memory Consumption&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Test native, hybrid, and web apps on any mobile OS with our free &lt;a href="https://www.lambdatest.com/android-emulator-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Android emulator online&lt;/a&gt;. Sign up to optimize app performance.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding the Document Object Model (DOM)
&lt;/h2&gt;

&lt;p&gt;The Document Object Model (DOM) is a programming language-neutral interface the browser creates when a web page is loaded. The DOM allows programs and scripts to dynamically access and update an HTML document’s content, structure, and style.&lt;/p&gt;

&lt;p&gt;The DOM defines HTML elements as objects. Also, the DOM defines the properties of all HTML elements and methods to access all HTML elements. Moreover, the DOM defines events for all HTML elements.&lt;/p&gt;

&lt;p&gt;Below is how the DOM defines HTML elements as objects.&lt;/p&gt;

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

&lt;p&gt;There are three types of DOM:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Core DOM&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Virtual DOM&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Shadow DOM&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Differences between the Core DOM, Virtual DOM, and Shadow DOM
&lt;/h2&gt;

&lt;p&gt;Below are the key differences between the Core DOM, Virtual DOM, and Shadow DOM, even though they are all related to the DOM.&lt;/p&gt;

&lt;h2&gt;
  
  
  Core DOM
&lt;/h2&gt;

&lt;p&gt;Core DOM is the real representation of HTML elements in a web page. When a change is made to the HTML document, the browser updates the Core DOM entirely.&lt;/p&gt;

&lt;p&gt;When dealing with large and complex web applications, updating the Core DOM completely can make them slow and cause performance issues.&lt;/p&gt;

&lt;p&gt;Here is how to view the Core DOM in a web application using inspect tools:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open the web application in a browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Right-click on the home page and select Inspect, which will open the DevTools.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Under the &lt;em&gt;Elements&lt;/em&gt; tab, the Core DOM tree of the web application is shown.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;h2&gt;
  
  
  Virtual DOM
&lt;/h2&gt;

&lt;p&gt;Virtual DOM is a lightweight version of the Core DOM. Virtual DOM keeps track of the changes made to the HTML documents.&lt;/p&gt;

&lt;p&gt;When a change is made to the HTML documents, Virtual DOM checks the difference between the previous and new versions of the HTML document and only updates elements that have changed on the Core DOM&lt;/p&gt;

&lt;p&gt;Here is how to view the Virtual DOM in a React web application using inspect tools and React Developer Tools:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Install the React Developer Tools extension on a browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open the web application in a browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Right-click on the home page and select Inspect, which will open the DevTools.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The React Developer Tools extension adds a new tab to DevTools that allows you to view the Virtual DOM or component tree of the React web application.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;h2&gt;
  
  
  Shadow DOM
&lt;/h2&gt;

&lt;p&gt;Shadow DOM creates an isolated component by enclosing an HTML element and its CSS styles. It allows you to create a separate DOM for separate HTML elements without interfering with the main DOM.&lt;/p&gt;

&lt;p&gt;Shadow DOM is used by HTML elements with their styles and behaviors.&lt;/p&gt;

&lt;p&gt;Here is how to view the Shadow DOM in a web application using inspect tools:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open the web application in a browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Right-click on the home page and select Inspect, which will open the DevTools.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Under the &lt;em&gt;Elements&lt;/em&gt; tab, the Shadow DOM is shown by a &lt;em&gt;#shadow-root&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

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

&lt;p&gt;Subscribe to the &lt;a href="https://www.youtube.com/c/LambdaTest?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=youtube" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel &lt;/a&gt;and stay updated with the latest tutorial around &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing,&lt;/a&gt; &lt;a href="https://www.lambdatest.com/cypress-testing" rel="noopener noreferrer"&gt;Cypress testing,&lt;/a&gt; and more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Test native, hybrid, and web apps on any mobile OS with our free &lt;a href="https://www.lambdatest.com/android-emulator-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Android online emulator&lt;/a&gt;. Sign up to optimize app performance.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to create Virtual DOM in JavaScript?
&lt;/h2&gt;

&lt;p&gt;In this section of this blog on using React Virtual DOM, we dive into how to create a React Virtual DOM and how to use a React Virtual DOM to improve the performance of a web application. To follow through with this section, you need a Text Editor and a Package Manager installed on your computer. In this case, I will use Visual Studio code as a Text Editor and NPM (Node Package Manager) as a Package Manager.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Create a project folder called VirtualDOM.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir VirtualDOM
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Open the project folder in a text editor and create a folder called src.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Create three files named &lt;em&gt;index.html, style.css&lt;/em&gt;, and *main.j*s in the src folder.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Link the &lt;em&gt;style.css&lt;/em&gt; and &lt;em&gt;main.js&lt;/em&gt; files to the index.html file. Then create a root div with #app id.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;link rel="stylesheet" href="style.css"&amp;gt;
    &amp;lt;title&amp;gt;Document&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div id="app"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;script type="module" src="main.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Install a build tool called Parcel by running the command below on a command line.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install parcel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; Add the following code block to the package.json file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
    "dev": "parcel src/index.html"
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Your &lt;em&gt;package.json&lt;/em&gt; file should now look as shown below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "scripts": {
    "dev": "parcel src/index.html"
  },
  "dependencies": {
    "parcel": "^2.8.3"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the &lt;em&gt;package.json&lt;/em&gt; file above, the scripts block defines a dev script that runs Parcel bundler with src.index.html file as the entry point. The Parcel is a web application bundler that bundles files and serves them on a server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt; Create a folder called vDom in the src folder.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 8:&lt;/strong&gt; Create a file called createElement.js in the vDom folder.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this article, we take a look at some aspects of simulation and discuss some ways through which we can use &lt;a href="https://www.lambdatest.com/blog/iphone-simulators-for-windows/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;ios emulator for pc. &lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 9:&lt;/strong&gt; A function called &lt;em&gt;createElement&lt;/em&gt; is used in Virtual DOM libraries such as React. The function creates a new React Virtual DOM element that can be rendered to the web application UI or Core DOM.&lt;/p&gt;

&lt;p&gt;For that reason, add the following code to the &lt;em&gt;createElement.js&lt;/em&gt; file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const createElement = (tagName, {attrs = {}, children = []} = {}) =&amp;gt; {
    return{
        tagName,
        attrs,
        children,
    }
}

export default createElement; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the code above, the &lt;em&gt;createElement&lt;/em&gt; function that creates and returns a React Virtual DOM element object is defined.&lt;/p&gt;

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

&lt;p&gt;The &lt;em&gt;createElement&lt;/em&gt; function takes two arguments. The first argument is called tagName, while the second argument is an object containing two optional properties: attrs and children.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;tagName&lt;/em&gt; argument is a string representing the tag name of the React Virtual DOM element to be created, such as a &lt;em&gt;div&lt;/em&gt;. The &lt;em&gt;attrs&lt;/em&gt; property is an object that represents attributes to be applied to the React Virtual DOM element, such as &lt;em&gt;class&lt;/em&gt; or &lt;em&gt;id&lt;/em&gt;. The children property is an array of child Virtual DOM elements such as other React Virtual DOM elements.&lt;/p&gt;

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

&lt;p&gt;Then the &lt;em&gt;createElement&lt;/em&gt; function returns an object that contains &lt;em&gt;tagName&lt;/em&gt;, &lt;em&gt;attrs&lt;/em&gt;, and &lt;em&gt;children&lt;/em&gt; properties.&lt;/p&gt;

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

&lt;p&gt;Finally, the &lt;em&gt;createElement&lt;/em&gt; function is exported so that it can be used by other files in the application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 10:&lt;/strong&gt; Add the following code to the &lt;em&gt;main.js&lt;/em&gt; file to define the React virtual DOM.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import createElement from "./vDom/createElement";

const virtualApp = createElement('div', {
    attrs: {
      id: 'app',
    },
    children: [
      createElement('h1', {
        attrs: {
          class: 'title',
        },
        children: [
            String("Virtual DOM")
        ]
      }),
      createElement('img', {
        attrs: {
            src: "https://files.virgool.io/upload/users/16337/posts/ksazdszokx1s/hl1p9zzfuygi.png"
        }
      }),
    ],
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the code above, a React Virtual DOM tree is created using the &lt;em&gt;createElement&lt;/em&gt; function imported from the &lt;em&gt;createElement.js&lt;/em&gt; file.&lt;/p&gt;

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

&lt;p&gt;The React Virtual DOM tree represents an HTML structure with a &lt;em&gt;div&lt;/em&gt; element as the root node, with an &lt;em&gt;id&lt;/em&gt; attribute set to the &lt;em&gt;app&lt;/em&gt;.&lt;/p&gt;

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

&lt;p&gt;The &lt;em&gt;div&lt;/em&gt; has two child elements: an &lt;em&gt;h1&lt;/em&gt; element and an img element. The &lt;em&gt;h1&lt;/em&gt; element has a &lt;em&gt;class&lt;/em&gt; attribute set to title and contains the string &lt;em&gt;Virtual DOM&lt;/em&gt; as its child node. The img element has an src attribute set to a URL that points to an image file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 11:&lt;/strong&gt; Let us render the React Virtual DOM created to the Actual DOM. To do that, create a file called render.js in the &lt;em&gt;vDom&lt;/em&gt; folder and add the following code to the file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const renderElement = ({tagName, attrs, children}) =&amp;gt; {
    const element = document.createElement(tagName);

    // set attributes
    for (const [k, v] of Object.entries(attrs)) {
        element.setAttribute(k, v);
    }

    // set children
    for (const child of children) {
        const $child = render(child);
        element.appendChild($child);
    }

    return element;
};

const render = (vNode) =&amp;gt; {
    if (typeof vNode === 'string') {
        return document.createTextNode(vNode);
    }

    return renderElement(vNode);
}

export default render;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the code above, a React Virtual DOM tree is rendered as real DOM elements.&lt;/p&gt;

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

&lt;p&gt;The &lt;em&gt;renderElement&lt;/em&gt; function takes an object representing a React Virtual DOM node as an argument, including the node’s &lt;em&gt;tagName, attrs,&lt;/em&gt; and &lt;em&gt;children&lt;/em&gt; properties.&lt;/p&gt;

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

&lt;p&gt;Inside the &lt;em&gt;renderElement&lt;/em&gt; function, a new DOM element with the specified &lt;em&gt;tagName&lt;/em&gt; is created.&lt;/p&gt;

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

&lt;p&gt;A for-loop is used to iterate over the attrs object to set each attribute on the newly created element using the &lt;em&gt;setAttribute&lt;/em&gt; method.&lt;/p&gt;

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

&lt;p&gt;A for-loop is used to iterate over the children array of React Virtual DOM nodes, recursively rendering each child node by calling the render function and appending it to the element using the &lt;em&gt;appendChild&lt;/em&gt; method.&lt;/p&gt;

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

&lt;p&gt;Finally, the &lt;em&gt;renderElement&lt;/em&gt; function returns the newly created DOM element.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Get started with this complete &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; automation testing tutorial. Learn what Selenium is, its architecture, advantages and more for automated cross browser testing.&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;The render function takes a React Virtual DOM node as an argument and checks if it’s a string node or a regular React Virtual DOM node. If the node is a string, the render function returns a text node with the string as its content.&lt;/p&gt;

&lt;p&gt;If the node is a regular React Virtual DOM node, render calls the renderElement function to create and return the corresponding DOM element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 12:&lt;/strong&gt; So far, we have created a React Virtual DOM and rendered it to the Actual DOM. Now we need to display the Actual DOM on a web page. To do that, create a file called mount.js in the vDom folder and add the following code.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const mount = (node, target) =&amp;gt; {
    target.replaceWith(node);
    return node;
};

export default mount;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the code above, a React Virtual DOM node is mounted onto an Actual DOM node.&lt;/p&gt;

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

&lt;p&gt;The mount function takes two arguments: node, which is the React Virtual DOM node to be mounted, and target, which is the Actual DOM node onto which the React Virtual DOM node should be mounted.&lt;/p&gt;

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

&lt;p&gt;The function replaces the target node with the React Virtual DOM node using the replaceWith method. This effectively removes the original target node from the document and replaces it with the new React Virtual DOM node.&lt;/p&gt;

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

&lt;p&gt;Finally, the function returns the React Virtual DOM node.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 13:&lt;/strong&gt; In the main.js file, import render and mount functions. At the bottom of the main.js file, render and mount the React Virtual DOM.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import createElement from "./vDom/createElement";
import render from "./vDom/render";
import mount from "./vDom/mount";

const virtualApp = createElement('div', {
    attrs: {
      id: 'app',
    },
    children: [
      createElement('h1', {
        attrs: {
          class: 'title',
        },
        children: [
            String("Virtual DOM")
        ]
      }),
      createElement('img', {
        attrs: {
            src: "https://bit.ly/41CwZhy"
        }
      }),
    ],
});

const App = render(virtualApp);
mount(App, document.getElementById('app'));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 14:&lt;/strong&gt; Run the command below on the command line.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;Navigate to &lt;a href="http://localhost:1234" rel="noopener noreferrer"&gt;http://localhost:1234&lt;/a&gt;, and you should see the React Virtual DOM showing on the web page.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  How does a Core DOM without a Virtual DOM affect a Web Application Performance?
&lt;/h2&gt;

&lt;p&gt;Assume you are shopping in an online eCommerce store web application, and the items you had added to the cart are lost every three seconds. Other online shoppers get the same user experience and as a result, the online eCommerce store sales go down.&lt;/p&gt;

&lt;p&gt;The owner of the online eCommerce store consults a web developer who determines that the online store web application HTML elements are reloading every three seconds because of a timer that shows how long some items on the e-commerce store are on offer.&lt;/p&gt;

&lt;p&gt;When a web application’s data changes constantly and triggers an update, the user interface is re-rendered. Re-rendering the whole application every time a change happens can make it slow, perform poorly or give a bad user experience, especially if it is a complex web application such as an online eCommerce store.&lt;/p&gt;

&lt;p&gt;In this section of the blog on using React Virtual DOM, you will learn how the real DOM affects a web application’s performance by following the steps below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Create a folder called &lt;em&gt;WebApp&lt;/em&gt;, then add two files called &lt;em&gt;index.html&lt;/em&gt; and &lt;em&gt;main.js&lt;/em&gt;. After that, install the &lt;em&gt;Parcel&lt;/em&gt; build tool, as shown in the section earlier.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; In the &lt;em&gt;index.html&lt;/em&gt; file, add the following code.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Web App&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div id="root"&amp;gt;

    &amp;lt;/div&amp;gt;
    &amp;lt;script type="module" src="/main.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the code above, an empty &lt;em&gt;div&lt;/em&gt; with a root id is created. Then the &lt;em&gt;main.js&lt;/em&gt; file is imported using a script tag.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; In the &lt;em&gt;main.js&lt;/em&gt; file, add the following code.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const update = () =&amp;gt; {
    const element = `
      &amp;lt;h3&amp;gt;Real DOM Vs Virtual DOM&amp;lt;/h3&amp;gt;
      &amp;lt;span&amp;gt;Time: ${new Date().toLocaleTimeString()}&amp;lt;/span&amp;gt;
    `;

    document.getElementById("root").innerHTML = element;
};

setInterval(update, 3000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the code above, a function called &lt;em&gt;update&lt;/em&gt; is created. Inside the function, a variable called the element is declared where it has the value of an h3 heading and a span that displays the current time using the JavaScript Date object.&lt;/p&gt;

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

&lt;p&gt;Then the &lt;em&gt;innerHTML&lt;/em&gt; property of the empty div in the index.html file is set to the value of the element variable.&lt;/p&gt;

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

&lt;p&gt;Finally, the &lt;em&gt;setInterval&lt;/em&gt; method sets up a timer that calls the update function every 3 seconds. As a result, the content of the root id div is updated with the current time every 3 seconds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Run the command below on the command line.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Navigate to &lt;a href="http://localhost:1234" rel="noopener noreferrer"&gt;http://localhost:1234&lt;/a&gt;, and you should see the current time updating every 3 seconds, as shown below.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; When you inspect the HTML elements, you will realize that the root id div element and its child elements representing real DOM are updated or re-rendered from scratch every 3 seconds, as shown below.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt; To see how updating or re-rendering all the HTML elements every time a change affects a web application’s performance, add a form input in the main.js file, as shown below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const update = () =&amp;gt; {
    const element = `
      &amp;lt;h3&amp;gt;Real DOM Vs Virtual DOM&amp;lt;/h3&amp;gt;
      &amp;lt;form&amp;gt;
        &amp;lt;input type="text"/&amp;gt;
      &amp;lt;/form&amp;gt;
      &amp;lt;span&amp;gt;Time: ${new Date().toLocaleTimeString()}&amp;lt;/span&amp;gt;
    `;

    document.getElementById("root").innerHTML = element;
};

setInterval(update, 3000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 8:&lt;/strong&gt; As shown below, when you try to type something on the input field, you will realize that the value is lost every time the elements are updated or re-rendered every 3 seconds.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Run your &lt;a href="https://www.lambdatest.com/playwright?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Playwright&lt;/a&gt; test scripts instantly on 50+ browser and OS combinations using the LambdaTest cloud. Read more.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use Virtual DOM to improve web application performance?
&lt;/h2&gt;

&lt;p&gt;In this section of the React Virtual DOM blog, let us add a React Virtual DOM to the web application created in the section above to reduce unnecessary updates that affect its performance. The React Virtual DOM will only update or re-render the span element with the timer every three seconds instead of the whole web application element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; In the WebApp folder created in the section above, run the command below on the command line to install ReactJS.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;Then run the command below to install ReactJS Virtual DOM.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install react react-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Replace the code on the &lt;em&gt;main.js&lt;/em&gt; file with the code below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createRoot } from "react-dom/client";

const rootElement = document.getElementById("root");
const root = createRoot(rootElement);

const update = () =&amp;gt; {
  const element = (
    &amp;lt;&amp;gt;
      &amp;lt;h3&amp;gt;Real DOM Vs Virtual DOM&amp;lt;/h3&amp;gt;
      &amp;lt;form&amp;gt;
        &amp;lt;input type="text" /&amp;gt;
      &amp;lt;/form&amp;gt;
      &amp;lt;span&amp;gt;Time: {new Date().toLocaleTimeString()}&amp;lt;/span&amp;gt;
    &amp;lt;/&amp;gt;
  );

  root.render(element);
};

setInterval(update, 3000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;In the code above, the React library renders a Real DOM and a React Virtual DOM. The import &lt;em&gt;{ createRoot }&lt;/em&gt; from &lt;em&gt;“react-dom/client”&lt;/em&gt; statement imports the &lt;em&gt;createRoot&lt;/em&gt; function from the react-dom/client module. This function creates a root-level component in a React application containing all the other components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The const &lt;em&gt;rootElement = document.getElementById(“root”)&lt;/em&gt; statement assigns the DOM element with the ID of “root” to the rootElement variable. This is where the root-level component created by &lt;em&gt;createRoot&lt;/em&gt; will be rendered.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The const &lt;em&gt;root = createRoot(rootElement)&lt;/em&gt; statement creates the root-level component using the createRoot function and assigns it to the root variable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The const &lt;em&gt;update = () =&amp;gt; { … }&lt;/em&gt; statement defines a function called update that will be called every 3 seconds using the setInterval function. This function creates a new element using JSX syntax(&amp;lt;&amp;gt;), a syntax extension of JavaScript that allows you to write HTML-like code in your JavaScript files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;em&gt;root.render(element)&lt;/em&gt; statement renders the new element created in the update function to the root-level component created earlier.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Run the command below on the command line which enables Parcel to bundle the web application and start a development server that listens on port number 1234 by default.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Navigate to &lt;a href="http://localhost:1234" rel="noopener noreferrer"&gt;http://localhost:1234&lt;/a&gt;, and inspect the HTML elements.&lt;/p&gt;

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

&lt;p&gt;As you can see, only the span element with the timer updates or re-renders every three seconds instead of all the web application HTML elements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; As shown below, when you type something on the input field, the value is not lost every time the timer is updated or re-rendered.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  How React uses Virtual DOM to improve web application performance?
&lt;/h2&gt;

&lt;p&gt;In React, the Virtual DOM is kept in memory as a virtual user interface representation. The React Virtual DOM is then synced with the DOM by a library such as ReactDOM in a process called reconciliation.&lt;/p&gt;

&lt;p&gt;ReactDOM is a JavaScript library used with React to build a web application user interface that can render React components in the core DOM. When you create a web application user interface components using React, ReactDOM provides the methods needed to render these components to the browser.&lt;/p&gt;

&lt;p&gt;These methods provided by ReactDOM include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;ReactDOM.render()&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;ReactDOM.unmountComponentAtNode()&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;ReactDOM.findDOMNode()&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;ReactDOM.createPortal()&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;ReactDOM.hydrate()&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;em&gt;ReactDOM.render()&lt;/em&gt; method takes a React component and mounts it into a DOM while &lt;em&gt;ReactDOM.unmountComponentAtNode()&lt;/em&gt; method unmounts a React component from the DOM.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;ReactDOM.findDOMNode()&lt;/em&gt; method returns the underlying DOM node of a React component while &lt;em&gt;ReactDOM.createPortal()&lt;/em&gt; method allows a React component to be rendered outside its parent DOM hierarchy.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;ReactDOM.hydrate()&lt;/em&gt; method is used to attach a React component to existing HTML content rendered by the server, known as Server Side Rendering (SSR) of React components.&lt;/p&gt;

&lt;p&gt;When a web application is rendered for the first time, React uses the &lt;em&gt;render()&lt;/em&gt; function to create a tree of React elements that act as a Virtual DOM. If the state of the web application changes, the &lt;em&gt;render()&lt;/em&gt; function creates a new tree of React elements or Virtual DOM.&lt;/p&gt;

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

&lt;p&gt;Then React compares the new Virtual DOM with the old version of the React Virtual DOM to determine which nodes have changed or have been updated. React then efficiently updates the user interface or the real DOM to match the new version of the React Virtual DOM.&lt;/p&gt;

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

&lt;p&gt;To compare the new version of Virtual DOM with the old version of React Virtual DOM, React uses an algorithm called Diffing. When using the Diffing Algorithm, React first compares the type of the old and new versions of React Virtual DOM root HTML elements.&lt;/p&gt;

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

&lt;p&gt;If the root elements are of different types, React will destroy the old version of the React Virtual DOM and build a new Virtual DOM from scratch. For example, if the old version of the React Virtual DOM root HTML element is a &amp;lt; div &amp;gt; and the new version of the Virtual DOM root HTML element is a &amp;lt; main &amp;gt; or &amp;lt; span &amp;gt;, the old version of the React Virtual DOM is destroyed.&lt;/p&gt;

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

&lt;p&gt;If the root HTML elements of the old and new versions of the Virtual DOM are of the same type, React looks at their attributes, then keeps the old version of the React Virtual DOM and only updates the parts that have changed.&lt;/p&gt;

&lt;p&gt;After handling the root HTML elements of the old and new versions of the Virtual DOM, React then recurses through their children’s HTML elements. When recursing through the children of the root HTML elements, React iterates both children’s HTML elements simultaneously and only updates HTML elements that have changed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Here’s 295+ &lt;a href="https://www.lambdatest.com/learning-hub/selenium-interview-questions?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium Interview Questions&lt;/a&gt; with Answers that will help you boost your confidence in an Interview.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Automated Geolocation Testing on a Virtual DOM web application using Jasmine and Cloud Selenium Grid
&lt;/h2&gt;

&lt;p&gt;Jasmine is one of the most popular &lt;a href="https://www.lambdatest.com/blog/top-javascript-automation-testing-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;JavaScript-based testing frameworks.&lt;/a&gt; It is a &lt;a href="https://www.lambdatest.com/blog/behaviour-driven-development-by-selenium-testing-with-gherkin/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Behavior-Driven Development (BDD&lt;/a&gt;) framework that provides a structure for developers to write tests. Jasmine tests are written in JavaScript and are typically run in a web browser or command line using a JavaScript runtime environment, such as Node.js.&lt;/p&gt;

&lt;p&gt;LambdaTest is a digital experience testing platform that lets you perform &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automation testing&lt;/a&gt; with Jasmine and &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; on a cloud Selenium Grid across 3,000+ different browsers and operating systems.&lt;/p&gt;

&lt;p&gt;In this section of the React Virtual DOM tutorial, you will learn how to create and run automated &lt;a href="https://www.lambdatest.com/blog/how-to-test-geolocation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;geolocation tests&lt;/a&gt; that test whether a user can see their local time on a web application. We will test the geolocation on multiple browser versions and operating system combinations. We can use three browser versions and operating system combinations in this case.&lt;/p&gt;

&lt;p&gt;These browser versions and operating system combinations are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Chrome 108.0 + Windows 10&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Safari 16.0 + macOS Ventura&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Firefox 106.0 + Windows 11&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To define your desired browser and operating system combinations, you can use &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest Capabilities Generator.&lt;/a&gt;&lt;/p&gt;

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

&lt;h2&gt;
  
  
  How to generate Browser and Operating System combinations?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; On the Capabilities Generator Page, select the programming language you are using to run your tests. In this case, we use JavaScript and can select Node JS, a JavaScript framework.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Select Selenium.&lt;/p&gt;

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

&lt;p&gt;Then select Selenium version 4 on the right.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Configure your capabilities by selecting a browser and browser version.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Click Configure Advanced Capabilities and select the operating system.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Scroll down to the Build Settings section and fill out the input fields as shown below.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; Scroll down to the test configuration section and fill out the input field as shown below.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt; Scroll down to the geolocation and timezone section, then select the options as shown below.&lt;/p&gt;

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

&lt;p&gt;On the right, you can now see the capabilities presented in a code format that you can copy and use in your test script.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Test Case Scenarios
&lt;/h2&gt;

&lt;p&gt;In this case, we will run four geolocation tests. The first test will test if a user in New York, United States can see their local time. Below is the test case scenario.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to the collaboration platform.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check whether the time shown is the same as New York’s local time.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The second test will test if a user in Berlin, Germany can see their local time. Below is the test case scenario.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to the collaboration platform.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check whether the time shown is the same as Berlin’s local time.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The third test will test if a user in Nairobi, Kenya can see their local time. Below is the test case scenario.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to the collaboration platform.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check whether the time shown is the same as Nairobi’s local time.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The fourth test will test if a user in Sydney, Australia, can see their local time. Below is the test case scenario.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to the collaboration platform.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check whether the time shown is the same as Sydney’s local time.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Creating and Running Test Scripts
&lt;/h2&gt;

&lt;p&gt;Due to many test scenarios and updates that might be made to the test code, &lt;a href="https://www.lambdatest.com/blog/using-page-object-model-pattern-in-javascript-with-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Page Object Model&lt;/a&gt; can be used in test scripts. Page Object Model, also known as POM, is a design pattern used in software testing to create maintainable and readable automated test code.&lt;/p&gt;

&lt;p&gt;POM creates an object for each web page in an application, and then page objects interact with the web page to perform actions such as filling out input fields, clicking buttons, or checking some text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Create a project folder called GeolocationTesting using the command below.\&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir GeolocationTesting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Open the project folder in a text editor and create a spec folder.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Create a pageModel and Geolocation folder in the spec folder, as shown below.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Create four files called us.js, germany.js, kenya.js, and australia.js in the pageModel folder.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Run the command below on the command line to install Jasmine in your project.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install — save-dev jasmine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Adding –save-dev to the command helps save the name and version of Jasmine in the dev-dependency object.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; Run the command below on the command line to initialize Jasmine in your project.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;px jasmine init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt; Configure the npm test script to run the Jasmine JS tests when the command npm test is executed. To do that, update the package.json file and add a script section, as shown below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "scripts": {
    "test": "jasmine"
  },
  "devDependencies": {
    "jasmine": "^4.6.0"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;&lt;strong&gt;Step 8:&lt;/strong&gt; Install the latest version of the &lt;a href="https://www.lambdatest.com/learning-hub/webdriver?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt; in the project folder by running the command below on the command line.&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 9:&lt;/strong&gt; In the &lt;em&gt;us.js file&lt;/em&gt;, add the following code.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;selenium = require('selenium-webdriver');
const {Builder, By, Key, until} = require('selenium-webdriver');

const username= process.env.LT_USERNAME || "Username"
const accessKey=  process.env.LT_ACCESS_KEY || "Access Key"
var remoteHub = 'https://' + username + ':' + accessKey + '@hub.lambdatest.com/wd/hub';

const NewYorkCaps = {
    "browserName": "Chrome",
    "browserVersion": "108.0",
    "LT:Options": {
        "username": "Username",
        "accessKey": "Access Key",
        "geoLocation": "US",
        "platformName": "Windows 10",
        "timezone": "New_York",
        "build": "New York USA",
        "project": "Geolocation Testing",
        "name": "New York Local Time Test",
        "selenium_version": "4.0.0",
        "w3c": true
    }
}

const getElementById = async (driver, id, timeout = 8000) =&amp;gt; {
    const el = await driver.wait(until.elementLocated(By.id(id)), timeout);
    return await driver.wait(until.elementIsVisible(el), timeout);
};

const seleniumDriver = new selenium.Builder().
usingServer(remoteHub).
withCapabilities(NewYorkCaps).
build();

const timeUrl = 'https://virtualdom.netlify.app/'

class Main {

    constructor() {
        this.driver = seleniumDriver;
        this.byId = getElementById;
        this.url = timeUrl;
        this.localTime = ('time');
    }

    async visit() {
        await this.driver.get(this.url);
    }

    async time() {
        const currentTime = await this.byId(this.driver, this.localTime);

        currentTime.getText().then(function(value) {
        expect(value).toBe(`Time: ${new Date().toLocaleTimeString()}.`);
        });
    }

    async before() {
        this.driver;
    }

    async quitB() {
        await this.driver.quit();
    }
}

module.exports = new Main();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Ace your Cypress interview with these 60+ &lt;a href="https://www.lambdatest.com/learning-hub/cypress-interview-questions?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Cypress interview questions&lt;/a&gt;. Boost you confidence and land your dream job with this comprehensive guide.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;Since we are using Selenium to run the tests, &lt;em&gt;Selenium&lt;/em&gt; &lt;em&gt;WebDriver&lt;/em&gt;, until, and By are imported using require function as shown below:&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;Variables &lt;em&gt;username&lt;/em&gt;, &lt;em&gt;accessKey&lt;/em&gt;, and &lt;em&gt;remoteHub&lt;/em&gt; to be used in the test case are set.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;Test capabilities are configured by passing &lt;em&gt;browser&lt;/em&gt;, &lt;em&gt;browser version&lt;/em&gt;, and &lt;em&gt;operating system&lt;/em&gt; information with LambdaTest Selenium Grid Capabilities through the capabilities object.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;An async function called &lt;em&gt;getElementById&lt;/em&gt; with parameters &lt;em&gt;driver&lt;/em&gt;, &lt;em&gt;id&lt;/em&gt;, and &lt;em&gt;timeout&lt;/em&gt; set to 8000 milliseconds is declared.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Inside the async function, declare a variable called el, where the variable value instructs the Selenium Driver to wait until the element with the targeted id is located on the registration page of the eCommerce website. The elementLocated() method is used here.&lt;/p&gt;

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

&lt;p&gt;Below is how an element is located by the &lt;a href="https://www.lambdatest.com/blog/making-the-move-with-id-locator-in-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;ID locator.&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;An object returned by the getElementById async function instructs the Selenium WebDriver to wait until the element we target by id is present on the DOM of the registration page and visible. Visibility means that the element is not only displayed but also has a height and width that is greater than zero. The elementIsVisible() method is used here.&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;A new instance of a Selenium WebDriver is initialized using the Builder design pattern.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;The &lt;em&gt;const&lt;/em&gt; declares a constant variable named &lt;em&gt;seleniumDriver&lt;/em&gt;, which will hold the created &lt;em&gt;Selenium WebDriver&lt;/em&gt; instance. The new &lt;em&gt;selenium.Builder()&lt;/em&gt; creates a new instance of the Builder class provided by the Selenium library.&lt;/p&gt;

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

&lt;p&gt;The usingServer(remoteHub) specifies the URL of a Selenium server to use, which is passed as the value of the remoteHub variable. This indicates that the WebDriver instance will be a remote one and not a local one.&lt;/p&gt;

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

&lt;p&gt;The withCapabilities(NewYorkCaps) sets the capabilities of the WebDriver instance. The NewYorkCaps variable holds an object that defines the desired capabilities for this WebDriver instance. Capabilities are a set of key-value pairs that specify the browser, platform, and other settings that will be used by the WebDriver instance.&lt;/p&gt;

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

&lt;p&gt;The &lt;em&gt;build()&lt;/em&gt; creates and returns a new instance of a Selenium WebDriver, based on the previously set configuration. The new WebDriver instance is then assigned to the seleniumDriver constant variable.&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;Variable &lt;em&gt;timeUrl&lt;/em&gt; is assigned the URL of the web application to be tested.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;A JavaScript class called Main is created where the class has a constructor method, a special method called when an object of the class is created. The constructor method initializes the properties of the class.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;A value of &lt;em&gt;seleniumDriver&lt;/em&gt; is assigned to &lt;em&gt;this.driver&lt;/em&gt; property, a value of &lt;em&gt;getElementById&lt;/em&gt; to &lt;em&gt;this.byId&lt;/em&gt; property, and a value of timeUrl to this.url property in this constructor method. Property this.localTime is assigned an ID selector value that will be used to find the local time in the web application.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;To add the ID selector, navigate to the web application.&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;The Async function &lt;em&gt;visit()&lt;/em&gt; is created where the &lt;em&gt;get()&lt;/em&gt; method is used to load the URL of the web application.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;The &lt;em&gt;Async function time()&lt;/em&gt; is created. In the async function, the path for the web element to be tested on the web application is defined in the async function.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;The &lt;em&gt;Async functions before()&lt;/em&gt; and quitB() are created where the async function before() starts a browser session while the &lt;em&gt;async function quitB()&lt;/em&gt; ends the browser session.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Finally, the Main class is exported to be used in other files.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt; In the germany.js, kenya.js, and australia.js files, add the same code as the us.js file. The only difference is the capabilities variables, as shown below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Capabilities for germany.js&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;Then add the BerlinCaps variable to the value of the seleniumDriver variable.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Capabilities for kenya.js&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;Then add the NairobiCaps variable to the value of the seleniumDriver variable.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Capabilities for australia.js&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;Then add the SydneyCaps variable to the value of the seleniumDriver variable.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 8:&lt;/strong&gt; In the Geolocation folder, create four files called newyork.spec.js, berlin.spec.js, nairobi.spec.js, and sydney.spec.js, as shown below.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 9:&lt;/strong&gt; In the &lt;em&gt;newyork.spec.js&lt;/em&gt;, add the following code.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ach(async () =&amp;gt; {
        Time.quitB();
    });

    it("User should be able to see their local time in New York", async function() {
        await Time.visit();

        await Time.time();
    });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;ol&gt;
&lt;li&gt;Variable Time is assigned the value of the Main class imported from the us.js file.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;The default timeout interval for tests is set.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;The jasmine.DEFAULT_TIMEOUT_INTERVAL = 80 * 1000; sets the default timeout interval to 80,000 milliseconds or 80 seconds. This means that if a test doesn’t complete within 100 seconds, it will be marked as a failure.&lt;/p&gt;

&lt;p&gt;The jasmine.getEnv().defaultTimeoutInterval = 80000; changes the default timeout interval to 60,000 milliseconds, or 60 seconds, after the initial default set in the previous line.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A describe block function called Local Time Tests, where all the tests for the web application are written.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;Inside the describe block, beforeEach and afterEach functions are created where they call &lt;em&gt;before()&lt;/em&gt; and &lt;em&gt;quitB()&lt;/em&gt; async functions created in the Main class.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;The &lt;em&gt;beforeEach&lt;/em&gt; function is called before each test case is run and is used to set up the initial state or environment for the tests. The afterEach function is called after each test case is run, and it is used to clean up or reset the state of the environment after a test case is completed.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A test case is defined.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;The it function is used to define a single test case, and it takes two arguments: the first is a string that describes the test case, and the second is a function that contains the test logic.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;em&gt;visit()&lt;/em&gt; async function from the Main class is called on the driver object, which is an instance of the Selenium WebDriver.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;The async function where the path for the web element on the web application defined in the Main class is called.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;In the berlin.spec.js, nairobi.spec.js, and sydney.spec.js files, add the same code. The difference is the file imported to each file.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;File import in berlin.spec.js&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Time = require(‘../pageModel/germany’)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;File import in nairobi.spec.js&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Time = require(‘../pageModel/kenya’)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;File import in berlin.spec.js&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Time = require(‘../pageModel/australia’)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Run the commands below on the command line.&lt;/p&gt;

&lt;p&gt;npx jasmine spec/Geolocation/newyork.spec.js &amp;amp;&amp;amp; npx jasmine spec/Geolocation/berlin.spec.js &amp;amp;&amp;amp; npx jasmine spec/Geolocation/nairobi.spec.js &amp;amp;&amp;amp; npx jasmine spec/Geolocation/sydney.spec.js&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once the commands run, you should see on your command line that the tests have passed successfully.&lt;/p&gt;

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

&lt;p&gt;Visit your &lt;a href="https://accounts.lambdatest.com/dashboard?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest Dashboard,&lt;/a&gt; and on the right side of the screen, you should be able to see your recent tests, as shown below.&lt;/p&gt;

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

&lt;p&gt;Click on one of the tests, and you will be redirected to the Automation Dashboard, as shown below.&lt;/p&gt;

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

&lt;p&gt;The Automation Dashboard has all the information about the test, including a video and a screenshot showing how the test went. You can also access the report on &lt;a href="https://analytics.lambdatest.com/test-overview?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Analytics Dashboard&lt;/a&gt;, which shows all the details and metrics related to your tests.&lt;/p&gt;

&lt;p&gt;To see all the details and metrics related to your tests, navigate to the Analytics Dashboard, and you will be prompted to select an analytics template, as shown below.&lt;/p&gt;

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

&lt;p&gt;In this case, you can select the Tests Summary Report template that provides all the summaries of the tests run on the LambdaTest Cloud Selenium Grid. On the right side of your page, you are prompted to create a dashboard where the test analytics will be displayed.&lt;/p&gt;

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

&lt;p&gt;The first thing you need to do is give the dashboard a name. In this case, you can name the dashboard Geolocation Tests, as shown below.&lt;/p&gt;

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

&lt;p&gt;Then filter the web automation reports you want to be displayed on the Geolocation Tests dashboard. In this case, you can filter the reports by builds and then add the builds, as shown below.&lt;/p&gt;

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

&lt;p&gt;Finally, click the Create New Dashboard button at the bottom. You will then be redirected to the tests summary report, as shown below.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;&lt;em&gt;This questionnaire intends to provide a list of some of the most frequently asked &lt;a href="https://www.lambdatest.com/learning-hub/jenkins-interview-questions?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Jenkins interview questions&lt;/a&gt; to assist job seekers in preparing for interviews.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;In conclusion, building web applications using a React Virtual DOM can improve web application performance and user experience. By using &lt;a href="https://www.lambdatest.com/blog/automation-testing-frameworks/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may23_bh&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing frameworks&lt;/a&gt; like Jasmine and web automated testing platforms like LambdaTest Cloud Selenium Grid, you can ensure a web application performs as expected when accessed by users.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions (FAQs)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. What is a virtual DOM in React?
&lt;/h3&gt;

&lt;p&gt;In React, the Virtual DOM (Document Object Model) is a lightweight copy of the actual DOM representation of a web page. It is a concept and technique used by React to optimize the updating process of web interfaces.&lt;/p&gt;

&lt;p&gt;When changes occur in a React component, instead of directly manipulating the real DOM, React creates a virtual representation of the DOM and compares it with the previous version. This allows React to efficiently determine the minimal number of changes needed to update the real DOM.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. What is React DOM vs React Virtual DOM?
&lt;/h3&gt;

&lt;p&gt;React DOM and React virtual DOM are two different concepts in React:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;React DOM is the package specifically designed for rendering React components into the real DOM. It provides the necessary methods and APIs to interact with the actual DOM, update it, and handle events. React DOM efficiently updates the real DOM based on changes in the virtual DOM.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Virtual DOM is a lightweight copy of the actual DOM. It is a concept and technique used by React to optimize the updating process of web interfaces. When changes occur in a React component, instead of directly manipulating the real DOM, React creates a virtual representation of the DOM and performs a diffing algorithm to determine the minimal changes needed to update the Real DOM.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Why is React virtual DOM faster?
&lt;/h3&gt;

&lt;p&gt;The React virtual DOM is designed to improve performance in several ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Efficient updates&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Batched updates&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Minimized DOM manipulations&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Virtual DOM operations are faster&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Efficient reconciliation&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Overall, the combination of efficient updates, batched operations, minimized DOM manipulations, faster virtual DOM operations, and optimized reconciliation contribute to the improved performance of React’s virtual DOM approach.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>performance</category>
      <category>programming</category>
      <category>react</category>
    </item>
    <item>
      <title>How To Perform Modern Web Testing With TestCafe Using JavaScript And Selenium</title>
      <dc:creator>Bonnie</dc:creator>
      <pubDate>Mon, 26 Dec 2022 13:31:05 +0000</pubDate>
      <link>https://dev.to/testmuai/how-to-perform-modern-web-testing-with-testcafe-using-javascript-and-selenium-f9b</link>
      <guid>https://dev.to/testmuai/how-to-perform-modern-web-testing-with-testcafe-using-javascript-and-selenium-f9b</guid>
      <description>&lt;p&gt;Whether it is an application or web app, every software requires testing after development to ensure it does what we expect it to do. Software testing involves using manual or automated tools. Test automation tools are the best to use over manual tools because they increase software testing effectiveness, efficiency, and coverage.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/guide-to-end-to-end-testing-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;End-to-End testing&lt;/a&gt; (or E2E testing) is used to test whether the flow of an application right from start to finish is behaving as expected. End-to-End tests simulate real user scenarios where the automation tool tests how a real user would use the application.&lt;/p&gt;

&lt;p&gt;This blog on modern web testing with TestCafe will help you learn how to perform End-to-End automated web tests with JavaScript using TestCafe and &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cloud Selenium Grid.&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Start your journey with &lt;a href="https://www.lambdatest.com/selenium-javascript-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium JavaScript Testing&lt;/a&gt; on LambdaTest’s online cloud.&lt;/p&gt;

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

&lt;p&gt;As per the StackOverflow 2021 Developer Survey, JavaScript completed its ninth year as the most commonly used programming language.&lt;/p&gt;

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

&lt;p&gt;TestCafe is a Node.js End-to-End free and open-source automation framework used to test web applications. TestCafe supports both JavaScript and TypeScript. Hence you can write TestCafe tests in either one of the two. With TestCafe, you needn’t depend upon WebDriver or worry about manual timeouts. Get the most out of &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; with this TestCafe tutorial on performing modern web testing with TestCafe.&lt;/p&gt;

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

&lt;p&gt;Selenium is an open-source automation framework extensively used in automated tests for web applications. A new version of Selenium has been launched in the market. The latest version is Selenium 4, an upgrade from Selenium 3. You can learn about the &lt;a href="https://www.lambdatest.com/blog/what-is-deprecated-in-selenium4/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;features and improvements in Selenium 4&lt;/a&gt; by going through this &lt;a href="https://www.lambdatest.com/learning-hub/selenium-4?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium 4 tutorial&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The most notable improvement in Selenium 4 is the &lt;a href="https://www.lambdatest.com/blog/selenium4-w3c-webdriver-protocol/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;World Wide Web Consortium(W3C)&lt;/a&gt; compliance with WebDriver APIs. This means that Selenium 4 offers more stable cross-browser tests, as no additional encoding-decoding of the API requests is necessary.&lt;/p&gt;

&lt;h2&gt;
  
  
  TestCafe Trends on GitHub
&lt;/h2&gt;

&lt;p&gt;TestCafe is a prevalent &lt;a href="https://www.lambdatest.com/blog/best-test-automation-frameworks-2021/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation framework&lt;/a&gt;; the data obtained from the official TestCafe GitHub repository says it all:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Stars: 93K&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Contributors: 107&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Forks: 650&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Releases: 338&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Used by 10K users&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At the time of writing this blog, TestCafe had 254,003 weekly downloads on NPM.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Advantages of TestCafe Automation
&lt;/h2&gt;

&lt;p&gt;Now that I have covered the fundamentals of TestCafe, let’s look at some of the significant advantages of TestCafe. JavaScript supports several other &lt;a href="https://www.lambdatest.com/selenium-languages-and-frameworks?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;web automation frameworks&lt;/a&gt; like WebDriverIO, Mocha, Jasmine, Protractor, etc. The critical question is, what is the core speciality of TestCafe?&lt;/p&gt;

&lt;p&gt;Here are some of the major benefits of the TestCafe automation framework:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;TestCafe is easy to set up because it does not require the installation of third-party plugins, web drivers, or additional libraries to run tests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;TestCafe supports all major browsers, such as&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Google Chrome&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IE 11&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Microsoft Edge&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mozilla&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Safari&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Chrome mobile&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Safari mobile&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;TestCafe is open source and free to use because it is licensed by MIT.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

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

&lt;p&gt;Liked this video? Follow the &lt;a href="https://www.youtube.com/c/LambdaTest" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; for more such videos around &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, CI/CD, &lt;a href="https://www.lambdatest.com/cypress-ui-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress UI testing&lt;/a&gt;, and more,&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started With TestCafe Automation
&lt;/h2&gt;

&lt;p&gt;In this section of this article on modern web testing with TestCafe, you will learn how to install TestCafe and run your first test in TestCafe. To install and use TestCafe in your system, you need a Text Editor, NodeJS, and Node Package Manager (NPM) installed.&lt;/p&gt;

&lt;p&gt;For demonstration, I will be using Visual Studio Code as the Text Editor. However, you can use the IDE of your choice.&lt;/p&gt;

&lt;p&gt;Here is the list of VS Code extensions necessary for performing modern web testing with TestCafe.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;TestCafe Snippets&lt;/strong&gt;: Provides code snippets for TestCafe&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;TestCafe Test Runner&lt;/strong&gt;: Allows you to run tests directly from VS Code&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;TestLatte&lt;/strong&gt;: Lets you debug or run your TestCafe tests on VS Code&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Want to make your life of testing easy and fuss-free while debugging? &lt;a href="https://www.lambdatest.com/lt-debug?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Try LT Debug Chrome extension&lt;/a&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  How to install TestCafe Extensions
&lt;/h2&gt;

&lt;p&gt;To install TestCafe Extensions, please follow the below mentioned steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;On your computer, create a folder called “TestCafeDemo”.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Right-click on the folder and open it using VS Code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once VS Code has launched, navigate to extensions by clicking the extensions button on the left side of your screen.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;4- On the extension’s search bar, type “testcafe” and all three extensions will appear. Click on each extension and install it.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Installing TestCafe in VS Code
&lt;/h2&gt;

&lt;p&gt;To install TestCafe in VS Code, please follow the below mentioned steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the terminal on VS Code by clicking the Terminal option at the top of your VS Code Window and then select New Terminal as shown below:&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;2-  Run the command below on your terminal to install TestCafe.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   npm install testcafe.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3- Once the installation is done, run the command below to see the version of TestCafe installed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   testcafe -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4- Run the command below to create a Package.json file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    npm init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;5- Run the command below to add TestCafe as a dependency for our project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    npm install testcafe
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if you navigate to the package.json file, you will find that TestCafe has been added as one of the dependencies.&lt;/p&gt;

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

&lt;p&gt;Run TestCafe Tests on the cloud! &lt;a href="https://accounts.lambdatest.com/register?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=register" rel="noopener noreferrer"&gt;Try LambdaTest Now!&lt;/a&gt;&lt;/p&gt;

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

&lt;h2&gt;
  
  
  How to run Selenium Tests using TestCafe?
&lt;/h2&gt;

&lt;p&gt;To demonstrate how to perform &lt;a href="https://www.lambdatest.com/testcafe-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;TestCafe testing&lt;/a&gt; using Selenium, I will be using a dummy e-commerce playground from LambdaTest for automating test scenarios. Here, the customers need to create an account to be able to buy something from the website.&lt;/p&gt;

&lt;p&gt;To make sure that the registration form works as expected, you can use TestCafe to run an automated test where TestCafe simulates the end-user interaction with the elements in the DOM. The automation will be performed on the Chrome, Firefox, and Safari browsers.&lt;/p&gt;

&lt;p&gt;To run the test, we will create a folder called “TestCafeTests”. Inside the folder, we will create two folders called “PageModel” and “Tests”. We will create two folders inside the “TestCafeTests” folder because we will be using &lt;a href="https://www.lambdatest.com/blog/using-page-object-model-pattern-in-javascript-with-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Page Object Model in Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Page Object Model, also known as POM, is a design pattern where an object repository is created for storing the WebElements. POM helps us reduce code duplication and minimizing efforts involved in test case maintenance.&lt;/p&gt;

&lt;p&gt;Before running the test, let us see how the test case will &lt;a href="https://www.lambdatest.com/blog/test-a-signup-page-problems-test-cases-and-template/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;run a test on the e-commerce registration page.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Test Scenario (Chrome Browser)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to the e-commerce playground.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add “John” to the First Name input field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add “Doe” to the Last Name input field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add “&lt;a href="mailto:johndoe@example.com"&gt;johndoe@example.com&lt;/a&gt;” to the email input field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add “0712345678” to the telephone input field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add “Qwerty123!” to the password input field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add “Qwerty123!” to the password confirm input field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the “agree to privacy policy” checkbox.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click the “Continue” submit button.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To run TestCafe tests, follow the below mentioned steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new folder in your project and call “TestCafeTests” in this path “TestCafeDemo/TestCafeTests”.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;2- In the “TestCafeTests” folder, create two other folders called “PageModel” and “Tests”.&lt;/p&gt;

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

&lt;p&gt;3- In the “PageModel” folder, let us create a file called “SignUp.js” as shown below.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Setting up POM
&lt;/h2&gt;

&lt;p&gt;You can follow the below mentioned steps to set up POM:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In this step, we will declare the “SignupPage” class in the “SignupPage.js” file and export its instance as shown below.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   class SignupPage {

       constructor(){
       }
    }

    export default new SignupPage();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2- We will need to add WebElements to the “SignupPage” class. These WebElements will be input fields and buttons on the e-commerce website registration page that I mentioned earlier.&lt;/p&gt;

&lt;p&gt;3- Navigate to the registration page, inspect the web page and get the &lt;a href="https://www.lambdatest.com/blog/making-the-move-with-id-locator-in-selenium-webdriver/" rel="noopener noreferrer"&gt;ID locator&lt;/a&gt; of the input fields together with buttons that a user is expected to fill and click when creating an account as shown below.&lt;/p&gt;

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

&lt;p&gt;4- Then add “firstname, last name, email, telephone, password, confirm password, Click on agree and continue” ID and &lt;a href="https://www.lambdatest.com/blog/selenium-java-tutorial-class-name-locator-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Class locators&lt;/a&gt; to the model. To do this, we will introduce “firstnameInput, lastnameInput, emailInput, telephoneInput, passwordInput, confirmInput, agreeBtn, and continueBtn ” properties and assign a selector to them. If you wish to learn more about Selenium locators, go through this article on &lt;a href="https://www.lambdatest.com/blog/locators-in-selenium-webdriver-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Locators in Selenium WebDriver&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;5- When inspecting the web page to get the ID locators, you will find out that the “Continue” submit button has no ID assigned to it. For TestCafe to be able to locate it, we will get the submit button class name and add “input.” before the class instead of “#” which represents ID locators.&lt;/p&gt;

&lt;p&gt;6- To assign a selector to them, we will have to import it at the top of the “SignupPage.js” file from TestCafe. The “SignupPage.js” file should now look as shown below:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FileName — SignupPage.js&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;  import {Selector, t} from 'testcafe';

    class SignupPage {

       constructor(){
           this.firstnameInput = Selector('#input-firstname');
           this.lastnameInput = Selector('#input-lastname');
           this.emailInput = Selector('#input-email');
           this.telephoneInput = Selector('#input-telephone');
           this.passwordInput = Selector('#input-password');
           this.confirmInput = Selector('#input-confirm');
           this.agreeBtn = Selector('#input-agree');
           this.continueBtn = Selector('input.btn-primary');
       }
    }

    export default new SignupPage();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;7- Let us now create a test that uses the POM design pattern Page that we created earlier. In the “Tests” folder, create a file called “SignupTest.js” as shown below.&lt;/p&gt;

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

&lt;p&gt;8- In the “SignupTets.js” file, we will import the page model instance from the “SignupPage.js” file 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;   import SignupPage from "../PageModel/SignupPage";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;9- Let us now create a variable called “url” that will hold the test URL against which the automation tests are run.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   import SignupPage from "../PageModel/SignupPage";

    const url = 'https://ecommerce-playground.lambdatest.io/index.php?route=account/register'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;10- Next we will declare a fixture. Fixtures are used to divide the list of test cases into categories. Fixtures in Selenium represent a group of tests that are targeted on one URL. Fixtures help to manage test cases with different test pages. Each fixture can represent tests on the Login Page, Registration Page, or Home Page&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  import SignupPage from "../PageModel/SignupPage";

    const url = 'https://ecommerce-playground.lambdatest.io/index.php?route=account/register'

    fixture('SignUp Page')
       .page(url)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;11- Now declare a test case named “Registration”, which is an asynchronous function that contains test code with a test controller object (t). All test actions are implemented as an async function of the test controller object t. This object is used to access the test run API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import SignupPage from "../PageModel/SignupPage";

    const url = 'https://ecommerce-playground.lambdatest.io/index.php?route=account/register'

    fixture('SignUp Page')
       .page(url)

    test("Registration", async t =&amp;gt; {

    });

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

&lt;/div&gt;



&lt;p&gt;12- Next we will use the “t.wait” function to wait for the actions to complete. When TestCafe executes a Selector query, it waits for the target element to appear in the DOM.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import SignupPage from "../PageModel/SignupPage";

    const url = 'https://ecommerce-playground.lambdatest.io/index.php?route=account/register'

    fixture('SignUp Page')
       .page(url)

    test("Registration", async t =&amp;gt; {
       await t

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

&lt;/div&gt;



&lt;p&gt;13- After that, we will use a method TestCotroller called “.typeText” which takes two parameters. The first parameter is a selector that identifies the WebElement in the DOM to receive input focus. The second parameter is the text that we intend to enter in the recently located WebElement.&lt;/p&gt;

&lt;p&gt;14- To test the radio button and submit button, we will use a method TestController called “.click”. The “.click” TestController method performs a click on the WebElement, and it takes one parameter — Selector used to identify the WebElement on the page.&lt;/p&gt;

&lt;p&gt;15- Since we already declared the selectors in the page model and imported the page model to our test file, we can just add the names we gave the selectors as our first parameter in the “.typeText” and “.click” TestController methods 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;   import SignupPage from "../PageModel/SignupPage";

    const url = 'https://ecommerce-playground.lambdatest.io/index.php?route=account/register'

    fixture('SignUp Page')
       .page(url)

    test("Registration", async t =&amp;gt; {
       await t
           .typeText(SignupPage.firstnameInput, 'John')
           .typeText(SignupPage.lastnameInput, 'Doe')
           .typeText(SignupPage.emailInput, 'johndoe@example.com')
           .typeText(SignupPage.telephoneInput, '0712345678')
           .typeText(SignupPage.passwordInput, 'Qwerty123!')
           .typeText(SignupPage.confirmInput, 'Qwerty123!')
           .click(SignupPage.agreeBtn)
           .click(SignupPage.continueBtn);
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;16- To run the test, run the command below on your command line. The command specifies the browser to use and the file that has the tests we want to be performed on the Test Page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   testcafe chrome TestCafeTests/Tests/SignupTest.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;17- TestCafe will launch the Chrome browser, navigate to the URL we specified in the fixture, and run all the tests that are a part of the test function. If everything looks good, you should be notified on the terminal that the test ran successfully.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  How to run Parallel Tests in TestCafe?
&lt;/h2&gt;

&lt;p&gt;The primary purpose of &lt;a href="https://www.lambdatest.com/blog/what-is-parallel-testing-and-why-to-adopt-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing in Selenium&lt;/a&gt; is to expedite the test execution time. The main benefits of parallel testing are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Accelerated test execution&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Increased test and browser coverage&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can execute tests in parallel using TestCafe by enabling concurrent mode, which runs multiple browser instances simultaneously.&lt;/p&gt;

&lt;p&gt;To enable concurrency while performing modern web testing with TestCafe, use the -c command-line option when running a test. To discover other TestCafe command-line options, you can run the following command in the terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  testcafe — help
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The following command invokes two Chrome instances and runs tests in parallel.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  testcafe -c 2 chrome tests/firstTest.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use concurrency when testing against multiple browsers. When setting the number of browser instances, make sure they are not more than the tests that you are running. The extra browsers will open but end up with an empty page because there are no tests left for those browsers. Extra browsers with empty pages will only lead to the consumption of system resources.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   testcafe -c 2 chrome, safari, firefox tests/firstTest.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As mentioned earlier, the primary benefit of parallel testing is to reduce testing time; if a large number of test scenarios have to be executed on the &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cloud Selenium Grid&lt;/a&gt;. To prove if this is true, we will create another test that checks if customers are able to log in to their accounts. Then we will run a normal test followed by a parallel test to compare.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new file called “LoginPage.js” in the PageModel folder and a file called “LoginTest.js” in the Tests folder as shown below:&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;2- Set up the Page Object Model in the “LoginPage.js” file 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;   import { Selector, t } from 'testcafe';

    class LoginPage {

       constructor() {
           this.emailInput = Selector('#input-email');
           this.passwordInput = Selector('#input-password');
           this.loginBtn = Selector('input.btn-primary');
       }
    }

    export default new LoginPage();

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

&lt;/div&gt;



&lt;p&gt;3- Create a login test in the “LoginTest.js” file 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;   import LoginPage from "../PageModel/LoginPage";

    const url = 'https://ecommerce-playground.lambdatest.io/index.php?route=account/login'

    fixture('Login Page')
       .page(url)

    test("Login", async t =&amp;gt; {
       await t
           .typeText(LoginPage.emailInput, 'johndoe@example.com')
           .typeText(LoginPage.passwordInput, 'Qwerty123!')
           .click(LoginPage.loginBtn);
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4- Let us now run a test using the command below and see how long the tests take to run.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   testcafe chrome TestCafeTests/Tests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see from the screenshot, it took 50 seconds to execute the two tests.&lt;/p&gt;

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

&lt;p&gt;5- Let us now see if a parallel test will take less than 50 seconds by using the command below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   testcafe -c 2 chrome TestCafeTests/Tests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see from the screenshot below, the parallel test took 37 seconds to execute the test. That means the parallel test has saved us 13 seconds. It might not be a lot but imagine how much time it would save you if you were running 100 tests or more.&lt;/p&gt;

&lt;p&gt;Test automation is highly beneficial, but sometimes it can be quite expensive, especially when testing at a large scale. To determine if test automation is worth the cost, you will need to calculate the Return On Investment (ROI). One of the metrics for evaluating the &lt;a href="https://www.lambdatest.com/blog/how-do-you-calculate-your-roi-on-test-automation-with-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;ROI of test automation&lt;/a&gt; is figuring out how much time you would save running the automatic tests.&lt;/p&gt;

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

&lt;p&gt;Execute TestCafe Script in Parallel Testing on the Cloud! &lt;a href="https://accounts.lambdatest.com/register?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=register" rel="noopener noreferrer"&gt;Try LambdaTest Now!&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to run Tests in Headless Mode in TestCafe?
&lt;/h2&gt;

&lt;p&gt;In simple terms, headless mode is running a test on a browser without the browser UI starting up or showing, meaning that the test runs in the background. Headless mode testing improves the speed and performance of your tests because the system saves the processing power that would otherwise be used in running the browser instance.&lt;/p&gt;

&lt;p&gt;TestCafe allows you to run tests in Google Chrome and Mozilla Firefox. To perform modern web testing with TestCafe in headless mode using Chrome, you can use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   testcafe chrome:headless tests/firstTest.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To run a test in headless mode using Firefox, you can use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   testcafe firefox:headless tests/firstTest.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check list of all &lt;a href="https://www.lambdatest.com/list-of-selenium-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium browsers&lt;/a&gt; on LambdaTest.&lt;/p&gt;

&lt;p&gt;This Selenium 4 complete tutorial covers everything you need to know about Selenium 4.&lt;/p&gt;

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

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

&lt;h2&gt;
  
  
  How to run Tests using TestCafe and Cloud Selenium Grid?
&lt;/h2&gt;

&lt;p&gt;In this article on modern web testing with TestCafe, you might have realized that running tests on different browsers and platform versions can be a huge hassle with the local Selenium Grid.&lt;/p&gt;

&lt;p&gt;Let’s consider a hypothetical scenario where you have a Windows machine, and you want to run cross-browser tests on (Safari + macOS) or (Firefox + Linux) combination. This is where &lt;a href="https://www.lambdatest.com/blog/cloud-selenium-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cloud Selenium testing&lt;/a&gt; can be hugely beneficial since it eliminates the need to invest in the maintenance of the in-house test infrastructure continually.&lt;/p&gt;

&lt;p&gt;Cloud Selenium Grid provides us with an option to run tests on a range of &lt;a href="https://www.lambdatest.com/intl/en-in/virtual-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;virtual browsers&lt;/a&gt;, browser versions, and operating systems securely over the cloud. LambdaTest is one such platform that provides a secure, scalable, and super reliable cloud-based Selenium Grid infrastructure that lets you run tests at scale.&lt;/p&gt;

&lt;p&gt;LambdaTest is a cloud-based &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platform that allows you to run tests on an &lt;a href="https://www.lambdatest.com/online-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;online browser farm&lt;/a&gt; of 3000+ real browsers and operating systems for mobile, desktop, and tablets. LambdaTest Selenium Grid also allows you to perform parallel testing.&lt;/p&gt;

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

&lt;p&gt;To use LambdaTest Selenium Grid together with TestCafe to run your tests, you will need a LambdaTest account.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to the &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest website&lt;/a&gt; and log in if you already have an account, or create one if you don’t have an account yet.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;2- Once you are logged in, navigate to the automation page by clicking automation on the left sidebar of your screen.&lt;/p&gt;

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

&lt;p&gt;3- To use TestCafe with LambdaTest Grid, you need LambdaTest credentials (i.e. username and access key). To get the credentials, click the “Access Key” button on the right side of your screen.&lt;/p&gt;

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

&lt;p&gt;4- Let us now save the credentials (username and access key) to environment variables LT_USERNAME and LT_ACCESS_KEY in our project.&lt;/p&gt;

&lt;p&gt;5- To save username to environment variable LT_USERNAME and access key to LT_ACCESS_KEY on Linux/Mac, run the following commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $ export LT_USERNAME= insert your username
    $ export LT_ACCESS_KEY= insert your access_key

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

&lt;/div&gt;



&lt;p&gt;6- For Windows, run the following commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $ set LT_USERNAME= insert your username
    $ set LT_ACCESS_KEY= insert your access_key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;7- To add these credentials to an environment variable in your project, run the following command on the Visual Studio command line.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;8- Then add your credentials 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;  $ export LT_USERNAME= insert your username
    $ export LT_ACCESS_KEY= insert your access_key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;9- Make sure you save the file by pressing CTRL + X and then press enter.&lt;/p&gt;

&lt;p&gt;10- LambdaTest has an npm plugin that allows you to &lt;a href="https://www.lambdatest.com/blog/testcafe-lambdatest-test-coverage/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;integrate TestCafe with LambdaTest&lt;/a&gt; for seamless &lt;a href="https://www.lambdatest.com/feature?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cross browser compatibility&lt;/a&gt; and true test coverage. You can install the plugin by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   npm install testcafe-browser-provider-lambdatest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;11- Run the below-mentioned command to have a look at the browsers supported by the LambdaTest Selenium Grid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  testcafe -b lambdatest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;12- Let us save our TestCafe credentials in our project so that our authentication on LambdaTest Selenium Grid goes through. You can save the credentials by running the commands below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   $ set LT_USERNAME=*insert your username*
    $ set LT_ACCESS_KEY=*insert your accesskey*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are now ready to run our test using TestCafe and LambdaTest Selenium Grid.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Test Case Scenarios
&lt;/h2&gt;

&lt;p&gt;As mentioned earlier, the advantage of using Cloud Selenium Grid is to have an option of testing on multiple browser versions and operating systems. In our case, we will use three test combinations to test whether our e-commerce website registration and login form work as expected. These combinations are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Chrome 85.0 + macOS Catalina&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Firefox 78.0 + Windows 10&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Chrome 86.0 + Windows 11&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ol&gt;
&lt;li&gt;To define your desired set of browser and operating system combinations, you can use &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest Capabilities Generator&lt;/a&gt; as shown below:&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;2- After setting your desired combinations, create a file called config.json and add your combinations as shown below without changing the code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FileName — config.json&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;   {
       "Chrome@85.0:MacOS Catalina": {
           "build": "TestCafe Demo",
           "network": true,
           "visual": true,
           "resolution": "1024x768"
       },


       "Firefox@78.0:Windows 10": {
           "build": "TestCafe Demo",
           "network": true,
           "visual": true,
           "resolution": "1024x768"
       },


       "Chrome@86.0:Windows 11": {
           "build": "TestCafe Demo",
           "network": true,
           "visual": true,
           "resolution": "1024x768"
       }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3- To run a test on (Chrome 85.0 + MacOS Catalina) combination, run the command below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    testcafe "lambdatest:Chrome@85.0:MacOS Catalina" TestCafeTests/Tests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4- To run a test on (Firefox 78.0 + Windows 10) Combination, run the command below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    testcafe "lambdatest:Firefox@78.0:Windows 10" TestCafeTests/Tests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5- To run a test on (Chrome 85.0 + Windows 11) Combination, run the command below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    testcafe "lambdatest:Chrome@85.0:Windows 11" TestCafeTests/Tests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;6- In case there are no issues with the test code, you should have the message on your Visual Studio Code Terminal that the test was successful for each combination.&lt;/p&gt;

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

&lt;p&gt;7- If you visit your &lt;a href="https://accounts.lambdatest.com/dashboard?_gl=1*kyd76b*_gcl_aw*R0NMLjE2NzEyMDUzMTMuQ2p3S0NBaUF5X0NjQmhCZUVpd0Fjb01SSEZSdHVkQmhsa3JrQklIc2V5Zmk1MTR6N29yZVZwaDhHeHF0UEl2eU8yWkJGZThELUhBenpCb0NjMXNRQXZEX0J3RQ..?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=login" rel="noopener noreferrer"&gt;LambdaTest Dashboard&lt;/a&gt; on the right side of your screen, you should be able to see your recent tests, as shown below.&lt;/p&gt;

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

&lt;p&gt;8- If you click on one of the tests, you will be redirected to the Automation Dashboard, where all the information about the test is available. This information includes a video and a screenshot that shows you how the test went.&lt;/p&gt;

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

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

&lt;p&gt;This certification will acknowledge your expertise in the use of JavaScript to create automated browser tests. Here’s a short glimpse of the Selenium JavaScript 101 certification from LambdaTest:&lt;/p&gt;

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

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

&lt;h2&gt;
  
  
  How to run a Parallel Test on TestCafe and Cloud Selenium Grid?
&lt;/h2&gt;

&lt;p&gt;In Selenium, &lt;a href="https://www.lambdatest.com/blog/what-is-parallel-testing-and-why-to-adopt-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing&lt;/a&gt; can be described as a method of testing that you can use to run tests simultaneously in different environments such as browser versions and operating systems.&lt;/p&gt;

&lt;p&gt;One of the main benefits of parallel testing on TestCafe and Cloud Selenium Grid is that it accelerates test execution while saving time, especially when testing at a larger scale. Also, parallel testing in Selenium is cost-effective and has a higher Return On Investment (ROI) compared to sequential testing.&lt;/p&gt;

&lt;p&gt;Sequential testing is a tedious process requiring development, maintenance, and keeping the test environment updated all the time. Managing all these factors can be costly compared to parallel testing in Selenium, which is automated and cloud-based.&lt;/p&gt;

&lt;p&gt;To run a parallel test on LambdaTest Cloud Selenium Grid on browser and operating system combinations that we used earlier, you can run the command below on your Visual Studio Code editor terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    testcafe "lambdatest:Chrome@85.0:MacOS Catalina","lambdatest:Firefox@78.0:Windows 10","lambdatest:Chrome@85.0:Windows 11" TestCafeTests/Tests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see from the screenshot below, the tests ran successfully on all combinations.&lt;/p&gt;

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

&lt;p&gt;Once the tests have run successfully, log in to LambdaTest Automation Dashboard to check the status of the test execution. You can also access the report on &lt;a href="https://analytics.lambdatest.com/test-overview?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Analytics Dashboard&lt;/a&gt;, which shows all the details and metrics related to your tests.&lt;/p&gt;

&lt;p&gt;Test Summary gives you a high-level overview of your test performance by showing you how many tests passed and failed. Below is a screenshot with all details and metrics related to tests that I run on Cloud Selenium Grid and TestCafe JavaScript end-to-end &lt;a href="https://www.lambdatest.com/web-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec26_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;web testing&lt;/a&gt;.&lt;/p&gt;

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

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

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

&lt;p&gt;The idea behind TestCafe is to solve common challenges developers and testers face with testing tools like Selenium. However, the integration of Cloud Selenium Grid and TestCafe JavaScript helps you to scale up your testing environment without spending a lot of money to set up an in-house grid infrastructure. I hope you enjoyed this article on performing modern web testing with TestCafe! 🙂&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>TestCafe Tutorial: How To Select Page Elements Using TestCafe Selectors</title>
      <dc:creator>Bonnie</dc:creator>
      <pubDate>Fri, 23 Dec 2022 13:05:48 +0000</pubDate>
      <link>https://dev.to/testmuai/testcafe-tutorial-how-to-select-page-elements-using-testcafe-selectors-1lnc</link>
      <guid>https://dev.to/testmuai/testcafe-tutorial-how-to-select-page-elements-using-testcafe-selectors-1lnc</guid>
      <description>&lt;p&gt;Let’s assume you want to build or create a web page as a web developer. First, you will create an HTML file that comprises semantic and non-semantic elements (e.g. &amp;lt; header &amp;gt;, &amp;lt; section &amp;gt;, and &amp;lt; footer &amp;gt; are examples of semantic elements). &amp;lt; div &amp;gt;, &amp;lt; span &amp;gt;, &amp;lt; h1 &amp;gt;, and &amp;lt; p &amp;gt; are examples of non-semantic elements.&lt;/p&gt;

&lt;p&gt;You must &lt;a href="https://www.lambdatest.com/blog/html-dialog-element/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;style the HTML elements &lt;/a&gt;using CSS to ensure the web page is super-responsive on different viewport sizes. The best way to style an HTML element is by targeting it using &lt;a href="https://www.lambdatest.com/blog/how-pro-testers-use-css-selectors-in-selenium-automation-scripts/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;CSS Selectors.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For instance, you could provide a unique id or class for styling the &amp;lt; header &amp;gt; element. The id and class attributes make it easier to target the &amp;lt; header &amp;gt; element and add styling to it on a CSS file. Therefore, there is a provision to add the id and class attributes by writing HTML code that looks like &amp;lt; header id=”header” &amp;gt; and &amp;lt; header class=”header” &amp;gt;.&lt;/p&gt;

&lt;p&gt;What do CSS Selectors have in common with TestCafe Selectors? Before answering that question, let us first understand what is TestCafe and what are TestCafe Selectors in this TestCafe tutorial.&lt;/p&gt;

&lt;p&gt;By the end of this TestCafe tutorial on TestCafe Selectors, you will have learned how to use TestCafe Selectors for selecting elements on the web page.&lt;/p&gt;

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

&lt;p&gt;TestCafe is a Node.js-based open-source &lt;a href="https://www.lambdatest.com/blog/best-test-automation-frameworks-2021/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing framework&lt;/a&gt; that can be majorly used for &lt;a href="https://www.lambdatest.com/learning-hub/end-to-end-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;End to End (E2E) testing&lt;/a&gt; of web applications. TestCafe supports both JavaScript and TypeScript.&lt;/p&gt;

&lt;p&gt;As a web developer and technical writer, I have been working on a portfolio website that helps me showcase my expertise. However, how can I ensure that the website does what I expect it to do when viewed on different browsers and operating systems? This is where I leverage the benefits of end-to-end (E2E) testing.&lt;/p&gt;

&lt;p&gt;I can run &lt;a href="https://www.lambdatest.com/blog/modern-web-testing-with-testcafe/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;End to End tests using TestCafe&lt;/a&gt; because it does not require any external dependencies like &lt;a href="https://www.lambdatest.com/learning-hub/webdriver?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;WebDriver&lt;/a&gt; (in the case of Selenium). Also, TestCafe uses the browsers I already have on my machine.&lt;/p&gt;

&lt;p&gt;At the time of writing this TestCafe tutorial, TestCafe had 9.4K stars and 659 forks, and the latest version was 1.20.1.&lt;/p&gt;

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

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

&lt;h2&gt;
  
  
  What are TestCafe Selectors?
&lt;/h2&gt;

&lt;p&gt;TestCafe Selectors are selectors that filter a web page and return page elements that match specified user-defined criteria. In simple terms, TestCafe Selectors target page elements you want to test, akin to how CSS Selectors target the HTML elements you want to style.&lt;/p&gt;

&lt;p&gt;For example, let’s consider a form on a web page with two inputs and a submit button. If you wanted to style the input elements and the button, you would have to target them using CSS Selectors, as you mentioned earlier.&lt;/p&gt;

&lt;p&gt;What if you wanted to test whether a user can fill in the form and submit the input data using Testcafe?&lt;/p&gt;

&lt;p&gt;TestCafe can identify the form inputs and buttons using TestCafe Selectors (like CSS selectors), as they both take advantage of unique ids or class attributes to locate the elements.&lt;/p&gt;

&lt;p&gt;In this TestCafe tutorial on TestCafe Selectors, we will go through different types of TestCafe Selectors and learn how to use them to find page elements that you want to test.&lt;/p&gt;

&lt;p&gt;Run TestCafe Tests on the cloud! &lt;a href="https://accounts.lambdatest.com/register?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=register" rel="noopener noreferrer"&gt;Try LambdaTest Now!&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to install TestCafe?
&lt;/h2&gt;

&lt;p&gt;In this section of this TestCafe tutorial on how to use TestCafe Selectors to select page elements, you will learn how to install TestCafe and use TestCafe Selectors. To install and use TestCafe in your system, you need an IDE, Node.js, and Node Package Manager (NPM) installed.&lt;/p&gt;

&lt;p&gt;I will use Visual Studio Code as the IDE for the demonstration. However, you can use the IDE of your choice.&lt;/p&gt;

&lt;p&gt;To install TestCafe on your machine, please follow the steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Create a folder called &lt;em&gt;“TestCafeSelectors,”&lt;/em&gt; then right-click on the folder and open it using Visual Studio Code.&lt;/p&gt;

&lt;p&gt;Once the “TestCafeSelectors” folder has opened on VS Code, open the terminal on VS Code by clicking the “Terminal” option on the top of your VS Code window, and then select “New Terminal,” as shown below.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Run the command below on your terminal to install TestCafe.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; npm install testcafe
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Once the installation is done, run the command below to see the version of TestCafe installed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    testcafe -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: Run the command below to create a package.json file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  npm init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The package.json file represents various metadata relevant to your project. The package.json file also helps NPM identify the project’s information and dependencies.&lt;/p&gt;

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

&lt;p&gt;If you open the &lt;em&gt;package.json&lt;/em&gt; file, it should look as shown above. The only thing we now need is to add TestCafe as a dependency for our project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt;: Run the command below to add TestCafe as a dependency to the project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; npm install testcafe
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you find that TestCafe has been added as one of the dependencies.&lt;/p&gt;

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

&lt;p&gt;Before we go through different types of TestCafe Selectors and learn how to use them to target page elements that you want to test, let me talk about the &lt;a href="https://www.lambdatest.com/blog/using-page-object-model-pattern-in-javascript-with-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Page Object Model.&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: &lt;a href="https://www.lambdatest.com/xcuitest?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;XCUITest&lt;/a&gt;: A Detailed Guide To XCUITest Framework&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Page Object Model
&lt;/h2&gt;

&lt;p&gt;Page Object Model, also known as POM, is a design pattern commonly used by testers when performing &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automation testing&lt;/a&gt;. The primary aim of the Page Object Model is to avoid code duplication and enhance code reusability. The &lt;a href="https://www.lambdatest.com/blog/page-object-model-in-selenium-python/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;POM design pattern&lt;/a&gt; is more programmer-friendly, making it easier to maintain and enhance test code.&lt;/p&gt;

&lt;p&gt;As mentioned earlier in this TesCafe tutorial on TestCafe Selectors, &lt;a href="https://www.lambdatest.com/blog/best-test-automation-frameworks-2021/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation frameworks&lt;/a&gt; like TestCafe help navigate a web page and perform relevant actions with the WebElements that are targeted using the appropriate TestCafe Selectors.&lt;/p&gt;

&lt;p&gt;The Page Object Model houses all the WebElements, actions, and validations happening on a page in one single Page Object. The POM directs us to create an object representing the UI of the page we want to test.&lt;/p&gt;

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

&lt;p&gt;The &lt;a href="https://www.lambdatest.com/blog/using-page-object-model-pattern-in-javascript-with-selenium/#Advantages?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;benefits of using the Page Object Model&lt;/a&gt; are more prevalent when testing complex and large-scale applications. Adopting the POM design pattern can be a huge time and cost saver on large-scale applications. The reason is that these applications are only expected to grow larger and more complex with every software release.&lt;/p&gt;

&lt;p&gt;Improved maintenance reduces the overhead costs involved in enhancing the test code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing Page Object Model
&lt;/h2&gt;

&lt;p&gt;As a developer, tester, or SQE, you should habitually implement the Page Object Model in your project.&lt;/p&gt;

&lt;p&gt;Let’s look at how the Page Object Model can be implemented in a test case that demonstrates how to choose page elements using TestCafe Selectors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Create a new folder in your project and name it “TestCase” in the path “TestCafeSelectors/TestCase”.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: In the “TestCafe” folder, create two other folders called “PageModel” and “Tests”.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: In the “PageModel” folder, create a file called “selectors.js” in the path “TestCafeSelectors/TestCase/PageModel/selectors.js” as shown below.&lt;/p&gt;

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

&lt;p&gt;The next step is to set up the Page Object Model to demonstrate how to use TestCafe Selectors to locate page elements. However, before I show you how to do that, let us assume you have an e-commerce website.&lt;/p&gt;

&lt;p&gt;On this e-commerce website, customers have to register or create an account for them to be able to check out items they have added to the cart. Now, how can you ensure that customers can register successfully without any issues?&lt;/p&gt;

&lt;p&gt;To ensure that the registration form works as expected, you can use TestCafe to run an automated test where TestCafe simulates the customer interaction with the inputs and buttons on the registration page.&lt;/p&gt;

&lt;p&gt;To demonstrate how to use TestCafe Selectors to select page elements, I will be using the LambdaTest e-commerce playground. To set up the Page Object Model for this project, declare the “TestCafeSelectors” class in the “selectors.js” file and export its instance 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;  class TestCafeSelectors {

       constructor() {
       }
    }

    export default new TestCafeSelectors();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next step is to import the Selector function on top of the “selectors.js” file. After that, let us add properties and assign a selector to them inside the constructor.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: Test On &lt;a href="https://www.lambdatest.com/test-on-iphone-simulator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;iPhone tester&lt;/a&gt; Simulator On Cloud&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use TestCafe Selectors to select page elements?
&lt;/h2&gt;

&lt;p&gt;Before performing any selector operation, you must find an XPath path to interact with the element. Some ways to get the element path are by ID, className, a unique attribute such as p, div, h1, or creating a custom XPath where you create relations between elements like child, parent, or sibling.&lt;/p&gt;

&lt;p&gt;You can now see how TestCafe Selectors are closely related to CSS selectors. Let us now see some TestCafe element selector examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  Selecting page elements by ID
&lt;/h2&gt;

&lt;p&gt;To learn how to select a page element by ID, navigate to the e-commerce website registration page I mentioned earlier. Inspect the web page and get the &lt;a href="https://www.lambdatest.com/blog/making-the-move-with-id-locator-in-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;ID locator&lt;/a&gt; of “First Name” input which the user is expected to fill when registering for an account, as shown below.&lt;/p&gt;

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

&lt;p&gt;The next step is to add the “First Name” ID locator to the Page Object Model. To do this, let us introduce the “firstnameInput” property and assign a selector to it.&lt;/p&gt;

&lt;p&gt;To assign a selector to the “firstnameInput,” we must import it at the top of the “selectors.js” file from TestCafe. The “selectors.js” file should now look 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;  import { Selector, t } from 'testcafe';

    class TestCafeSelectors {

       constructor() {
           this.firstnameInput = Selector('#input-firstname');
       }
    }

    export default new TestCafeSelectors();

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

&lt;/div&gt;



&lt;p&gt;Let’s now create a test case that opens the browser, navigates to the e-commerce website registration page URL, and enters “John” into the “First Name” input field. Note that the test will use the existing directory structure we discussed earlier.&lt;/p&gt;

&lt;p&gt;In our project’s “Tests” folder, create a file called “SelectorsTest.js,” as shown below.&lt;/p&gt;

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

&lt;p&gt;In the “SelectorsTest.js” file, at the top, import the page model instance named “TestCafeSelectors” from the “Selectors.js” file in the PageModel folder, 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;    import TestCafeSelectors from “../PageModel/Selectors”;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After adding the page model module, let us create a variable called “pageURL” that will hold the e-commerce website URL, 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;   import TestCafeSelectors from "../PageModel/Selectors";

    const pageURL =   'https://ecommerce-playground.lambdatest.io/index.php?route=account/register'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, let us declare a fixture named “Registration Page” 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;    import TestCafeSelectors from "../PageModel/Selectors";

    const pageURL = 'https://ecommerce-playground.lambdatest.io/index.php?route=account/register'

    fixture('Registration Page')
       .page(pageURL)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that fixtures are used to divide the list of test cases into categories. They help to manage test cases with different test pages. For example, each fixture can represent tests on the Product Page, Check Out Page, or Home Page.&lt;/p&gt;

&lt;p&gt;Let us now create a test named “FirstName,” 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;    import TestCafeSelectors from "../PageModel/Selectors";

    const pageURL = 'https://ecommerce-playground.lambdatest.io/index.php?route=account/register'

    fixture('Registration Page')
       .page(pageURL)

    test("FirstName", async t =&amp;gt; {

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

&lt;/div&gt;



&lt;p&gt;The test case we declared above is an asynchronous function that contains test code with a test controller object(t). Note that all test actions are implemented as an async function of the test controller t, which is used to access the test run API.&lt;/p&gt;

&lt;p&gt;When TestCafe executes a Selector query, it waits for the target element to appear in the DOM. To learn more about it, you can go through this blog on &lt;a href="https://www.lambdatest.com/blog/types-of-waits-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;handling waits in Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To enable TestCafe to wait for the target element to load, let us add the “t.wait” function into our “FirstName” test 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;   import TestCafeSelectors from "../PageModel/Selectors";

    const pageURL = 'https://ecommerce-playground.lambdatest.io/index.php?route=account/register'

    fixture('Registration Page')
       .page(pageURL)

    test("FirstName", async t =&amp;gt; {
       await t

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Understanding t.wait Function In TestCafe&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Wait commands are important for test automation frameworks such as TestCafe and Selenium. Including wait commands in your test code helps the testing framework to wait for a web page to load or an element to appear on the web page. If wait commands are not used, &lt;a href="https://www.lambdatest.com/blog/49-common-selenium-exceptions-automation-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Element Not Found Exceptions&lt;/a&gt; might occur.&lt;/p&gt;

&lt;p&gt;TestCafe has six types of wait commands or mechanisms. These commands or mechanisms are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Wait Method.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wait Mechanism for Actions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wait Mechanism for Selectors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wait Mechanism for Assertions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wait Mechanism for XHR and Fetch Requests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wait Mechanism for Redirect.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The t.wait Function is part of the second wait mechanism, which automatically waits for the element to become visible before an action is executed. Note that an element must be interactable before an operation can be performed on it.&lt;/p&gt;

&lt;p&gt;TestCafe actions can interact with elements if they satisfy the following conditions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;An element is within the &amp;lt; body &amp;gt; element of a page window or an &amp;lt; iframe &amp;gt; window.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An element is visible.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An element is not overlapped.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;TestCafe automatically waits for the target element to become visible when running a test. It tries to evaluate the specified selector multiple times within the timeout. If the element does not appear, the test will fail.&lt;/p&gt;

&lt;p&gt;With the “t.wait” function in place, let us now use a method TestController called “typeText.” The TestController takes two parameters; where the first parameter is a selector that identifies the page element in the DOM to receive input focus.&lt;/p&gt;

&lt;p&gt;The second parameter is the text we intend to enter in the selected page element, which in our case is “John.” The .typeText syntax looks as shown below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;t.typeText(selector, text)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Since we already declared the Selector in the page model and imported it to our test file, let us add “firstnameInput’, which is the name we gave the selector, as our first parameter in the “.typeText” TestController as shown below in the final code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import TestCafeSelectors from "../PageModel/Selectors";

    const pageURL = 'https://ecommerce-playground.lambdatest.io/index.php?route=account/register'

    fixture('Registration Page')
       .page(pageURL)

    test("FirstName", async t =&amp;gt; {
       await t
           .typeText(TestCafeSelectors.firstnameInput, 'John')
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make sure that TestCafe is able to select the “First Name” input element and type the name “John,” run the command below on your command line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    testcafe chrome TestCase/Tests/SelectorsTest.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the command specifies the browser to use and the file that has the test we want to be performed on the Test Web Page.&lt;/p&gt;

&lt;p&gt;TestCafe will launch the Chrome browser, navigate the e-commerce website registration page URL and enter the name “John” into the “First Name” input field.&lt;/p&gt;

&lt;p&gt;If there are no errors, you should be notified on the terminal that the test ran successfully, as shown below.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: Test On &lt;a href="https://www.lambdatest.com/android-emulator-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Android Emulator&lt;/a&gt; Online. Test your web and mobile apps on Android Emulators online.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Selecting page elements by Class Name
&lt;/h2&gt;

&lt;p&gt;In this section of this TestCafe tutorial, we will learn to select page elements by &lt;a href="https://www.lambdatest.com/blog/selenium-java-tutorial-class-name-locator-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Class Name locator.&lt;/a&gt; Let us consider a page on which you want to interact with an element with no ID. What can be done in such cases? The first thing you need to do is to check whether the page element has a class name.&lt;/p&gt;

&lt;p&gt;For example, when you inspect the e-commerce website registration page to get ID locators, you will find that the “Continue” submit button has no ID. To enable TestCafe to locate the button, you need to get the submit button class name, then add “input.” before the class instead of “#,” which represents ID locators.&lt;/p&gt;

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

&lt;p&gt;In the test case project, the first step is to add the “Continue” submit button class name locator to the Page Object Model.&lt;/p&gt;

&lt;p&gt;To do that, let us introduce the “continueBtn” property and assign a selector to it, as shown below on the “selectors.js” file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  import { Selector, t } from 'testcafe';

    class TestCafeSelectors {

       constructor() {
           this.continueBtn = Selector('input.btn-primary');
       }
    }

    export default new TestCafeSelectors();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To test the submit button, let us use a method TestController called “.click,” which performs a click on the page element. The TestController takes one parameter, which is used to identify the page element. To learn more about it, you can refer to this blog on the &lt;a href="https://www.lambdatest.com/blog/selenium-click-button-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium click method button&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once you have imported the page model to your test file, the “SelectorsTest.js” file should now look as shown below in the snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import TestCafeSelectors from "../PageModel/Selectors";

    const pageURL = 'https://ecommerce-playground.lambdatest.io/index.php?route=account/register'

    fixture('Registration Page')
       .page(pageURL)

    test("SubmitButton", async t =&amp;gt; {
       await t
           .click(TestCafeSelectors.continueBtn)
    });

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

&lt;/div&gt;



&lt;p&gt;Run the command below, and TestCafe can select the submit button as it was able to select the “First Name” input when locating an element using ID.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    testcafe chrome TestCase/Tests/SelectorsTest.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h2&gt;
  
  
  Selecting page elements by Attribute
&lt;/h2&gt;

&lt;p&gt;When selecting a page element by attribute, you use a Selector.withAttribute method, which finds elements with the specified attribute or attribute value. The syntax of the method looks 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;   Selector().withAttribute(attrName [, attrValue]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Attribute name (attrName) is case-sensitive together with attribute value (attrValue), but attribute value is optional.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding Attribute Name and Attribute Value&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Attributes are used to give more meaning to HTML tags, where they define additional characteristics or properties of the page element. Attributes are always specified in the start or opening tag, where they usually consist of attribute name and value pairs such as name=”value.” Note that attribute values should always be enclosed in quotation marks.&lt;/p&gt;

&lt;p&gt;In the example below, “for” inside the &amp;lt; label &amp;gt; tag is an attribute name, while “input-firstname” is the attribute value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;label for=”input-firstname”&amp;gt; &amp;lt;/label&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let us assume that you want to test the “First Name” input element on the e-commerce website page I mentioned earlier, but it has no ID or Class Name locators.&lt;/p&gt;

&lt;p&gt;What you can do is check whether the input has any attributes. In this case, the “First Name” input tag has attribute name “name” and attribute value “firstname,” as shown below.&lt;/p&gt;

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

&lt;p&gt;To see if TestCafe can locate the “First Name” input element by attribute, the page model code in the “Selectors.js” file should look 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;    import { Selector, t } from 'testcafe';

    class TestCafeSelectors {

       constructor() {
           this.firstnameInput = Selector('input').withAttribute("name", "firstname");
       }
    }

    export default new TestCafeSelectors();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Import the Page Object Model to the “SelectorsTest.js” file and the code should look 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;  import TestCafeSelectors from "../PageModel/Selectors";

    const pageURL = 'https://ecommerce-playground.lambdatest.io/index.php?route=account/register'

    fixture('Registration Page')
       .page(pageURL)

    test("FirstName", async t =&amp;gt; {
       await t
           .typeText(TestCafeSelectors.firstnameInput, 'John')
    });

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

&lt;/div&gt;



&lt;p&gt;Run the command below and see if the test runs successfully.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;testcafe chrome TestCase/Tests/SelectorsTest.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After hitting the enter button to run the command on the command line, you will run into the error below.&lt;/p&gt;

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

&lt;p&gt;The issue is that TestCafe waits for the browser to be ready but times out before the browser is ready. The solution is to increase the value of the “browserInitTimeout” option, which will give enough wait time until the browser is ready.&lt;/p&gt;

&lt;p&gt;To give TestCafe more wait time, add “.wait(5000)” to your code in the “SelectorsTest.js” file, 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;   import TestCafeSelectors from "../PageModel/Selectors";

    const pageURL = 'https://ecommerce-playground.lambdatest.io/index.php?route=account/register'

    fixture('Registration Page')
       .page(pageURL)

    test("FirstName", async t =&amp;gt; {
       await t
           .typeText(TestCafeSelectors.firstnameInput, 'John')
           .wait(5000)
    });


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

&lt;/div&gt;



&lt;p&gt;Run the test command and you should be notified on the terminal that the test ran successfully as shown below.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Selecting page elements by custom XPath
&lt;/h2&gt;

&lt;p&gt;XPath is a technique used to navigate through the HTML structure of a page. It can be used to navigate both HTML and XML documents. XPath provides an option to search for an element within a web page dynamically. You can refer to this &lt;a href="https://www.lambdatest.com/blog/most-exhaustive-xpath-locators-cheat-sheet/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;XPath cheat sheet&lt;/a&gt; to learn more about &lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;XPath locators&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To use Custom XPath in TestCafe to select a page element, you must create a custom function and import it into your test file. Let us implement Custom XPath in our project by creating a file named “XPathSelector.js” in the PageModel folder, as shown below.&lt;/p&gt;

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

&lt;p&gt;In the “XPathSelector.js” file, import Selector from TestCafe at the top and create a custom function named “getElementsByXPath.” Then export the function at the bottom. Your code in the “XPathSelector.js” should look 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;  import { Selector } from 'testcafe';

    const getElementsByXPath = Selector(xpath =&amp;gt; {
       const iterator = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
       const items = [];

       let item = iterator.iterateNext();

       while (item) {
           items.push(item);
           item = iterator.iterateNext();
       }

       return items;
    });

    export default function (xpath) {
       return Selector(getElementsByXPath(xpath));
    }

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

&lt;/div&gt;



&lt;p&gt;The next step is to import XPathSelector from “XPathSelector.js” at the top of the “Selectors.js” file in the PageModel folder to use the “getElementsByXPath” function.&lt;/p&gt;

&lt;p&gt;Let us now use the XPathSelector in the Page Object Model, which targets elements with the custom path “//*[&lt;a class="mentioned-user" href="https://dev.to/id"&gt;@id&lt;/a&gt;=’input-firstname]” as shown below.&lt;/p&gt;

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

&lt;p&gt;Your code in the “Selectors.js” file should look 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;    import { Selector, t } from 'testcafe';
    import XPathSelector from './XPathSelector';

    class TestCafeSelectors {

       constructor() {
           this.firstnameInput = XPathSelector("//*[@id='input-firstname']");
       }
    }

    export default new TestCafeSelectors();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let us now create a test case that uses the Page Object Model in “SelectorsTest.js” file in the Tests folder. In the test, TestCafe opens a browser instance, navigates to the e-commerce website registration page URL, and enters “John” into the “First Name” input selected by custom XPath “//*[&lt;a class="mentioned-user" href="https://dev.to/id"&gt;@id&lt;/a&gt;=’input-firstname]”.&lt;/p&gt;

&lt;p&gt;Your code in the “SelectorsTest.js” file should now look 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;    import TestCafeSelectors from "../PageModel/Selectors";

    const pageURL = 'https://ecommerce-playground.lambdatest.io/index.php?route=account/register'

    fixture('Registration Page')
       .page(pageURL)

    test("FirstName", async t =&amp;gt; {
       await t
           .typeText(TestCafeSelectors.firstnameInput, 'John')
           .wait(5000)
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the command below to see if TestCafe is able to locate the “First Name” input element and enter “John”.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    testcafe chrome TestCase/Tests/SelectorsTest.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If there are no errors, you should be notified on the terminal that the test ran successfully, as shown below.&lt;/p&gt;

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

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

&lt;h2&gt;
  
  
  Selecting page elements by relations
&lt;/h2&gt;

&lt;p&gt;Apart from selecting a page element using TestCafe with the methods mentioned above, TestCafe provides other methods to select a page element by relations between elements. Relations between elements include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Parent&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Child&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sibling&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every web page comprises an HTML document referred to as a document tree. Elements in the document tree can be described as a family tree where there are parents, children, and siblings.&lt;/p&gt;

&lt;p&gt;A parent is an element directly above and connected to an element in the document tree. A child is directly below and connected to an element in the document tree. A sibling is an element that shares the same parent with another element.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Selector.parent Method
&lt;/h3&gt;

&lt;p&gt;The Selector.parent Method has three types of syntax which are parent(), parent(index) and parent(cssSelector).&lt;/p&gt;

&lt;p&gt;The first method syntax looks as shown below, and it returns an array of parent elements, starting with the closest relatives.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Here is how you can use the method in an example that selects all ancestors of all div elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   import { Selector, t } from 'testcafe';

    class TestCafeSelectors {

       constructor() {
           this.inputClosestParents = Selector('input').parent(0);
       }
    }

    export default new TestCafeSelectors();

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

&lt;/div&gt;



&lt;p&gt;Here is how you can use the method in an example that selects all furthest ancestors of all inputs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   import { Selector, t } from 'testcafe';

    class TestCafeSelectors {

       constructor() {
           this.inputFurthestParents = Selector('input').parent(-1);
       }
    }

    export default new TestCafeSelectors();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The third method syntax looks as shown below and it looks for parent elements that match the CSS Selector parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Selector().parent(cssSelector)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is how you can use the method in an example that selects all divs that are ancestors of a form element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   import { Selector, t } from 'testcafe';

    class TestCafeSelectors {

       constructor() {
           this.formDivParents = Selector('form').parent(‘div’);
       }
    }

    export default new TestCafeSelectors();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Selector.child Method
&lt;/h3&gt;

&lt;p&gt;The Selector.child Method has three types of syntax which are child(), child(n), and child(cssSelector). The first method syntax looks as shown below, and it returns an array of child elements, starting with direct descendants.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;The method can be used in an example that selects all children of a form element, 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;   import { Selector, t } from 'testcafe';

    class TestCafeSelectors {

       constructor() {
           this.formChildren = Selector('form').child();
       }
    }

    export default new TestCafeSelectors();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second method syntax looks as shown below, and it returns an array of n-th closest descendant elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Selector().child(n)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If n is negative, the method returns an array of n-th most distant descendant elements.&lt;/p&gt;

&lt;p&gt;The method can be used in an example that selects all the closest children of all div elements, 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;    import { Selector, t } from 'testcafe';

    class TestCafeSelectors {

       constructor() {
           this.formChildren = Selector('form').child();
       }
    }

    export default new TestCafeSelectors();

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

&lt;/div&gt;



&lt;p&gt;The second method syntax looks as shown below, and it returns an array of n-th closest descendant elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    Selector().child(n)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If n is negative, the method returns an array of n-th most distant descendant elements.&lt;/p&gt;

&lt;p&gt;The method can be used in an example that selects all the closest children of all div elements, 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;    import { Selector, t } from 'testcafe';

    class TestCafeSelectors {

       constructor() {
           this.divClosestChildren = Selector('div').child(0);
       }
    }

    export default new TestCafeSelectors();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The method can also be used in an example that selects all furthest children of all div elements 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;   import { Selector, t } from 'testcafe';

    class TestCafeSelectors {

       constructor() {
           this.divFurthestChildren = Selector('div').child(-1);
       }
    }

    export default new TestCafeSelectors();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The third method syntax looks as shown below and it looks for element descendants that match the CSS Selector argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    Selector().child(cssSelector)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The method can be used in an example that selects all input elements that are children of a form element, 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;   import { Selector, t } from 'testcafe';

    class TestCafeSelectors {

       constructor() {
           this.formInputChildren = Selector('form').child(‘input’);
       }
    }

    export default new TestCafeSelectors();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Selector.sibling Method
&lt;/h3&gt;

&lt;p&gt;The Selector.child Method has three types of syntax which are sibling(), sibling(n), and sibling(cssSelector). The first method syntax looks as shown below, and it returns an array of sibling elements, starting with the closest relatives.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;The method can be used in an example that selects all siblings of all input elements, 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;  import { Selector, t } from 'testcafe';

    class TestCafeSelectors {

       constructor() {
           this.inputSiblings = Selector('input').sibling();
       }
    }

    export default new TestCafeSelectors();

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

&lt;/div&gt;



&lt;p&gt;The second method syntax looks as shown below and it returns an array of n-th closest sibling nodes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    Selector().sibling(n)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If n is negative, the method returns an array of n-th most distant descendant sibling nodes.&lt;/p&gt;

&lt;p&gt;The method can be used in an example that selects all div elements’ siblings that go first in their parent’s child list 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;   import { Selector, t } from 'testcafe';

    class TestCafeSelectors {

       constructor() {
           this.divClosestSiblings = Selector('div').sibling(0);
       }
    }

    export default new TestCafeSelectors();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The method can also be used in an example that selects all form elements siblings that go last in their parent’s child lists, 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;    import { Selector, t } from 'testcafe';

    class TestCafeSelectors {

       constructor() {
           this.inputFurthestSiblings = Selector('input').sibling(-1);
       }
    }

    export default new TestCafeSelectors();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The third method syntax looks as shown below and it looks for element siblings that match the CSS Selector argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Selector().child(cssSelector)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The method can be used in an example that selects all input elements that are succeeding siblings of a form element, 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;
    import { Selector, t } from 'testcafe';

    class TestCafeSelectors {

       constructor() {
           this.formInputSibling = Selector('form').sibling(‘input’);
       }
    }

    export default new TestCafeSelectors();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Accessing Shadow DOM
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/shadow-dom-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Shadow DOM&lt;/a&gt; is a DOM tree with elements and styles isolated from the DOM. Shadow DOM differs from the regular DOM in that the main CSS does not affect the styling.&lt;/p&gt;

&lt;p&gt;The Shadow DOM is completely encapsulated, keeping the markup structure, style, and behavior hidden and separate from other codes. The encapsulation is so that different parts do not clash, and the code can be kept nice and clean.&lt;/p&gt;

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

&lt;p&gt;Some examples of shadow DOM are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Embedded forms.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Embedded tweets.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Embedded YouTube videos.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Chat pop-ups.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When testing, you cannot access shadow DOM elements directly. To interact with the shadow DOM in TestCafe, identify the root node of a shadow tree, and use other selector methods to traverse it. You can identify the root node of a shadow tree using Selector.shadowRoot Method.&lt;/p&gt;

&lt;h2&gt;
  
  
  Selector.shadowRoot Method
&lt;/h2&gt;

&lt;p&gt;This method returns the shadow root node chain to other methods to traverse the shadow DOM. The method returns null if the shadow DOM is not open and its syntax looks 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; selector.shadowRoot()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The example below shows how to identify the root node, access the shadow tree, and return the &amp;lt; p &amp;gt; element from the shadow DOM.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   import { Selector } from 'testcafe';

    fixture`ShadowDOM`
       .page`https://devexpress.github.io/testcafe/example/`;

    test('ShadowDOM Test', async t =&amp;gt; {
       const shadowRoot = Selector('div').withAttribute('id', 'shadow-host').shadowRoot();
       const paragraph = shadowRoot.child('p');

       await t.expect(paragraph.textContent).eql('This paragraph is in the shadow tree');

       try {
           await t.click(shadowRoot);
       }
       catch (error) {
           await t.expect(error.code).eql('E27');
       }
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s have a walkthrough of the code above.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; The selector function is imported from TestCafe to be used in the test code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; A fixture called “ShadowDOM” is declared, where it represents a group of tests targeted by one URL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; The Test.page method is used to specify the URL of the web page being tested.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; A test case called “ShadowDOM Test” is declared, where it is an asynchronous function that contains test code with a test controller object (t).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; A variable called “shadowRoot” is declared where its value is a “selector.shadowRoot method” that selects a “div” with attribute name “id” and attribute value “shadow-host.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; A variable called “paragraph” is declared where it calls “shadowRoot” declared in step 5. The variable creates a method called “shadowRoot.child()” that returns an element child “p.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt; “t.expect.eql method” is used where the method asserts that the actual value is equal to the expected value. “paragraph.textContent” is the actual value while “This paragraph is in the shadow tree” is the expected value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8:&lt;/strong&gt; Try statement is used to define a block code to be tested for errors while it is being executed. Also, a catch statement defines a block of code to be executed if an error occurs in the try block.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In this case, the try statement will cause an error if the shadow root is targeted directly or used in assertions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: Run Automated &lt;a href="https://www.lambdatest.com/puppeteer-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Puppeteer Testing&lt;/a&gt; Online&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Test your Puppeteer test scripts online.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to find Shadow DOM?
&lt;/h2&gt;

&lt;p&gt;To identify shadow DOM in a web page:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to the web page and open the devtools as shown below.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;2- Click the settings gear in the top-right corner of the devtools window to open settings as shown below.&lt;/p&gt;

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

&lt;p&gt;3- Under the “Elements,” enable the “show user agent shadow DOM” checkbox as shown below.&lt;/p&gt;

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

&lt;p&gt;4- Go back to devtools, and you should be able to identify shadow DOM, as shown below.&lt;/p&gt;

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

&lt;p&gt;Watch this video to learn what Shadow DOM is and how to automate it using Selenium WebDriver.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: &lt;a href="https://www.lambdatest.com/blog/regression-testing-what-is-and-how-to-do-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;What is Regression testing&lt;/a&gt;: Complete Guide With Best Practices&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Limitations of TestCafe Selectors
&lt;/h2&gt;

&lt;p&gt;There are three types of TestCafe Selectors. These TestCafe Selectors are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Keyword-Based TestCafe Selectors&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Function-Based TestCafe Selectors&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Selector-Based TestCafe Selectors&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keyword-Based TestCafe Selectors filter the page in search of elements that match a CSS selector. Function-Based TestCafe Selectors execute a client-side function that traverses the DOM. Selector-Based TestCafe Selectors execute or filter the results of another Selector query.&lt;/p&gt;

&lt;p&gt;These TestCafe Selectors have limitations. These limitations are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Selector queries cannot access user variables outside their scope.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Keyword-Based TestCafe Selectors and Selector-Based TestCafe Selectors do not accept custom arguments.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Function-Based TestCafe Selectors cannot contain generators or async/await keywords.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: &lt;a href="https://www.lambdatest.com/blog/regression-testing-what-is-and-how-to-do-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Regression test&lt;/a&gt;: Complete Guide With Best Practices&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Running tests using TestCafe on cloud Selenium Grid
&lt;/h2&gt;

&lt;p&gt;As developers, when we create a web app and push it to production, users can access it using different browsers, browser versions, and operating systems. Your task as a developer or tester is to ensure that the web app performs as expected on all these browsers, browser versions, and operating systems.&lt;/p&gt;

&lt;p&gt;To test the web app on all these browsers and operating systems, you need an in-house &lt;a href="https://www.lambdatest.com/learning-hub/test-infrastructure?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;test infrastructure&lt;/a&gt;. Unfortunately, running and maintaining an in-house test infrastructure can be quite expensive. Using TestCafe and &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cloud Selenium Grid&lt;/a&gt; can be beneficial because it eliminates the need to invest in the maintenance of the in-house test infrastructure.&lt;/p&gt;

&lt;p&gt;Cloud Selenium Grid provides you with an option to run tests on a range of virtual browsers, browser versions, and operating systems securely over the cloud. LambdaTest is one of the top &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platforms offering cloud &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, a secure, scalable, and reliable cloud-based Selenium Grid Infrastructure that lets you run tests at scale on an &lt;a href="https://www.lambdatest.com/online-browser-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;online browser farm&lt;/a&gt; of 3000+ browsers and operating systems.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: Mobile &lt;a href="https://www.lambdatest.com/mobile-emulator-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Emulator Online&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Test your mobile websites and smartphone apps using our scalable on cloud mobile emulator.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can follow the &lt;a href="https://www.youtube.com/c/LambdaTest?sub_confirmation=1" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; for more such videos around&lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt; Selenium testing,&lt;/a&gt; CI/CD, &lt;a href="https://www.lambdatest.com/cypress-ui-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress UI testing,&lt;/a&gt; and more.&lt;/p&gt;

&lt;p&gt;To use LambdaTest Selenium Grid together with TestCafe to run your tests, you will need a LambdaTest account.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to the &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest website&lt;/a&gt; and log in if you already have an account, or create one if you don’t have an account yet.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;2- Once you are logged in, navigate to the automation page by clicking Automation on the left sidebar of your screen and selecting “Builds”&lt;/p&gt;

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

&lt;p&gt;3- To use TestCafe with LambdaTest Grid, you need LambdaTest credentials (i.e., username and access key). To get the credentials, click the “Access Key” button on the right side of your screen.&lt;/p&gt;

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

&lt;p&gt;4- Let us now save the credentials (username and access key) to environment variables LT_USERNAME and LT_ACCESS_KEY in our project.&lt;/p&gt;

&lt;p&gt;5- To save username to environment variable LT_USERNAME and access key to LT_ACCESS_KEY on Linux/Mac, run the following commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  $ export LT_USERNAME= insert your username
    $ export LT_ACCESS_KEY= insert your access_key

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

&lt;/div&gt;



&lt;p&gt;6- For Windows, run the following commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $ set LT_USERNAME= insert your username
    $ set LT_ACCESS_KEY= insert your access_key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;7- To add these credentials to an environment variable in your project, run the following command on the Visual Studio command line.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;8- Then add your credentials 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;
    $ export LT_USERNAME= insert your username
    $ export LT_ACCESS_KEY= insert your access_key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;9- Make sure you save the file by pressing CTRL + X and enter.&lt;/p&gt;

&lt;p&gt;10- LambdaTest has an npm plugin that allows you to &lt;a href="https://www.lambdatest.com/blog/testcafe-lambdatest-test-coverage/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;integrate TestCafe with LambdaTest&lt;/a&gt; for seamless&lt;a href="https://www.lambdatest.com/feature?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt; cross browser compatibility&lt;/a&gt; and true &lt;a href="https://www.lambdatest.com/blog/code-coverage-vs-test-coverage/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test coverage.&lt;/a&gt; You can install the plugin by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  npm install testcafe-browser-provider-lambdatest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;11- Run the below-mentioned command to look at the browsers supported by the LambdaTest Selenium Grid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;testcafe -b lambdatest 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;12- Let us save our TestCafe credentials in our project so that our authentication on LambdaTest Selenium Grid goes through. You can save the credentials by running the commands below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   $ set LT_USERNAME=*insert your username*
    $ set LT_ACCESS_KEY=*insert your accesskey*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s assume you want to test the “First Name” input element of the e-commerce website registration page we mentioned earlier on a Chrome browser version 85.0 + macOS combination.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To define your desired set of browser and operating system combinations, you can use &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest Capabilities Generator&lt;/a&gt; as shown below:&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;2- After setting your desired combinations, create a file called config.json and add your combinations as shown below without changing the code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   {
       "Chrome@85.0:MacOS Catalina": {
           "build": "TestCafe Demo",
           "network": true,
           "visual": true,
           "resolution": "1024x768"
       }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3- Navigate to the e-commerce website registration page. Inspect the web page and get the ID locator of “First Name” input which the user is expected to fill when registering for an account, as shown below.&lt;/p&gt;

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

&lt;p&gt;4- The next step is to add the “First Name” ID locator to the Page Object Model. 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;    import { Selector, t } from 'testcafe';

    class TestCafeSelectorsID {

       constructor() {
           this.firstnameInput = Selector('#input-firstname');
       }
    }

    export default new TestCafeSelectorsID();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5- Since we already declared the Selector in the page model and imported it to our test file, let us add “firstnameInput’, which is the name we gave the selector, as our first parameter in the “.typeText” TestController as shown below in the final code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   import TestCafeSelectorsID from "../PageModel/SelectByID";

    const pageURL = 'https://ecommerce-playground.lambdatest.io/index.php?route=account/register'

    fixture('Registration Page')
       .page(pageURL)

    test("FirstName", async t =&amp;gt; {
       await t
           .typeText(TestCafeSelectorsID.firstnameInput, 'John')
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;6- To run a test on (Chrome 85.0 + MacOS Catalina) combination, run the command below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    testcafe "lambdatest:Chrome@85.0:MacOS Catalina" TestCase/Tests/SelectByIDTest.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;7- If you visit your &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=login" rel="noopener noreferrer"&gt;LambdaTest Dashboard&lt;/a&gt; on the right side of your screen, you should be able to see your recent tests, as shown below.&lt;/p&gt;

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

&lt;p&gt;8- If you click on one of the tests, you will be redirected to the Automation Dashboard, where all the information about the test is available. This information includes a video and a screenshot that shows you how the test went.&lt;/p&gt;

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

&lt;p&gt;If you are a developer or a tester, this certification will acknowledge your expertise in using JavaScript to create automated browser tests. The Selenium JavaScript 101 certification is a globally-recognized certification that proves your expertise and skill in using &lt;a href="https://www.lambdatest.com/blog/automation-testing-with-selenium-javascript/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium with JavaScript&lt;/a&gt;.&lt;/p&gt;

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

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

&lt;p&gt;With this, we have reached the end of this TestCafe tutorial on TestCafe Selectors. As you have seen from the examples used in this TestCafe tutorial, TestCafe Selectors are similar to CSS Selectors in both purpose and syntax. We have learned about TestCafe Selectors and how to use them to select page elements.&lt;/p&gt;

&lt;p&gt;We further deep-dived into accessing Shadow DOM and showcased how to perform &lt;a href="https://www.lambdatest.com/testcafe-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec23_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;TestCafe testing&lt;/a&gt; on a cloud Selenium grid like LambdaTest.&lt;/p&gt;

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

</description>
      <category>gratitude</category>
    </item>
  </channel>
</rss>
