<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Sachinj34</title>
    <description>The latest articles on Forem by Sachinj34 (@sachinj34).</description>
    <link>https://forem.com/sachinj34</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%2F963078%2F76af6756-dc5b-47f1-92a9-fc220cae6d39.png</url>
      <title>Forem: Sachinj34</title>
      <link>https://forem.com/sachinj34</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sachinj34"/>
    <language>en</language>
    <item>
      <title>How To Fill And Submit Forms In Cypress</title>
      <dc:creator>Sachinj34</dc:creator>
      <pubDate>Fri, 11 Nov 2022 12:24:33 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-fill-and-submit-forms-in-cypress-29db</link>
      <guid>https://forem.com/testmuai/how-to-fill-and-submit-forms-in-cypress-29db</guid>
      <description>&lt;p&gt;Web forms are one of the most common types of forms that you may have encountered when interacting with websites. An example of a simple form is a login page, where the user needs to enter the login credentials to access the relevant features of the platform. On the other hand, complex forms can contain a combination of user details, captchas, date pickers, and more.&lt;/p&gt;

&lt;p&gt;Be it &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress automation&lt;/a&gt; testing or &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; ; the tests are meant to interact with the WebElements on the page. As per my experience, automating the website’s behavior using appropriate methods is a must-have skill for &lt;a href="https://www.lambdatest.com/blog/getting-started-with-cypress/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this blog of the ongoing &lt;a href="https://www.lambdatest.com/learning-hub/cypress-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress tutorial&lt;/a&gt; series, I will be covering the integral aspects related to forms: How to use Cypress to fill out forms and How to use Cypress to submit forms. In case you are coming from a Selenium background and intrigued to know &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;what is Cypress&lt;/a&gt;, make sure to check out the &lt;a href="https://www.lambdatest.com/blog/cypress-vs-selenium-comparison/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium vs Cypress&lt;/a&gt; comparison.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Forms in HTML documents?
&lt;/h2&gt;

&lt;p&gt;Before I deep dive into how to use Cypress to fill out forms or perform Cypress form validation, let me touch upon the essential aspects of Forms in HTML. Here, I will also focus on the different types of attributes that constitute the creation of a form.&lt;/p&gt;

&lt;p&gt;HTML Forms are generally used to take different types of user inputs such as name, email address, phone numbers, card details, etc. These inputs are generally driven by forms through special elements (or controls) like checkboxes, text, password fields, input range, etc.&lt;/p&gt;

&lt;p&gt;Users are generally required to complete a form by entering text, selecting items, etc., and submitting this form from the front-end. Once the content is submitted, a response is received from the server’s end. Understanding how to &lt;a href="https://www.lambdatest.com/blog/finding-html-elements-using-cypress-locators/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;find HTML Elements using Cypress locators&lt;/a&gt; is a starting point to use Cypress to fill out forms and submit forms.&lt;/p&gt;

&lt;p&gt;The &lt;/p&gt; tag is used to create an HTML form. Here’s a simple example of a login form:
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html lang="en"&amp;gt;
   &amp;lt;form&amp;gt;
       &amp;lt;label&amp;gt;User: &amp;lt;br&amp;gt;
       &amp;lt;input type="text"&amp;gt;&amp;lt;/label&amp;gt;&amp;lt;br&amp;gt;
       &amp;lt;label&amp;gt;Password:&amp;lt;br&amp;gt;
       &amp;lt;input type="password"&amp;gt;&amp;lt;/label&amp;gt;&amp;lt;br&amp;gt;
       &amp;lt;input type="submit" value="Submit"&amp;gt;
   &amp;lt;/form&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&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%2F2024%2F1%2A02rdhcFJQaHZ7TyjHohdSA.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%2F2024%2F1%2A02rdhcFJQaHZ7TyjHohdSA.png" width="800" height="273"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we know the basic syntax of forms let’s implement the different input interactions with Cypress. I will walk you through each type of form that can be handled through the &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress automation framework&lt;/a&gt;. I will also cover the potential limitations of Cypress from the perspectives of form submission and validation of forms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Test your &lt;a href="https://www.lambdatest.com/mobile-testing-lab?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;mobile testing lab&lt;/a&gt; app and websites on LambdaTest’s Mobile testing cloud and get instant feedback. Find bugs early on, improve performance, quality, user experience and save time with mobile application testing on LambdaTest.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Form submission with Cypress
&lt;/h2&gt;

&lt;p&gt;Here are some of the major types of WebElements that most of us would have come across on web pages:&lt;/p&gt;
&lt;h2&gt;
  
  
  Input Elements
&lt;/h2&gt;

&lt;p&gt; tag is the most used type of element in forms. This is because it allows you to add various types of user input fields that are majorly dependent on the attribute type.&lt;/p&gt;

&lt;p&gt;An input element can be a text field, password field, checkbox, radio button, etc. Each of these elements serves different purposes, and the approach in handling them purely depends on the element type.&lt;/p&gt;

&lt;p&gt;Here are some of the major input fields that can be handled with Cypress &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation&lt;/a&gt;:&lt;/p&gt;
&lt;h3&gt;
  
  
  Text Fields
&lt;/h3&gt;

&lt;p&gt;Text fields are single text input controls. In text fields, the type attribute has a value of the text. Here’s an example text input used to take username:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Handling Text fields in Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For demonstrating how to handle text fields in Cypress, I will be using the following HTML form:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html lang="en"&amp;gt;
   &amp;lt;form action="https://www.automationtestinginsider.com/"&amp;gt;
       First name:&amp;lt;br&amp;gt;&amp;lt;input name="firstname" type="text"&amp;gt;&amp;lt;br&amp;gt;
       Last name:&amp;lt;br&amp;gt;&amp;lt;input name="lastname" type="text"&amp;gt;&amp;lt;br&amp;gt;
     &amp;lt;/form&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The output of the above example is 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%2A9y8U1Y0S5UlEwXYZ.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%2A9y8U1Y0S5UlEwXYZ.png" width="362" height="115"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the Cypress implementation for handling text fields on a test website:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;beforeEach('Launch site', ()=&amp;gt;{
   cy.visit('https://www.automationtestinginsider.com/2019/08/textarea-textarea-element-defines-multi.html')
})

it('Interacting with text fields',()=&amp;gt;{
   cy.get('input[name="firstname"]')
     .type('Sachin')
.should('have.value','Sachin')
.get('input[name="lastname"]')
.type('Joshi')
.should('have.value','Joshi')
})
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I am using cy.visit() to open the target website in the above code. Once the site is loaded, the cy.get() function is called by passing the &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=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;CSS web locator&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Appropriate &lt;a href="https://www.lambdatest.com/blog/finding-html-elements-using-cypress-locators/#LocatorsinCypress?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;CSS locators in Cypress&lt;/a&gt; are used to locate the desired WebElement and interact with the same. For example, on similar lines, the cy.get() method is used for entering the ‘last name’ in the text field.&lt;/p&gt;

&lt;p&gt;For both the fields, I am asserting the value using .should() to validate if the text is showing the same value or not.&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%2F2756%2F0%2AjYJ07qjcUzcz-cKq.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%2F2756%2F0%2AjYJ07qjcUzcz-cKq.png" width="800" height="214"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check out the below video that deep dives into Assertions in Cypress:&lt;/p&gt;

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

&lt;p&gt;However, you can visit the &lt;a href="https://www.youtube.com/c/LambdaTest?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube channel&lt;/a&gt; for more videos in the &lt;a href="https://www.youtube.com/playlist?list=PLZMWkkQEwOPnxrxi544nL1vdC1noooXPx?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress Testing tutorial&lt;/a&gt; and videos on &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, so there’s never a shortage of learning opportunities.&lt;/p&gt;

&lt;h3&gt;
  
  
  Password Field
&lt;/h3&gt;

&lt;p&gt;The characters in the password fields are masked; hence, they are shown as dots or asterisks. Akin to text fields, password fields are also input controls created using an  element with attribute type as password.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Handling Password field in Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here’s an example of a password input inside &lt;/p&gt; for user password:
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html lang="en"&amp;gt;
   &amp;lt;form&amp;gt;
       &amp;lt;label for="pwd"&amp;gt;Password:&amp;lt;/label&amp;gt;
       &amp;lt;input type="password" name="password" id="user-pwd"&amp;gt;
   &amp;lt;/form&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The output of the above example is 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%2AcyPn16EcLc-tBu08.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%2AcyPn16EcLc-tBu08.png" width="800" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the Cypress implementation for handling password field on a test website:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it('Interacting with password fields' ,()=&amp;gt;{
   cy.visit('https://opensource-demo.orangehrmlive.com/index.php/auth/login')
   .get('#divUsername')
   .type("Admin")
   .get('#txtPassword').type('admin123')
   .type('{enter}')
   .get('.head')
   .should('be.visible');
})
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here, I am visiting the site’s login page and locating the elements using the .get() method. An assert is raised using the using should() method if the login is unsuccessful.&lt;/p&gt;

&lt;p&gt;Along with it, the visibility of the .head class is also checked to ensure that the required elements are available on the 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%2F2760%2F0%2ANhsfHFuadgtO4Hpf.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%2F2760%2F0%2ANhsfHFuadgtO4Hpf.png" width="800" height="238"&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%2F2760%2F0%2AeDxQJGBvjZejTs_C.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%2F2760%2F0%2AeDxQJGBvjZejTs_C.png" width="800" height="238"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Radio Buttons are used when the user selects exactly one option out of the listed ones when submitting the HTML form. The Radio button is created using an  element with type attribute value as radio.&lt;/p&gt;

&lt;p&gt;One of its common applications is when the user has to select their gender, marital status, or submit answers that have binary (i.e., yes/no) options.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Handling Radio buttons in Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here’s an example of a radio buttons inside &lt;/p&gt; tag:
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html lang="en"&amp;gt;
   &amp;lt;form&amp;gt;
   &amp;lt;input type="radio" name="gender" id="male"&amp;gt;
    &amp;lt;label for="male"&amp;gt;Male&amp;lt;/label&amp;gt;
    &amp;lt;input type="radio" name="gender" id="female"&amp;gt;
    &amp;lt;label for="female"&amp;gt;Female&amp;lt;/label&amp;gt;
   &amp;lt;/form&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here is the output of the HTML code:&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%2A8r33-tuXJaySGy3-.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%2A8r33-tuXJaySGy3-.png" width="620" height="24"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the Cypress implementation for handling radio buttons on a test website:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it('Interacting with radio buttons',()=&amp;gt;{
   cy.visit('https://www.automationtestinginsider.com/2019/08/textarea-textarea-element-defines-multi.html')
   .get('input[value="Yes"')
   .click()
   .get('input[value="No"')
   .click()
   .get('input[value="Don\'t Know"')
   .click()
})
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first step is to locate (or identify) the radio button with the Value attribute. For realizing this, I am leveraging the  tag [Yes, No, etc.].&lt;/p&gt;

&lt;p&gt;The click() method is used for selecting the required value (using the radio button on the form).&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%2AlB7WFVfmkQ7bcuS_.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%2AlB7WFVfmkQ7bcuS_.png" width="512" height="143"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Checkboxes
&lt;/h3&gt;

&lt;p&gt;Checkboxes in forms help you select more than one option from a list of predefined options. It is created using an  element with attribute type as checkbox.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Handling Checkboxes in Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For demonstrating how to handle checkboxes in Cypress, I have created a simple HTML form that comprises a few checkboxes.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html lang="en"&amp;gt;
   &amp;lt;form&amp;gt;
       &amp;lt;input type="checkbox" name="policy" id="policy1"&amp;gt;
       &amp;lt;label for="policy"&amp;gt;Policy1 - I Agree&amp;lt;/label&amp;gt;
       &amp;lt;br&amp;gt;
       &amp;lt;input type="checkbox" name="policy" id="policy2"&amp;gt;
       &amp;lt;label for="policy"&amp;gt;Policy2 - I Agree&amp;lt;/label&amp;gt;
       &amp;lt;br&amp;gt;
       &amp;lt;input type="checkbox" name="policy" id="policy3"&amp;gt;
       &amp;lt;label for="policy"&amp;gt;Policy3 - I Agree&amp;lt;/label&amp;gt;
       &amp;lt;/form&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here is the output of the following HTML code:&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%2AhZq-Yax_94jx_mjL.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%2AhZq-Yax_94jx_mjL.png" width="800" height="277"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the Cypress implementation for handling checkboxes on a test website:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it('Interacting with checkboxes',()=&amp;gt;{
 cy.visit('https://www.automationtestinginsider.com/2019/08/textarea-textarea-element-defines-multi.html')
     .get('input[value="Checkbox1"]')
     .click()
     .get('input[value="Checkbox2"]')
     .click()
     .get('input[value="Checkbox3"]')
     .click()
     .get('input[value="Checkbox1"]')
     .click()  //this to uncheck first one again
})
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I have checked all the four checkboxes in the above example and unchecked them one by 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%2A0Hj-m1898r_r22o-.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%2A0Hj-m1898r_r22o-.png" width="775" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;To get started, the required WebElement is identified using the Value attribute. Then, depending on your convenience, you can also use other attributes like ID, Name, etc.&lt;/p&gt;

&lt;p&gt;Like &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=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;XPath in Selenium&lt;/a&gt;, you can also choose to use XPath in Cypress if XPath is your go-to WebLocator for locating WebElements. As seen in the output below, Checkbox1 is unchecked (if checked) once we perform a click operation on 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%2Fcdn-images-1.medium.com%2Fmax%2F2380%2F0%2AnM8Quass12lpTSx8.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%2F2380%2F0%2AnM8Quass12lpTSx8.png" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  TextArea
&lt;/h3&gt;

&lt;p&gt;Textarea is another form of text input field where users can enter more than one line of text. Textarea field is particularly useful when users submit lengthy text like feedback, instructions, etc.&lt;/p&gt;

&lt;p&gt;With the attributes like rows, cols, and maxlength, you can limit the visibility and number of characters in the text area. The  tag element is used to create multi-line text fields.&lt;/p&gt;

&lt;p&gt;The attribute rows is used to specify the visible number of lines, whereas cols is used to specify the visible width of a text area.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Handling Textarea in Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To demonstrate how to handle textarea in Cypress, I have created a simple HTML form containing a single text area.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
   &amp;lt;body&amp;gt;
       &amp;lt;label for="address"&amp;gt;About Yourself:&amp;lt;/label&amp;gt;
         &amp;lt;form&amp;gt;
             &amp;lt;textarea rows="10" cols="30" name="address" id="address"&amp;gt;&amp;lt;/textarea&amp;gt;
         &amp;lt;/form&amp;gt;
     &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here is the output of the following HTML code:&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%2A72mMiKx-hvfYZDuA.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%2A72mMiKx-hvfYZDuA.png" width="349" height="123"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the Cypress implementation for handling the text area (where rows are 10 in number). This means that text will be visible only till 10 rows. Post that, users will have to scroll to see the remaining text.&lt;/p&gt;

&lt;p&gt;Shown below is the implementation to enter multiple rows with the use of new line character (i.e. “\n”):&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it('Ensure the text limits in text area', () =&amp;gt; {
   cy.visit('https://www.automationtestinginsider.com/2019/08/textarea-textarea-element-defines-multi.html')
    .get('textarea')
    .first()
    .clear()
    .type(Row1\n Row2\nRow3\nRow4\nRow5\nRow6\nRow7\nRow8\n
   Row9\nRow10\nRow11\nRow12')
    }
)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The cy.get(‘textarea’) method is used for locating the textarea field. The clear() method in Cypress is used for clearing the input text that might be pre-populated by default.&lt;/p&gt;

&lt;p&gt;The type() method in Cypress is used for entering text across rows till Row-12. The text till row 10 is visible in the below screenshot, after which you will have to scroll down to see the content entered in the remaining rows. This is because we have limited the maximum number of rows to 10 for the  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%2F2758%2F0%2AlZ1gCZnNHv0TWCJJ.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%2F2758%2F0%2AlZ1gCZnNHv0TWCJJ.png" width="800" height="203"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Dropdown Menu
&lt;/h3&gt;

&lt;p&gt;A dropdown menu provides a list of options that users can select before submitting the form. A common usage of dropdown menus is choosing the appropriate country/state/city from the pre-populated list.&lt;/p&gt;

&lt;p&gt;It is created using the  element along with the  tag which lists the options available for selection. The  tag can be used without any attributes; however, a value attribute is a must if you want to send the selected values to the server once the form is submitted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Handling Dropdown menu in Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here, I have created a simple downtown list that lets the user select their preferred automobile brand:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
   &amp;lt;form action="/action_page.php"&amp;gt;
       &amp;lt;label for="cars"&amp;gt;Choose a car:&amp;lt;/label&amp;gt;
       &amp;lt;select name="cars" id="cars"&amp;gt;
         &amp;lt;option value="volvo"&amp;gt;Volvo&amp;lt;/option&amp;gt;
         &amp;lt;option value="saab"&amp;gt;Saab&amp;lt;/option&amp;gt;
         &amp;lt;option value="opel"&amp;gt;Opel&amp;lt;/option&amp;gt;
         &amp;lt;option value="audi"&amp;gt;Audi&amp;lt;/option&amp;gt;
       &amp;lt;/select&amp;gt;
       &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
       &amp;lt;input type="submit" value="Submit"&amp;gt;
     &amp;lt;/form&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here is the Cypress implementation for handling dropdown menu in Cypress:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;describe.only('DropDown selection',()=&amp;gt;{
   it('Select boxes using Visible option',()=&amp;gt;{       
 cy.visit('https://www.automationtestinginsider.com/2019/08/textarea-textarea-element-defines-multi.html')
           .get('select')
           .eq(0)
           .select('Fiat')
           .should('have.value','fiat')
       })

       it('Select boxes using values',()=&amp;gt;{
           cy.visit('https://www.automationtestinginsider.com/2019/08/textarea-textarea-element-defines-multi.html')
           .get('select')
           .eq(0)
           .select('fiat')
           .should('have.value','fiat')
       })
})
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The cy.select() method in Cypress is used for handling dropdowns in Cypress. The select(params) method accepts only one parameter. We can use attribute value as well as visible text value as a parameter to find and select the options from the list.&lt;/p&gt;

&lt;p&gt;Once the option is selected from the dropdown, should() assert the values using the built-in assertion method ‘have.value’. The method returns the value of the selected option.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2756%2F0%2AeSG7G0qSn-KW5EJF.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%2F2756%2F0%2AeSG7G0qSn-KW5EJF.png" width="800" height="288"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Submit and Reset Buttons
&lt;/h3&gt;

&lt;p&gt;Input control of the submit type is used for sending the form data to the server. When the submit button is clicked, the data entered by the user is submitted (or passed) to either retrieve from the database or perform actions on the submitted data.&lt;/p&gt;

&lt;p&gt;For instance, when a user enters login details, the username and password combination is sent to the server for verification. Then, the next set of actions are performed depending on the verification status. In scenarios where the user clicks the submit button without filling in the required entries, an error message is displayed on the screen.&lt;/p&gt;

&lt;p&gt;On similar lines, reset type of input control is used to clear all the details that the users enter. This is especially useful if the user has to re-enter the details in the form and clean all the respective fields if the submission has to be done freshly.&lt;/p&gt;

&lt;p&gt;Submit and Reset are created using the  tag, where the attribute value is set to “submit” and “reset,” respectively.&lt;/p&gt;

&lt;p&gt;Example: Using Submit button in Cypress&lt;/p&gt;

&lt;p&gt;I have created a simple form to demonstrate the handling of submit and reset buttons in Cypress:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
   &amp;lt;form action="https://www.automationtestinginsider.com/"&amp;gt;
       First name:&amp;lt;br&amp;gt; &amp;lt;input name="firstname" type="text"&amp;gt;&amp;lt;br&amp;gt;
       Last name:&amp;lt;br&amp;gt; &amp;lt;input name="lastname" type="text"&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
       &amp;lt;input type="submit" value="Submit"&amp;gt;
       &amp;lt;input type="reset"&amp;gt;
     &amp;lt;/form&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here is the sample output with the submit and reset buttons:&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%2F2704%2F0%2Aro7hNA23mlsWvafx.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%2F2704%2F0%2Aro7hNA23mlsWvafx.png" width="800" height="171"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Shown below are the two approaches for handling Submit button in Cypress:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Approach 1: Using ‘Submit Button’ in Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Shown below is the sample demonstration to use Submit button on a form with Cypress:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it('Form submit with cypress submit() method', () =&amp;gt; {
   cy.visit('https://opensource- demo.orangehrmlive.com/index.php/auth/login')
        .get('#divUsername')
        .type("Admin")
        .get('#txtPassword').type('admin123')
        .get('form#frmLogin')
        .submit()
        .get('.head')
        .should('be.visible');
})
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The code is pretty simple 🙂 After entering the username and password, the submit() method is invoked to submit the contents entered in the form. In order to use the submit() method, we need to identify the form that has to be submitted.&lt;/p&gt;

&lt;p&gt;For this, the form ID is used to identify the form and invoke the submit() method to submit the contents entered in the form. To check if the form is submitted successfully or not, the visibility of the dashboard is checked by invoking the should() method. Here, the in-built be.visible parameter is used for confirming the visibility.&lt;/p&gt;

&lt;p&gt;Shown below is the execution snapshot:&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%2F2756%2F0%2AaUU3ccp-Fr3YhCl7.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%2F2756%2F0%2AaUU3ccp-Fr3YhCl7.png" width="800" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Approach 2: Using ‘Submit Button’ in Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this approach, the click() method is used for locating the Submit button using the appropriate locators in Cypress.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it('Form submit with usual click method', () =&amp;gt; {
   cy.visit('https://opensource-demo.orangehrmlive.com/index.php/auth/login')
       .get('#divUsername')
       .type("Admin")
       .get('#txtPassword').type('admin123')
       .get('input[type="submit"]')
       .click()
       .get('.head')
       .should('be.visible');
})
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Form submission using the click() method is akin to how clicks are performed on any button on a page. However, the major difference between the earlier approach and this one is the methodology used for locating the button using the get(‘input[type=”submit”]’) method.&lt;/p&gt;

&lt;p&gt;Once the button is located, the click() method is invoked for performing the requisite actions.&lt;/p&gt;

&lt;p&gt;Shown below is the execution snapshot:&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%2F2756%2F0%2AlI6r_vhfH3Br72hv.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%2F2756%2F0%2AlI6r_vhfH3Br72hv.png" width="800" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Using Reset button in Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here is the implementation for using Reset buttons in Cypress:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it('Form reset after filling up',()=&amp;gt;{
  cy.visit('https://www.automationtestinginsider.com/2019/08/textarea-textarea-element-defines-multi.html')
   cy.get('input[name="firstname"]')
       .type('Sachin')
       .should('have.value', 'Sachin')
       .get('input[name="lastname"]')
       .type('Joshi')
       .should('have.value', 'Joshi')
       .get('input[type="reset"]')
       .click()
       .get('input[name="firstname"]')
       .should('have.value','')
})
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Reset button is identified using the get(‘input[type=”reset”]’) method. Once the button is identified, a click operation is performed to empty the data entered in the username and password fields.&lt;/p&gt;

&lt;p&gt;The should() method is used to by-pass the in-built parameter ‘have.value’ to ‘equal to.’&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%2F2938%2F0%2ABZTeb9y-Prvd5QT8.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%2F2938%2F0%2ABZTeb9y-Prvd5QT8.png" width="800" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Take this certification to showcase your expertise with end-to-end testing using Cypress automation framework and stay one step ahead.&lt;/p&gt;

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

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

&lt;p&gt;Starting your journey with &lt;a href="https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress End-to-End Testing?&lt;/a&gt; Check out how you can test your Cypress test scripts on LambdaTest’s online cloud.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Test your native app and website on &lt;a href="https://www.lambdatest.com/cloud-mobile-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cloud Mobile Testing&lt;/a&gt; Labs on the cloud with real iOS and Android devices. LambdaTest is a convenient, cost-effective and centralized solution for running real-time and Automated tests on real devices cloud.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  File Upload Testing in Cypress
&lt;/h2&gt;

&lt;p&gt;Input type file is a special control that lets the user upload documents such as image, pdf, docx, ppt, etc., when submitting the forms. File uploads is a common input type that is primarily used for uploading files like ID proofs, profile photos, etc. File upload control is created with input tags that have attribute value type=file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: File Upload in Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I have created a simple form to demonstrate file upload functionality in Cypress:&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
&amp;lt;form method="POST" enctype="multipart/form-data"&amp;gt;
   &amp;lt;input id="file-upload" type="file" name="file"&amp;gt;
    &amp;lt;br&amp;gt;
   &amp;lt;input class="button" id="file-submit" type="submit"
   value="Upload"&amp;gt;
&amp;lt;/form&amp;gt; 
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Here is the output snapshot:&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%2F2756%2F0%2AwMJuGy9MrWj7-xr1.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%2F2756%2F0%2AwMJuGy9MrWj7-xr1.png" width="800" height="555"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Demo: File Upload testing in Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Cypress, by default, does not have built-in functionality to handle file uploads. Instead, the cypress-file-upload package is used for handling file uploads in Cypress.&lt;/p&gt;

&lt;p&gt;Here is the series of steps for realizing file upload in Cypress:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Installing plugin&lt;/p&gt;

&lt;p&gt;We first install the package by invoking the “npm install cypress-file-upload –save” command on the terminal.&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%2An1SlUWQfUjBLNC7P.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%2An1SlUWQfUjBLNC7P.png" width="800" height="247"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Import package in command.js&lt;/p&gt;

&lt;p&gt;Once the installation is done, add the statement import ‘cypress-file-upload’ in the command.js file. You can locate the command.js file under the support folder within the project.&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%2AHpkLWGBMHCBCSgxw.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%2AHpkLWGBMHCBCSgxw.png" width="800" height="247"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Adding upload file to fixtures&lt;/p&gt;

&lt;p&gt;We shall now place the file that we need to upload under the fixtures 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%2F2758%2F0%2AMn6A-FROpozTjl06.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%2F2758%2F0%2AMn6A-FROpozTjl06.png" width="800" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: Cypress implementation to upload files&lt;/p&gt;

&lt;p&gt;Here is the sample implementation for uploading files using Cypress:&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it('Test file upload with valid file extension', () =&amp;gt; {
   const filePath='somefile.txt';
   cy.visit("https://the-internet.herokuapp.com/upload")
   cy.get('#file-upload').attachFile(filePath)
   cy.get('#file-submit').click()
   cy.get('#uploaded-files').contains('somefile')
})
&lt;/code&gt;&lt;/pre&gt;

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

&lt;p&gt;Once you get the locator for file input using .get(‘#file-upload’), I am attaching a file placed under a fixture using attachFile(). A verification process of the uploaded file is done to ensure that the uploaded filename is the same as the original file. The contains() method in Cypress is used for realizing the above requirement.&lt;/p&gt;

&lt;p&gt;There is no need to specify the file path, as Cypress automatically looks for the required file under the fixtures folder.&lt;/p&gt;

&lt;p&gt;Here is the output snapshot:&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%2F2758%2F0%2AWHoJawWbVhfcSjFN.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%2F2758%2F0%2AWHoJawWbVhfcSjFN.png" width="800" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Handling Date picker in Form using Cypress
&lt;/h2&gt;

&lt;p&gt;Date Picker is another type of input field using which users can select the required date from the options. Date picker can be created either using  or .&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
   &amp;lt;form action="/action_page.php"&amp;gt;
       &amp;lt;label for="birthday"&amp;gt;Birthday:&amp;lt;/label&amp;gt;
       &amp;lt;input type="date" id="birthday" name="birthday"&amp;gt;
       &amp;lt;input type="submit"&amp;gt;
   &amp;lt;/form&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Here is the Cypress implementation for handling date pickers:&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it.only('Datepicker in form', ()=&amp;gt;{
   cy.visit('https://demoqa.com/automation-practice-form')
   .get('#dateOfBirth-wrapper')
   .click()
   .get('.react-datepicker__day--013')
   .click()
   .get('#dateOfBirthInput')
   .should('have.value', '13 Nov 2021')
})
&lt;/code&gt;&lt;/pre&gt;

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

&lt;p&gt;First we identify (or locate) the date picker field with .get(‘#dateOfBirth-wrapper’). The fields in the date picker are shown once a click is performed on the picker.&lt;/p&gt;

&lt;p&gt;For example, .get(‘.react-datepicker__day–013’) sets the date to “13 Nov 2021”. The date is verified using the .should() method by passing the ‘have.value’ as “13 Nov 2021”.&lt;/p&gt;

&lt;p&gt;Here is the execution snapshot:&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%2F2758%2F0%2ASnB4Yo4BasYnKhrU.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%2F2758%2F0%2ASnB4Yo4BasYnKhrU.png" width="800" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Cypress to fill out Forms and submit them on a Cloud Grid
&lt;/h2&gt;

&lt;p&gt;Now that I have covered the essentials of using Cypress to fill out forms, and submit &amp;amp; reset buttons, let me demonstrate everything using an end-to-end example. Rather than using a local Cypress Grid, I will be running tests on a cloud Cypress Grid like LambdaTest.&lt;/p&gt;

&lt;p&gt;LambdaTest simplifies the task of executing your Cypress tests in parallel on a range of &lt;a href="https://www.lambdatest.com/virtual-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online browse&lt;/a&gt;r and OS combinations hosted on the LambdaTest cloud grid. While writing this blog, there are 40+ browser versions for Cypress testing on the LambdaTest cloud grid.&lt;/p&gt;

&lt;p&gt;There are umpteen &lt;a href="https://www.lambdatest.com/blog/cloud-testing-tutorial/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;benefits of cloud testing&lt;/a&gt;, the major ones being improved scalability, reliability, security, and improved browser coverage. You can refer to the getting started guide to &lt;a href="https://www.lambdatest.com/blog/how-to-perform-cypress-testing-at-scale-with-lambdatest/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress testing on cloud&lt;/a&gt; to understand the benefits of cloud Cypress Grid better.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;a href="https://www.lambdatest.com/android-app-debugging?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Debug Android app&lt;/a&gt; on the cloud and get instant feedback. Find bugs early on, improve performance, quality, user experience, and save time with instant support on LambdaTest.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo: Using Cypress to fill out Forms
&lt;/h2&gt;

&lt;p&gt;I will perform relevant actions on the form placed on the website under test. The implementation shown below covers all the standard input types that can be used when filling up forms:&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it('Interacting with checkboxes',()=&amp;gt;{
   cy.visit('https://www.automationtestinginsider.com/2019/08/textarea-textarea-element-defines-multi.html')
     .get('input[value="Checkbox1"]')
     .click()
     .get('input[value="Checkbox2"]')
     .click()
     .get('input[value="Checkbox3"]')
     .click()
     .get('input[value="Checkbox1"]')
     .click()  //this to uncheck first one again
})

describe('Form Submission on LambdaTest', () =&amp;gt; {

   it('Fillup details and submit', () =&amp;gt; {

       const filePath = 'somefile.txt';

       cy.visit('https://demoqa.com/automation-practice-form')
           .get('#firstName')
           .type('Sachin')
           .get('#lastName').type('Joshi')
           .get('#userEmail').type('test.me@yopmail.com')
           .get('input[value="Male"]').click({force:true})
           .get('#userNumber').type('1231231231')

       cy.get('#dateOfBirth-wrapper')
           .click()
           .get('.react-datepicker__day--013')
           .click()
           .get('#subjectsInput').type('Sports')
           .get('input[type="checkbox"][value="1"]').click({force:true})

       cy.get('#uploadPicture').attachFile(filePath)
       cy.get('#currentAddress').type('This is long text area as you can type \n Multiple \n lines')
       cy.get('#state').type('Rajasthan{enter}')
       cy.get('#city').type('Jaipur')
       cy.get('#submit').click()

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

&lt;p&gt;LambdaTest config helps run tests in parallel against Chrome and Firefox on Windows &amp;amp; macOS platforms. There are a number 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=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;benefits of parallel testing&lt;/a&gt; with frameworks like Cypress, as it expedites the testing and release processes.&lt;/p&gt;

&lt;p&gt;Perform &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress Parallel Testing&lt;/a&gt; on LambdaTest and speed up the testing and release process. Check out how you can test your Cypress test scripts on LambdaTest’s online cloud.&lt;/p&gt;

&lt;p&gt;Here is the lambdatest-config.json file that houses the configuration-related information for running Cypress tests at scale on LambdaTest. I have used the LambdaTest Cypress CLI to override the essential configuration from a JSON file.&lt;/p&gt;

&lt;p&gt;Cypress CLI lets you manipulate the test configuration file [i.e., lambdatest-config.json] through the command-line interface (CLI), which allows you to override and/or manually modify your tests at any time you want.&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`{
  "lambdatest_auth": {
     "username": "&amp;lt;username&amp;gt;",
     "access_key": "&amp;lt;access_key&amp;gt;"
  },
  "browsers": [
     {
        "browser": "Chrome",
        "platform": "Windows 10",
        "versions": [
           "94.0"
        ]
     },

     {
        "browser": "Firefox",
        "platform": "Windows 10",
        "versions": [
           "92.0"
        ]
     },
     {
        "browser": "Chrome",
        "platform": "macOS Big Sur",
        "versions": [
           "94.0"
        ]
     },

     {
        "browser": "Firefox",
        "platform": "macOS Big Sur",
        "versions": [
           "92.0"
        ]
     }
  ],
  "run_settings": {
     "cypress_config_file": "cypress.json",
     "build_name": "Cypress",
     "parallels": 4,
     "specs": "./cypress/integration/practice/formSubmit.spec.js",
     "ignore_files": "",
     "npm_dependencies": {
        "cypress": "8.1.0"
     },
     "feature_file_suppport": false,
     "video":true
  },
  "tunnel_settings": {
     "tunnel": false,
     "tunnelName": null
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once we are ready with the tests and configuration file demonstrating &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; with Cypress, we can run the same on the LambdaTest grid by triggering the following command on the terminal:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;lambdatest-cypress run&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After a successful run, you will see the tests appended on the LambdaTest Grid.&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%2F2760%2F0%2AZj6MDRe5govoTfiY.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%2F2760%2F0%2AZj6MDRe5govoTfiY.png" width="800" height="317"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can navigate to the &lt;a href="https://automation.lambdatest.com/timeline/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov11_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest automation dashboard&lt;/a&gt; to check the status of the test. As we have executed the tests parallely on Chrome and Firefox browsers, the same can be seen in the dashboard.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2758%2F0%2AKvbzesPgqPGRgGL9.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%2F2758%2F0%2AKvbzesPgqPGRgGL9.png" width="800" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;I hope you enjoyed reading the blog on using Cypress to fill out forms and submit them, where we saw different types of form inputs that we come across in most websites and how we can automate the form submission with Cypress. We also covered the cross-browser capability of the Cypress testing tools like LambdaTest, and as evident from screenshots of the LambdaTest dashboard, it took us only 1 minute to execute the form test across four different combinations of firefox and chrome for Windows and macOS systems. Such is the power of cloud-based testing platforms.&lt;/p&gt;

&lt;p&gt;Thank you and Happy Learning!!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>cypress</category>
      <category>testing</category>
      <category>automation</category>
    </item>
    <item>
      <title>How To Find HTML Elements Using Cypress Locators</title>
      <dc:creator>Sachinj34</dc:creator>
      <pubDate>Thu, 10 Nov 2022 08:29:57 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-find-html-elements-using-cypress-locators-455c</link>
      <guid>https://forem.com/testmuai/how-to-find-html-elements-using-cypress-locators-455c</guid>
      <description>&lt;p&gt;Cypress is a new yet upcoming automation testing tool that is gaining prominence at a faster pace. Since it is based on the JavaScript framework, it is best suited for end-to-end testing of modern web applications. Apart from the QA community, Cypress can also be used effectively by the front-end engineers, a requirement that cannot be met with other &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;test automation&lt;/a&gt; frameworks like Selenium.&lt;/p&gt;

&lt;p&gt;Since Cypress is an open-source framework suited for testing modern web applications, many QA engineers prefer Cypress test automation over testing with other automation frameworks.&lt;/p&gt;

&lt;p&gt;To access any WebElement in the DOM (Document Object Model), you would need to use Cypress locators, comparable to locators in Selenium. Thus, by the end of this &lt;a href="https://www.lambdatest.com/learning-hub/cypress-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress tutorial&lt;/a&gt;, you would be in a position to use Cypress locators to access WebElements in the DOM for realizing &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress automation&lt;/a&gt; tests.&lt;/p&gt;

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

&lt;p&gt;Starting your journey with &lt;a href="https://www.lambdatest.com/blog/getting-started-with-cypress/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress Testing?&lt;/a&gt; Check out how you can test your Cypress test scripts on LambdaTest’s online cloud.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Cypress Locators
&lt;/h2&gt;

&lt;p&gt;If you are coming from a &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium automation&lt;/a&gt; background and willing to jump ship to the Cypress framework, the &lt;a href="https://www.lambdatest.com/blog/cypress-vs-selenium-comparison/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress vs Selenium comparison&lt;/a&gt; would be helpful to make a wiser decision! In addition, you can take a quick refresher of the Cypress framework by visiting our earlier blog that deep-dives into the &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress architecture and design&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Akin to locators in Selenium, Cypress locators are also used to find WebElements in the HTML Document Object Model (DOM). Once you find multiple elements in Cypress, relevant operations can be performed on these elements or assert their presence for validation.&lt;/p&gt;

&lt;p&gt;Locators are generally classified in the following categories, while they are being used to find multiple elements in Cypress:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;tags&lt;/strong&gt; — Locate WebElements using HTML tags like &lt;em&gt;&lt;/em&gt;, &lt;em&gt;&lt;/em&gt;, &lt;em&gt;&lt;a&gt;&lt;/a&gt;&lt;/em&gt;, etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ids&lt;/strong&gt; — Locate WebElements using the &lt;em&gt;ID&lt;/em&gt; of the elements&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;name&lt;/strong&gt; — Locate WebElements using &lt;em&gt;name&lt;/em&gt; attribute that is set for elements (especially form input elements)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;class&lt;/strong&gt; — Locate WebElements by &lt;em&gt;class&lt;/em&gt; value&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;links&lt;/strong&gt; — Locate WebElements by &lt;em&gt;links&lt;/em&gt; &lt;em&gt;text&lt;/em&gt; property&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;attributes&lt;/strong&gt; — Locate WebElements by &lt;em&gt;one or multiple sets of attributes&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since the core fundamentals of web locators are agnostic of the automation framework, you can refer to our &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=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;locators in Selenium&lt;/a&gt; that deep dive into each locator (mentioned above) in more detail.&lt;/p&gt;

&lt;p&gt;Get the best out of your Cypress tests with LambdaTest’s online &lt;a href="https://www.lambdatest.com/cypress-automation-tool?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress automation tool&lt;/a&gt;. Check out how you can test your Cypress test scripts using LambdaTest’s online cloud.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Test your &lt;a href="https://www.lambdatest.com/puppeteer-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Puppeteer&lt;/a&gt; test scripts online. Deploy a quality build faster by running automated checks across over 3000+ browsers and OS combinations with the LambdaTest cloud. Try for free.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use Locators in Cypress
&lt;/h2&gt;

&lt;p&gt;Cypress supports only CSS selectors out of the box for locating elements in the DOM. So in case you intend to use other web locators like XPath, ID, etc., with Cypress, you need to add relevant external packages that support using those with Cypress 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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AghRxxLfVzTt4mAU-.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%2AghRxxLfVzTt4mAU-.png" width="507" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s deep dive into details of how to use and work with locators in Cypress. For this blog in the Cypress tutorial series, I will be using &lt;a href="http://automationpractice.com/index.php?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;ecommerce practice site&lt;/a&gt; for showcasing the usage of the relevant web 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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2ABGmoRzPW-srtCRDj.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%2ABGmoRzPW-srtCRDj.png" width="512" height="349"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can go through the following video to learn Cypress GET and FIND Command Hacks supported by the &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress test automation framework&lt;/a&gt;. This will help you write your first cypress test and target HTML elements using the GET command. However, visit the &lt;a href="https://www.youtube.com/c/LambdaTest?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest YouTube channel&lt;/a&gt; for more Cypress videos, so there’s never a shortage of Cypress learning opportunities.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Identify HTML elements using ‘ID’ Cypress locator
&lt;/h2&gt;

&lt;p&gt;IDs are the unique attributes given to the HTML elements that can be identified and updated with minimal effort. The &lt;em&gt;ID&lt;/em&gt; attribute is unique across the DOM, due to which it is the fastest way for locating the required WebElement. It also helps in accelerating the interactions with the underlying elements in the DOM.&lt;/p&gt;

&lt;p&gt;Here is a sample HTML page that showcases the syntax of ID in HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ul id="lists"&amp;gt;
   &amp;lt;li id="first"&amp;gt; Option 1 &amp;lt;/li&amp;gt;
   &amp;lt;li id="second"&amp;gt; Option 2 &amp;lt;/li&amp;gt;
   &amp;lt;li id="third"&amp;gt; Option 3 &amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here, &lt;em&gt;&lt;ul&gt;&lt;/ul&gt;&lt;/em&gt; tag can be identified uniquely with CSS selectors command using &lt;em&gt;$(‘#lists’)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Demonstration: ID locator in Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s look at using an &lt;em&gt;ID&lt;/em&gt; locator in Cypress using the example site that we showed earlier. Here, we locate the search bar on the site; the HTML representation of the search bar is below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input class=“search_query form-control ac_input” type=“text”
id=“search_query_top” name=“search_query” placeholder=“Search” value="" autocomplete=“off”&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AFaS19qi-A5xIg92hW1sSCg.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%2F1%2AFaS19qi-A5xIg92hW1sSCg.png" width="512" height="247"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the implementation that demonstrates the use of the &lt;em&gt;ID&lt;/em&gt; locator in Cypress:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;describe('Cypress Locators in action', ()=&amp;gt;{
   beforeEach(()=&amp;gt;{
       cy.visit('[http://automationpractice.com'](http://automationpractice.com'))
   })
   it('Interact with Elements using ID selector', ()=&amp;gt;{
       cy.get('#search_query_top') //ids are identified using # prefix
       .type('Dress')
       .type('{enter}')
       .get('#center_column')
       .should('be.visible')
   })
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;em&gt;cy.get() *is used in Cypress to find multiple elements in DOM. The method accepts a parameter in the form of an identifier. Here we pass the *ID&lt;/em&gt; of the element with ‘#’ as a prefix. Since the call is chainable, we used &lt;em&gt;type()&lt;/em&gt; to enter values and used should() to assert the visibility of the corresponding WebElement.&lt;/p&gt;

&lt;p&gt;Shown below is the execution screenshot, which indicates that the test execution was successful:&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%2F2758%2F0%2AKa5AZaWlYnMIPNfL.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%2F2758%2F0%2AKa5AZaWlYnMIPNfL.png" width="800" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Identify HTML elements using ‘NAME’ Cypress locator
&lt;/h2&gt;

&lt;p&gt;The HTML name attribute is mostly used by &lt;em&gt;&lt;/em&gt;,&lt;em&gt;&lt;/em&gt;, &lt;em&gt;&lt;/em&gt; tags where it helps to identify field details when submitted to the server. You can refer to our detailed blog on &lt;a href="https://www.lambdatest.com/blog/how-to-use-name-locator-in-selenium-automation-scripts/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;NAME locator in Selenium&lt;/a&gt; to get insights on the said web locator.&lt;/p&gt;

&lt;p&gt;Here is a sample HTML page that showcases the syntax of NAME in HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input class=“search_query form-control ac_input” type=“text”
id=“search_query_top” name=“search_query” placeholder=“Search” value="" autocomplete=“off”&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;&lt;strong&gt;Demonstration: NAME locator in Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Shown below is the syntax of the NAME locator in Cypress:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cy.get(&amp;lt;tag&amp;gt;[name='value'])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;where &lt;em&gt;&lt;/em&gt; can be HTML tags like input, form, etc. &lt;em&gt;&lt;/em&gt; is optional, when not specified, it will match name against all the tags (wherever match is found).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;describe('Cypress Locators in action', ()=&amp;gt;{
   beforeEach(()=&amp;gt;{
       cy.visit('[http://automationpractice.com'](http://automationpractice.com'))
   })
it('Interact with Elements using name attribute',()=&amp;gt;{
   cy.get('input[name="search_query"]') //observe how we use name attribute
   .type('Tshirt{enter}')
   .get('#center_column')
   .should('be.visible')
})
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;Once the site is opened after the &lt;em&gt;beforeEach()&lt;/em&gt; execution, the test &lt;em&gt;“Interact with Elements using name attribute”&lt;/em&gt; starts with identifying elements using the name attribute (‘&lt;em&gt;search_query&lt;/em&gt;’) and then sends the search value to the text box using the &lt;em&gt;type()&lt;/em&gt; method.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it('Interact with Elements using name attribute',()=&amp;gt;{
   cy.get('input[name="search_query"]') //observe how we use name attribute
   .type('Tshirt{enter}')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The Inspect tool in Google Chrome is used for locating the element using the CSS Selector. Here is how we use the browser console using &lt;em&gt;$()&lt;/em&gt; as the CSS selector:&lt;/p&gt;

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

&lt;p&gt;Once the search results are available, we can use the ID locator in Cypress to find multiple elements and assert using Cypress’s built-in assertion method *should(‘be.visible’). *An assert is raised if the search results are not displayed properly.&lt;/p&gt;

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

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

&lt;p&gt;Shown below is the execution snapshot, which indicates the respective WebElement was located successfully using the NAME locator:&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%2F2756%2F0%2AqYwJz6XZVevyqOFz.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%2F2756%2F0%2AqYwJz6XZVevyqOFz.png" width="800" height="285"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Identify HTML elements using ‘Attributes’ in Cypress
&lt;/h2&gt;

&lt;p&gt;Attributes are ways to set a particular property of the HTML element. They also help define the behavior of the elements when a specific condition is set and triggered. Attributes are applied to almost all the HTML tags and work similarly to the NAME locator in Cypress. Thus, we can use the same syntax for locating elements using other attributes as well.&lt;/p&gt;

&lt;p&gt;Shown below is the syntax to use attributes in Cypress:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cy.get(&amp;lt;tag&amp;gt;[attribute_name=attribute_value])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Additionally, consider a case where one would like to use Cypress to find multiple elements or all of them having attribute titles whose value contains ‘store’ (e.g., store-1, store-2, …). One of the brute force ways is to find each element one by one with the exact attribute value using the above syntax. However, this task is mundane and not beneficial when we need to find multiple elements in Cypress and add some common functional logic to them.&lt;/p&gt;

&lt;p&gt;A better approach would be to use the regex-supported syntax in the CSS selector to get the list of items in one go.&lt;/p&gt;

&lt;p&gt;Fortunately, Cypress provides an easier way to tackle this problem, where you can use patterns like &lt;em&gt;starts-with&lt;/em&gt; and &lt;em&gt;ends-with&lt;/em&gt; particular substring to match all the elements in the DOM.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;th&gt;Syntax&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;To find all the elements containing values&lt;/td&gt;
&lt;td&gt;*=, cy.get([attr_name *= attr_value])&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;To find all the elements starting with attr_value, we use&lt;/td&gt;
&lt;td&gt;^=, cy.get([attr_name ^= attr_value])&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;To find all the elements ending with attr_value&lt;/td&gt;
&lt;td&gt;$=, cy.get([attr_name $= attr_value])&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Demonstration : Using Attributes in Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;describe('Cypress Locators in action', ()=&amp;gt;{
   beforeEach(()=&amp;gt;{
       cy.visit('[http://automationpractice.com'](http://automationpractice.com'))
   })

   it('Finding elements using attribute values',()=&amp;gt;{
    cy.get('a[title*="store"]')
     .should('have.length.at.most',1)

    cy.get('a[title*="store" i]')  //case insensitive
     .should('have.length.gt',1)
       .each(i=&amp;gt; console.table([i.attr('href')]))
})

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

&lt;/div&gt;

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

&lt;p&gt;&lt;strong&gt;Step1&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;cy.get()&lt;/em&gt; method is used in Cypress to find multiple elements based on attribute value using *&lt;em&gt;title&lt;/em&gt;=store *&lt;em&gt;for locating *Our Stores&lt;/em&gt; link from the footer 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%2F3998%2F0%2AP3FscMH5lpCVNAlE.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3998%2F0%2AP3FscMH5lpCVNAlE.png" width="800" height="239"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once the intended WebElement is located, we validate that the page has at least one element that matches the required locator. Cypress built-in assertion method &lt;em&gt;.should(‘&lt;/em&gt;&lt;em&gt;have.length.at.most&lt;/em&gt;&lt;em&gt;’,1)&lt;/em&gt; is used for checking length value where ‘&lt;em&gt;have.length.at.most&lt;/em&gt;’ in Cypress evaluates the length of the located 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%2F2756%2F0%2AYHGHEJfHhIo81lM7.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%2F2756%2F0%2AYHGHEJfHhIo81lM7.png" width="800" height="272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;cy.get(‘a[title&lt;/em&gt;=”store” i]’) *method is used to find all the links on the page that contains the title *“store”. *In the screenshot shown below, I have highlighted two elements on the page that matched the required locator:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The first one is the logo with the title = &lt;strong&gt;“My&lt;/strong&gt; &lt;strong&gt;Store”&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The second one is the footer with the title = &lt;strong&gt;“Our stores”&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;should()&lt;/em&gt; method is used for asserting if the length of the located WebElements is greater than 1. The length is checked using the *have.length.gt *method.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;.each()&lt;/em&gt; in Cypress is used to iterate on each of the located WebElements. Here I am printing the &lt;em&gt;href *value using the *attr([key])&lt;/em&gt; method that returns the attribute value for the key provided as the argument.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.should('have.length.gt',1)
       .each(i=&amp;gt; console.table([i.attr('href')]))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As seen below, the URL of each element that is located on the page is printed on the console:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3998%2F0%2A_f5muIgWufeq3rj0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3998%2F0%2A_f5muIgWufeq3rj0.png" width="800" height="239"&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%2F2756%2F0%2AgX73n8W6NxAsI9i7.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%2F2756%2F0%2AgX73n8W6NxAsI9i7.png" width="800" height="272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this &lt;a href="https://www.lambdatest.com/xcuitest?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;XCUITest tutorial&lt;/a&gt;, learn about XCUITest framework and its benefits for mobile automation testing. Take a look at how XCUITest works and see how to use it to test your mobile applications.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Identify HTML elements using ‘By Class’ in Cypress
&lt;/h2&gt;

&lt;p&gt;HTML class attribute is mostly used for styling the element or group of elements. Unlike ID, class attributes need not be unique, which is why this is helpful when we need to apply a common style to multiple elements.&lt;/p&gt;

&lt;p&gt;In Cypress, class selectors can be identified using the following options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;cy.get(.)&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;cy.get([class=’&amp;lt;class_value’])&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Demonstration: Using ‘By Class’ in Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Consider the following HTML Page for demonstration:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;a href="[http://automationpractice.com/index.php?id_category=3&amp;amp;controller=category](http://automationpractice.com/index.php?id_category=3&amp;amp;controller=category)" title=“Women” class=“sf-with-ul”&amp;gt;Women&amp;lt;/a&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Shown below is the implementation that demonstrates the usage of ‘&lt;em&gt;By Class&lt;/em&gt;’ in Cypress:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;describe('Cypress Locators in action', ()=&amp;gt;{
   beforeEach(()=&amp;gt;{
       cy.visit('[http://automationpractice.com'](http://automationpractice.com'))
   })

  it('Interact with Elements using class selector',()=&amp;gt;{
        cy.get('.item')
        .eq(0) //0th element in the array of elements
        .click()
        cy.get('[class*="center_column"]') 
        .should('be.visible')
    })  
  it('Class selector short hand',()=&amp;gt;{
     //find class containing value .. using *=
     cy.get("a[class*='add_to_cart']")
     .eq(0)  // finding 0th element
     .click()
     .get("#layer_cart")
     .should('be.visible')

   //find class value that start with .. using ^=
    cy.get("[class^='layer_cart_product']")
    .should('be.visible')
    .get("a[title='Proceed to checkout']")
    .click()

   //find class that ends with... using $=
    cy.get('[class$="_delete"]')
    .click()
    .get('.alert')
    .should('be.visible')
 })
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Test 1: Interact with Elements using class selector&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;cy.get(‘.item’)&lt;/em&gt; method is used to locate the element with class=”item”, which returns the list of elements matching the query.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cy.get('.item')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is how the locator is identified using the Inspect tool in Chrome:&lt;/p&gt;

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

&lt;p&gt;Once we get the list of the elements using the &lt;em&gt;get()&lt;/em&gt; method, the &lt;em&gt;eq()&lt;/em&gt; method in Cypress is used for locating the first element from the list. Once we locate the first element from the list, we click on the link that it points to (i.e. ‘&lt;a href="http://automationpractice.com/index.php?controller=prices-drop" rel="noopener noreferrer"&gt;Prices Drop&lt;/a&gt;’)&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.eq(0) //0th element in the array of elements
.click()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next, we find the class containing value using the &lt;em&gt;cy. get(‘ [class&lt;/em&gt;=”center_column”]’)* method. Raise an assert on the visibility of the element using the &lt;em&gt;.should()&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%2F3998%2F0%2A-7UVJGoyFm3MxKGN.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3998%2F0%2A-7UVJGoyFm3MxKGN.png" width="800" height="309"&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%2F2756%2F0%2A6T5vDr2JmMro_nT8.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%2F2756%2F0%2A6T5vDr2JmMro_nT8.png" width="800" height="246"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Test 2: Class selector short hand&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We find the first product from the list of items and add that product to the cart. We then validate the product present in the cart, remove the product and verify if the cart is empty.&lt;/p&gt;

&lt;p&gt;For this, we make use of regex with the &lt;em&gt;class&lt;/em&gt; selector so that the code looks cleaner.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cy.get("a[class*='add_to_cart']").eq(0)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The above code locates the ‘Add to cart button’ on the home page and returns the first button using &lt;em&gt;eq(0).&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%2F3998%2F0%2AUY3Z88nZnLP2vhbd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3998%2F0%2AUY3Z88nZnLP2vhbd.png" width="800" height="307"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After clicking on the first button, we wait for the element with ID *#layer_car *to be visible to perform necessary operations on that WebElement.&lt;/p&gt;

&lt;p&gt;Once the button is visible, we click on the same by locating it using its title (i.e. ‘&lt;em&gt;Proceed to checkout&lt;/em&gt;‘).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cy.get("[class^='layer_cart_product']")
    .should('be.visible')
    .get("a[title='Proceed to checkout']")
    .click()
&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%2F3998%2F0%2AVJkf1Ni1XeplP0kh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3998%2F0%2AVJkf1Ni1XeplP0kh.png" width="800" height="307"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We add a Product to the cart by clicking on the ‘Proceed to checkout’ button.&lt;/p&gt;

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

&lt;p&gt;Once the item is added to the cart, we delete the same and check if the shopping cart is empty. The delete button is located using &lt;em&gt;class$=”_delete”&lt;/em&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cy.get('[class$="_delete"]')
.click()
.get('.alert')
.should('be.visible')
&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%2F3998%2F0%2A1CKxsOqBv3h1p8wQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3998%2F0%2A1CKxsOqBv3h1p8wQ.png" width="800" height="233"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Identify HTML elements by ‘Link Text’ in Cypress
&lt;/h2&gt;

&lt;p&gt;Links are ways for connecting web resources (or web pages) to another through anchor tags (i.e., &lt;a&gt;) and &lt;em&gt;href&lt;/em&gt; attributes. For example, as shown below, My Orders is the link text displayed on the page.&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;a href="[http://automationpractice.com/index.php?controller=history](http://automationpractice.com/index.php?controller=history)"&amp;gt;My orders&amp;lt;/a&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We can locate links in cypress using &lt;em&gt;cy.get(:contains(‘’))&lt;/em&gt;. Shown below is the sample implementation that demonstrates the usage of Link Text in Cypress:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it('Interact with links or button using partial text',()=&amp;gt;{
   cy.get('a:contains("My orders")')  // similar to partial link text
   .click()
   cy.get('.page-heading')
   .should('have.text','Authentication')
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Shown below is the execution screenshot, which indicates that the test execution is successful:&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%2F2756%2F0%2AkaCGIO6gJ33PeKL7.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%2F2756%2F0%2AkaCGIO6gJ33PeKL7.png" width="800" height="246"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to use the first() method in Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Consider a scenario where you want to get the list of elements in DOM having a common pattern. For example, it could be items in the list, and you might be interested in fetching only the first item from the list.&lt;/p&gt;

&lt;p&gt;To realize such a requirement, Cypress provides two approaches to get the first element in Cypress:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;eq()&lt;/strong&gt; — Fetch element at &lt;em&gt;&lt;/em&gt; specified in the parameter. The example for this is covered above in the &lt;em&gt;by class&lt;/em&gt; section.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;first()&lt;/strong&gt; — Fetch only the first element from the list. It is useful when we intend to validate only the first element in the list.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To demonstrate the usage of the &lt;em&gt;first()&lt;/em&gt; method in Cypress, we get all the links under the &lt;em&gt;“item”&lt;/em&gt; class and use the &lt;em&gt;first()&lt;/em&gt; method to click the first from the list.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;t.only('Find elements with first()',()=&amp;gt;{
   cy.get('.item a')
   .first()
   .click()
   .get('.navigation_page')
   .should('contain.text','Price')
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Shown below is the approach through which the first element is located on the desired 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%2F3998%2F0%2AmWYOKYevtYvGjt36.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3998%2F0%2AmWYOKYevtYvGjt36.png" width="800" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the execution snapshot:&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%2F2756%2F0%2AakNx_9DCprtIwg5h.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%2F2756%2F0%2AakNx_9DCprtIwg5h.png" width="800" height="247"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to use the last() method in Cypress&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Akin to the first() method, Cypress’s last() method is used to locate the last element in a list of elements. This is a handy utility when working with applications like the ToDo app, where tasks are added at the end of the list and verification has to be done w.r.t the tasks’ addition (or deletion).&lt;/p&gt;

&lt;p&gt;For demonstrating the usage of the last() method, we use the &lt;a href="https://todomvc.com/examples/react/#/active" rel="noopener noreferrer"&gt;React ToDo App&lt;/a&gt; where we would be adding items and accessing the last item from the list.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it.only('Working with last()', ()=&amp;gt;{
   let task='Task at the end'
   cy.visit('[https://todomvc.com/examples/react/#/active'](https://todomvc.com/examples/react/#/active'))
   .get('.new-todo')
   .type(task)
   .type('{enter}')
   .get('.todo-list li')
   .last()
   .should('have.text',task)
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Shown below is the execution snapshot:&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%2F2756%2F0%2AcOFID_-jD52lMu60.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%2F2756%2F0%2AcOFID_-jD52lMu60.png" width="800" height="238"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Starting your journey with &lt;a href="https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress End-to-End Testing?&lt;/a&gt; Check out how you can test your Cypress test scripts on LambdaTest’s online cloud.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;a href="https://www.lambdatest.com/test-website-on-different-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Test website on different browsers&lt;/a&gt; on a cloud platform. Get instant access of Browsers like Chrome, Safari, Firefox, Opera, Yandex, Brave, 3000+ desktop &amp;amp; mobile environments. Try for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Handling ancestors and siblings elements in Cypress
&lt;/h2&gt;

&lt;p&gt;In the below HTML, &lt;/p&gt;
&lt;li&gt; elements are grouped inside common &lt;ul&gt; and they all are at the same level from the root. These are called siblings. &lt;ul&gt; will be immediate parent to the lists while  will be parent to &lt;ul&gt; &amp;amp; &lt;li&gt;.
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div list="items"&amp;gt;
   &amp;lt;ul id="social"&amp;gt;
         &amp;lt;li class='facebook'&amp;gt;facebook&amp;lt;/li&amp;gt;
         &amp;lt;li class='twitter'&amp;gt;twitter&amp;lt;/li&amp;gt;
         &amp;lt;li class='youtube'&amp;gt;youtube&amp;lt;/li&amp;gt;
          &amp;lt;li class='google-plus'&amp;gt;youtube&amp;lt;/li&amp;gt;
   &amp;lt;/ul&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There are certain cases in automation where we might need to check the sequence of the items displayed on the page and for this, we can use the &lt;em&gt;next()&lt;/em&gt; call in the chainable form in Cypress to find multiple elements and assert the sequence. Furthermore, similar to &lt;em&gt;next()&lt;/em&gt;, we can use the &lt;em&gt;prev()&lt;/em&gt; call to find previous siblings of selected elements.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;nextUntil()&lt;/em&gt; and &lt;em&gt;prevUntil()&lt;/em&gt; are the advanced ways of using the &lt;em&gt;next()&lt;/em&gt; and &lt;em&gt;prev() *methods in Cypress. Suppose you want to validate the sequence of all the elements under siblings until some conditions set through selectors are not met. The *nextUntil()&lt;/em&gt;/&lt;em&gt;prevUntil()&lt;/em&gt; methods in Cypress validate the sequence of elements until certain conditions are met.&lt;/p&gt;

&lt;p&gt;Shown below is the implementation that demonstrates the handling of ancestors and siblings using Cypress:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it.only('Working with siblings &amp;amp; parents', ()=&amp;gt;{
   cy.get('#social_block ul li')
   .first()
   .should('have.class','facebook')
   .next() //to next siblings
   .should('have.class','twitter')
   .next()
   .should('have.class','youtube')
   .next()
   .should('have.class','google-plus')
   .prev() // using prev() back to previous sibling of google-plus which should be 'youtube'
   .should('have.class', 'youtube') 

   cy.get('#social_block').siblings('div')  //siblings() method to check all sibling with &amp;lt;div&amp;gt; tag
   cy.get('#social_block').next('div').should('have.length',1)  //next() to find only next div
   cy.get('#social_block ul').children() //children() method to check sibling

   cy.get('#social_block&amp;gt;&amp;gt;li').next('.youtube') //next() with selector
   cy.get('#social_block').prev('div') //prev() with selector

   cy.get('.youtube').prevAll() //yields all before youtube
   cy.get('.facebook').nextAll() //yields all after facebook

   cy.get('.facebook').nextUntil('.google-plus') //yields twitter and youtube
   cy.get('#social_block').prevUntil('[class*="footer-block"]') //
})
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Shown below is the execution snapshot that indicates that the test execution was successful:&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%2F2756%2F0%2AFU-coZrBREhJIaq9.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%2F2756%2F0%2AFU-coZrBREhJIaq9.png" width="800" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Take this certification to showcase your expertise with end-to-end testing using &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress automahttps://www.lambdatest.com/blog/cypress-test-automation-framework/tion&lt;/a&gt; framework and stay one step ahead.&lt;/p&gt;

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

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

&lt;h2&gt;
  
  
  How to find HTML elements using Cypress XPath
&lt;/h2&gt;

&lt;p&gt;Although Cypress only supports CSS selectors by default, external packages are now available that let you use XPath with Cypress. To use Cypress XPath, perform the following steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Install &lt;em&gt;cypress-xpath&lt;/em&gt; at the root of the project. using &lt;em&gt;npm install cypress-path -d&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set &lt;em&gt;require(‘cypress-xpath’)&lt;/em&gt; under &lt;em&gt;cypress/support/index.js&lt;/em&gt;. With this, you are all set to use XPath in tests&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using XPath is very popular with automation frameworks to locate elements in DOM. In practice, XPath uses generic format of &lt;em&gt;//[@attribute=value]&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;// is used in Cypress to find multiple elements anywhere in the DOM. It is also called the relative path. Similarly, there is ‘/’ , which can be used to find WebElement at an absolute location. &lt;em&gt;&lt;/em&gt; is optional; if specified, all the elements matching the conditions will be returned.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;@attribute *is the attribute of the elements against which the match needs to be done. You can also use Cypress XPath functions like *contains()&lt;/em&gt;, &lt;em&gt;text()&lt;/em&gt;, etc., to use more advanced features to locate relevant WebElements.&lt;/p&gt;

&lt;p&gt;Here is the sample implementation that demonstrates the usage of Cypress XPath [ i.e. *cy.xpath() *]:&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/// &amp;lt;reference types="cypress" /&amp;gt;
/// &amp;lt;reference types="cypress-xpath" /&amp;gt;
describe('Working with xpath in Cypress made easy', ()=&amp;gt;{
   beforeEach(()=&amp;gt;{
       cy.visit('[http://automationpractice.com'](http://automationpractice.com'))
   })
   it('Xpath id usages', ()=&amp;gt;{  
       cy.xpath('//*[[@id](http://twitter.com/id)="search_query_top"]')
       .type('Dress')
       .type('{enter}')
       .get('#center_column')
       .should('be.visible')
   })
   it('xpath class usage',()=&amp;gt;{
       cy.xpath('//*[[@class](http://twitter.com/class)="item"]//a')
       .eq(0) //0th element in the array of elements
       .click()
       cy.xpath('//*[contains([@class](http://twitter.com/class),"center_column")]')
       .should('be.visible')
   })
   it('Interact with  Elements using name attribute',()=&amp;gt;{
       cy.xpath('//input[[@name](http://twitter.com/name)="email"]')
       .type('[xyz@yopmail.com](mailto:xyz@yopmail.com){enter}')
       .get(".alert")
       .should('contain.text','Newsletter')
   })
   it.only('Interact with elements using text', ()=&amp;gt;{
       cy.xpath('//a[text()="Women"]')
       .should('be.visible')
   })
})
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Shown below is the execution snapshot:&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%2F2756%2F0%2A617GR3ZXrrxj9_vg.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%2F2756%2F0%2A617GR3ZXrrxj9_vg.png" width="800" height="238"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Perform free end to end &lt;a href="https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress testing online&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus Tip: Cypress Selector Playground
&lt;/h2&gt;

&lt;p&gt;Cypress has another useful feature for users that helps locate CSS selectors easily on pages directly from the test runner. Selector Playground will always match and find the unique locators for the elements to not create an issue when using them.&lt;/p&gt;

&lt;p&gt;Shown below is the priority of the unique locators that Cypress supports:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;data-cy&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;data-test&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;data-testid&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;id&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;class&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;tag&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;attributes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;nth-child&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Where &lt;em&gt;data-&lt;/em&gt;* are the cypress recommended attributes added to the WebElements to isolate the elements from JS/CSS changes that might break the 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%2Fcdn-images-1.medium.com%2Fmax%2F2760%2F0%2Ao0J43rKKhrPlv11I.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%2F2760%2F0%2Ao0J43rKKhrPlv11I.png" width="800" height="473"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Cypress is a cutting-edge browser automation solution that is fast gaining the attention of the software community. It offers a better, more effective approach to web testing and is gaining popularity due to its ability to help teams keep pace with a complete range of application testing.&lt;/p&gt;

&lt;p&gt;By using Cypress, you can take advantage of all built-in locators and features like intelligent matching and asynchronous commands to ensure that each test has no dependencies. In this Cypress tutorial, we have seen how we can use Cypress locators to access WebElements in the DOM for realizing Cypress automation tests. Moreover, although Cypress is built with a strict “no CSS selectors allowed” stance internally, external community packages now exist that allow you to write Cypress tests using XPath.&lt;/p&gt;

&lt;p&gt;Though Cypress has a rich feature set, the true capabilities of Cypress can only be leveraged by running Cypress tests on a scalable cloud-based &lt;a href="https://www.lambdatest.com/?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platform like LambdaTest. LambdaTest Cypress CLI simplifies the task of executing your &lt;a href="https://www.lambdatest.com/cypress-parallel-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress tests in parallel&lt;/a&gt; on a range of &lt;a href="https://www.lambdatest.com/virtual-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov10_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;online browser&lt;/a&gt; and OS combinations hosted on the LambdaTest cloud grid. While writing this blog, there are 40+ browser versions for Cypress testing on the LambdaTest cloud grid.&lt;/p&gt;

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


&lt;/li&gt;

&lt;/ul&gt;

&lt;/ul&gt;

&lt;/ul&gt;

&lt;/li&gt;

</description>
    </item>
    <item>
      <title>Cypress Automation Testing Tutorial: E2E Testing with Cypress</title>
      <dc:creator>Sachinj34</dc:creator>
      <pubDate>Wed, 09 Nov 2022 09:54:22 +0000</pubDate>
      <link>https://forem.com/testmuai/cypress-automation-testing-tutorial-e2e-testing-with-cypress-2bdb</link>
      <guid>https://forem.com/testmuai/cypress-automation-testing-tutorial-e2e-testing-with-cypress-2bdb</guid>
      <description>&lt;p&gt;The demand for Cypress automation testing has increased exponentially with the need to deliver products faster to the market. As per the State of JS survey 2021, Cypress awareness has climbed from 74% in 2020 to 83% in 2021 with 92% satisfaction. Cypress has emerged as a prominent tool for web automation testing in recent years addressing fundamental issues faced by modern web applications. Now Selenium testing has been widely accepted for web &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing&lt;/a&gt;. Which often triggers a debate around &lt;a href="https://www.lambdatest.com/blog/cypress-vs-selenium-comparison/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium vs Cypress&lt;/a&gt;, however, this article isn’t just about resolving the Selenium vs Cypress debate. This is going to be on help you perform Cypress automation testing like a pro.&lt;/p&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/learning-hub/cypress-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress tutorial&lt;/a&gt;, we talk about the Cypress test automation framework that is fundamentally and architecturally different from the &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium test automation&lt;/a&gt;. How to set up and install Cypress and finally, run Cypress automation testing over hundreds of browsers and operating systems using the LambdaTest &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress cloud&lt;/a&gt;.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Introduction To Cypress Automation Testing Framework
&lt;/h2&gt;

&lt;p&gt;Cypress is a purely JavaScript-based front-end testing framework that lets you easily write powerful and flexible tests for your web applications. It enables advanced testing options for both unit tests and integration tests with benefits such as easy test configuration, convenient reporting, intuitive dashboard experience, and more.&lt;/p&gt;

&lt;p&gt;As Cypress supports only JavaScript, it is widely accepted by the developer community. It also has a huge following (around 32K GitHub stars) from developers and QA engineers since the time was publicly released for the community.&lt;/p&gt;

&lt;p&gt;So why Cypress automation is considered an alternative to Selenium?&lt;/p&gt;

&lt;p&gt;Let’s take a look at the architectural differences between Cypress and Selenium and how Cypress is resolving the problems faced in modern-day web application testing.&lt;/p&gt;

&lt;p&gt;Get the best out of your Cypress tests with LambdaTest’s online &lt;a href="https://www.lambdatest.com/cypress-automation-tool?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress automation tool&lt;/a&gt;. Check out how you can execute your Cypress test scripts using LambdaTest’s online cloud.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Online mobile &lt;a href="https://www.lambdatest.com/mobile-emulator-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=" rel="noopener noreferrer"&gt;emulators online&lt;/a&gt; from LambdaTest allows you to seamlessly test your mobile applications, websites,and web apps on mobile browsers and mobile devices.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Selenium Architecture
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt; is a powerful tool for developers that lets you perform automation tests across different browsers. This architecture includes a Selenium server that runs your tests, browser driver corresponding to the browser (under test), and ’N’ number of clients that communicate with the server, typically in the language supported by the Selenium framework.&lt;/p&gt;

&lt;p&gt;Shown below is the top-level architecture diagram of the Selenium 3 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%2F2048%2F0%2Amj5h8yKqUPDY0tYj.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%2F2048%2F0%2Amj5h8yKqUPDY0tYj.png" width="800" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As of writing this blog, Selenium 4 is in the beta stage and open to use for the community. &lt;a href="https://www.lambdatest.com/blog/selenium4-w3c-webdriver-protocol/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium 4 is W3C compliant&lt;/a&gt; which means that test flakiness will be significantly reduced with Selenium 4. A couple of features of Selenium 3 are deprecated in Selenium 4, you can make sure to check &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=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;what is new in Selenium 4 and what is deprecated in it&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now, let’s dive into Cypress architecture and its breakthrough features to understand the difference with Selenium.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Cypress Architecture
&lt;/h2&gt;

&lt;p&gt;Cypress is an open-source &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=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;testing framework based on JavaScript&lt;/a&gt; that supports web application testing. Unlike Selenium, Cypress automation testing works completely on a real browser without the need for driver binaries. The automated code and application code share the same platform, which gives complete control over the application under test.&lt;/p&gt;

&lt;p&gt;To describe the backend story of Cypress test automation, let’s have a look at its high-level architecture.&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%2AqKfORTDkTEM3ynWM.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AqKfORTDkTEM3ynWM.jpg" width="512" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress automation&lt;/a&gt; testing runs on NodeJS server, which communicates with the test runner(Browser) instrumentalized by Cypress to run the application (one of the iframe) and test code(another iframe) in the same event loop.&lt;/p&gt;

&lt;p&gt;Here’s quick video if you have doubts regarding how to handle iframes in Cypress.&lt;/p&gt;

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

&lt;p&gt;This in turn allows the Cypress automation testing code to mock and even change the JavaScript object on the fly. This is one of the primary reasons why Cypress automation testing is expected to execute faster than corresponding Selenium test automation.&lt;/p&gt;

&lt;p&gt;Watch this video to learn how Cypress can be used to automate accessibility testing.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Key benefits of using Cypress test automation framework:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Cypress is easy to set up.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cypress has an in-built wait for requests feature that eliminates the need to configure additional waits.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There is no need for driver binaries in Cypress automation testing and execution happens on the real browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Since test code and application run in the same browser, it can access application JS objects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cypress automation testing lets you change code and execute the same on the fly .&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It provides dashboard support for detailed reporting.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It supports parallel test execution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It has support for BDD and TDD style testing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cypress tests are less flaky due to the auto-wait features supported by the framework.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;At each step, screen grabs that show the test behavior are captured. These can be super helpful in debugging issues with the tests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Detailed documentation and thriving community.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;This &lt;a href="https://www.lambdatest.com/learning-hub/smoke-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;smoke testing&lt;/a&gt; tutorial covers what smoke testing is, its importance, benefits, and how to perform it with real-time examples.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up Cypress Automation Testing
&lt;/h2&gt;

&lt;p&gt;Cypress requires Node JS (&amp;gt;= 12) to be pre-installed on the machine. It is bundled into a singleton package which can be added to your node_modules with npm or yarn using the following commands:&lt;/p&gt;

&lt;p&gt;npm install cypress&lt;/p&gt;

&lt;p&gt;OR&lt;/p&gt;

&lt;p&gt;yard add cypress.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Make sure you have initialized your folder with npm init or package.json file is created under your project folder.&lt;/p&gt;

&lt;p&gt;Once Cypress packages are added to your project directory, you should be able to see the cypress folder added to your project with pre-added tests for sample testing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cypress Test runner&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To open Cypress test runner and view the pre-added tests, run the following command on the terminal:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;npx cypress open&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you manage commands through package.json, then you might write it under scripts that would look something as shown below. In that case, use the following command:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;npm run cy:open&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
...
"scripts":{
"cy:open":"cypress open",
...
}
...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Once you execute the command, the test runner would show up as seen below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2048%2F0%2A3Beedsp0HCRSpQjW.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%2F2048%2F0%2A3Beedsp0HCRSpQjW.png" width="800" height="294"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As in the above screenshot, you can choose to run the specific test by selecting one or run all at the root folder. You can also run the tests by selecting a browser via CLI:&lt;/p&gt;

&lt;p&gt;npx cypress run -- --browser chrome&lt;/p&gt;

&lt;p&gt;Additionally, to run specific file use:&lt;/p&gt;

&lt;p&gt;npx cypress run -- --browser chrome --spec ''&lt;/p&gt;

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

&lt;p&gt;actions.spec.js file is written with Mocha style and uses Cypress built-in commands to launch and interact with the browser. If you’re new to Mocha, you can refer to this &lt;a href="https://www.lambdatest.com/blog/mocha-javascript-tutorial-with-examples-for-selenium-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Mocha tutorial&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;List of a few commands that we would be using is shown below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;cy.visit() — Launch a browser with the URL provided as the argument&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;cy.get() — Get the elements using CSS-selectors&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;type()- Enter the value in input boxes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;{keyCommand} like “{enter}” — Write keyboard actions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Asserts command — Cypress automation testing uses its own BDD style of assertions inspired by likes of Chai&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are a whole bunch of advanced commands around Cypress API, which you can check on the Cypress official website.&lt;/p&gt;

&lt;p&gt;For demonstration of Cypress test automation, we use the Kitchen Sink example which is available on the official GitHub of Cypress.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;describe('Actions', () =&amp;amp;gt; {
  beforeEach(() =&amp;amp;gt; {
    cy.visit('[https://example.cypress.io/commands/actions'](https://example.cypress.io/commands/actions'))
  })

  // [https://on.cypress.io/interacting-with-elements](https://on.cypress.io/interacting-with-elements)

  it('.type() - type into a DOM element', () =&amp;amp;gt; {
    // [https://on.cypress.io/type](https://on.cypress.io/type)
    cy.get('.action-email')
      .type('[fake@email.com](mailto:fake@email.com)').should('have.value', '[fake@email.com](mailto:fake@email.com)')

      // .type() with special character sequences
      .type('{leftarrow}{rightarrow}{uparrow}{downarrow}')
      .type('{del}{selectall}{backspace}')

      // .type() with key modifiers
      .type('{alt}{option}') //these are equivalent
      .type('{ctrl}{control}') //these are equivalent
      .type('{meta}{command}{cmd}') //these are equivalent
      .type('{shift}')

      // Delay each keypress by 0.1 sec
      .type('[slow.typing@email.com](mailto:slow.typing@email.com)', { delay: 100 })
      .should('have.value', '[slow.typing@email.com](mailto:slow.typing@email.com)')

    cy.get('.action-disabled')
      // Ignore error checking prior to type
      // like whether the input is visible or disabled
      .type('disabled error checking', { force: true })
      .should('have.value', 'disabled error checking')
  })

  it('.focus() - focus on a DOM element', () =&amp;amp;gt; {
    // [https://on.cypress.io/focus](https://on.cypress.io/focus)
    cy.get('.action-focus').focus()
      .should('have.class', 'focus')
      .prev().should('have.attr', 'style', 'color: orange;')
  })

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

&lt;/div&gt;

&lt;p&gt;Here is the execution snapshot of the test running on the Chrome browser:&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%2F2048%2F0%2ANBRMM_3xKQhde-ye.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%2F2048%2F0%2ANBRMM_3xKQhde-ye.png" width="800" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Defaults to Spec reporter in the console output:&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%2F2048%2F0%2AnLByZDfVJ9h1c7fj.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%2F2048%2F0%2AnLByZDfVJ9h1c7fj.png" width="800" height="355"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The amazing part to notice about execution is that it auto records your test execution and stores it as a .mp4 file for viewing or sharing with other members in the team.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dashboard services of Cypress test automation framework&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While test runner does a wonderful job of running tests and storing the recorded session for execution, Cypress automation testing provides more amazing features through its paid services. The paid services are completely optional for use but CI integration and parallelization of test runs stand out from the rest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Some of the key features of dashboard services include:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Allows tests to run parallel with CI setup.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Allows tests to be grouped and run for multilevel environments or browsers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Easily integrates with CI tools.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Provides insights into your historical runs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Auto balancing feature to reduce the load on CI servers.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Configuring test to run in the dashboard&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For running tests in Dashboard services, we need to create an account on &lt;a href="https://dashboard.cypress.io/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress Dashboard&lt;/a&gt;. Follow the below steps for creating a projectId and record key.&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%2F2048%2F0%2A8Sl1jwg1Z3EYL3qd.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%2F2048%2F0%2A8Sl1jwg1Z3EYL3qd.png" width="800" height="349"&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%2F2048%2F0%2AG0uDeEa56ifkpep0.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%2F2048%2F0%2AG0uDeEa56ifkpep0.png" width="800" height="337"&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%2F2048%2F0%2AIv4B7Ev20_iJg5ni.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%2F2048%2F0%2AIv4B7Ev20_iJg5ni.png" width="800" height="337"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add your projectId on the cypress.json file:&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;Execute tests on Cypress Dashboard with:&lt;/p&gt;

&lt;p&gt;npx cypress run --record --key&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%2F2048%2F0%2Aeg6gpnFE-E3T2YQB.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%2F2048%2F0%2Aeg6gpnFE-E3T2YQB.png" width="800" height="307"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Try your free &lt;a href="https://www.lambdatest.com/cypress-ui-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress UI automation&lt;/a&gt; testing online.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this &lt;a href="https://www.lambdatest.com/learning-hub/system-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;System testing&lt;/a&gt; tutorial, learn why System testing is important and all the intricacies of the System testing process.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup Cypress Automation Testing with Cloud-based Selenium Grid
&lt;/h2&gt;

&lt;p&gt;While the &lt;a href="https://www.lambdatest.com/blog/getting-started-with-cypress/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt; framework does let you run tests in parallel, achieving optimal browser coverage is impossible when running tests on a local setup. For optimal browser coverage, you need to upgrade your test infrastructure to a Grid-based system so that you can leverage Cypress framework for performing &lt;a href="https://www.lambdatest.com/cypress-ui-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress UI testing&lt;/a&gt; on different browsers and operating systems.&lt;/p&gt;

&lt;p&gt;The need for a cloud-based &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platform like LambdaTest can help resolve the underlying problems to a great extent. Let’s now write a simple Cypress automation testing and see it in action on the LambdaTest platform.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Create a new spec file.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a new spec file google.spec.js under /cypress/integration folder. In the test code, we are searching Cypress on Google and verifying the results containing Cypress as a keyword.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;describe('Search Cypress on Google',()=&amp;amp;gt;{
  it('Open google site',()=&amp;amp;gt;{ 
      cy.visit('[https://www.google.com/'](https://www.google.com/'))
  })

  it('search cypress term in search bar',()=&amp;amp;gt;{ 
      cy.get('[name="q"]').should('be.enabled').type('Cypress{enter}')
  })

  it('Check the results of search',()=&amp;amp;gt;{ 
      cy.get('#search').should('be.visible')
      cy.get('#search').contains('Cypress').should('be.visible')
  })
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Install the LambdaTest Cypress CLI:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;LambdaTest Cypress CLI enables cross browser testing with Cypress. It lets you test your application across different browsers without any hiccups!&lt;/p&gt;

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

&lt;p&gt;Install lamdatest-cypress cli package using npm install lambdatest-cypress-cli under the project root directory. Once installed, lambdatest-config.json is created using the npx lambdatest-cypress-cli init command, which looks like below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "lambdatest_auth": {
       "username": "",
       "access_key": ""
    },
    "browsers": [
       {
          "browser": "Chrome",
          "platform": "Windows 10",
          "versions": [
             "90.0"
          ]
       },
       {
          "browser": "Firefox",
          "platform": "macOS Big Sur",
          "versions": [
             "82.0"
          ]
       }
    ],
    "run_settings": {
       "cypress_config_file": "cypress.json",
       "build_name": "LambdaCypress",
       "parallels": 1,
       "specs": "./cypress/integration/*.spec.js",
       "ignore_files": "",
       "npm_dependencies": {
          "cypress": "6.1.0"
       },
       "feature_file_suppport": false
    },
    "tunnel_settings": {
       "tunnel": false,
       "tunnelName": null
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the above config file, we are specifying browsers Chrome and Firefox with the desired versions and platform configurations. As of writing this blog, LambdaTest supports the following browsers and platforms for &lt;a href="https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress E2E 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%2F2048%2F0%2AhR0Sk_I_ntPJh2BT.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%2F2048%2F0%2AhR0Sk_I_ntPJh2BT.png" width="800" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "name": "cypressdemo",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
      "test": "cypress open",
      "cy:run": "cypress run",
      "record": "cypress run  --record --key ",
      "lambdarun":"lambdatest-cypress run"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dependencies": {
      "cypress": "^5.6.0",
      "lambdatest-cypress-cli": "^2.0.4",
      "typescript": "^4.1.3"
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Run the tests using npm run lambdatest to see the tests in action on the LambdaTest Grid.&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%2F2048%2F0%2AXq3345PV_MW01n1h.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%2F2048%2F0%2AXq3345PV_MW01n1h.png" width="800" height="337"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also view the execution logs in LambdaTest results under the ‘Automation Logs’ option.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2048%2F0%2A5BupF6KegpWRg71E.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%2F2048%2F0%2A5BupF6KegpWRg71E.png" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My recommendations to folks looking for a reliable &lt;a href="https://www.lambdatest.com/automate-cloud-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation cloud testing&lt;/a&gt; framework are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If your applications are built with modern UI frameworks and need component-based test support, then you might think to switch to Cypress eventually (if not on a priority).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Switch to Cypress automation testing if current tests show flakiness and have to be revamped for betterment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you are building a new automated framework that works hand in hand with development and deployment, then a POC on Cypress automation testing is worth a try!&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Trim down your test cycles by executing &lt;a href="https://www.lambdatest.com/cypress-parallel-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress parallel testing&lt;/a&gt; online with LambdaTest. In this Cypress tutorial, we covered the basics of the Cypress &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov09_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation&lt;/a&gt; framework and how its modern architecture resolves the problems faced in modern web automation testing.&lt;/p&gt;

&lt;p&gt;We also looked into its open-source test runner and paid Dashboard services and tried our hands-on with Cypress tests on cloud-based grid LamdaTest. It helps perform cross browser testing with Cypress, along with running tests in parallel on a reliable and scalable cloud grid.&lt;/p&gt;

&lt;p&gt;Take this certification to showcase your expertise with end-to-end testing using Cypress automation testingand stay one step ahead.&lt;/p&gt;

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

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/qL_rgUEI2s0"&gt;
&lt;/iframe&gt;
&lt;br&gt;
Happy Testing!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How To Get Data Of Attributes In JavaScript With Selenium</title>
      <dc:creator>Sachinj34</dc:creator>
      <pubDate>Tue, 08 Nov 2022 07:57:59 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-get-data-of-attributes-in-javascript-with-selenium-3j7o</link>
      <guid>https://forem.com/testmuai/how-to-get-data-of-attributes-in-javascript-with-selenium-3j7o</guid>
      <description>&lt;p&gt;When performing &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov08_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation&lt;/a&gt;, you would have come across umpteen scenarios where there is a need to verify the properties and values of the WebElements. For example, you might need to get the element’s text value in your automation test code and later verify the same against the desired value. In Selenium, the getText() method is used for fetching the text value of the WebElement.&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%2ASF5JpGTtfbDyyqXz.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%2ASF5JpGTtfbDyyqXz.gif" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What if the test scenario is more complicated and just getting the text value of the element is not sufficient? In such cases, you would need to use additional (and relevant) properties of the WebElements. Similarly, we may face a situation where just verifying text value is not enough for testing and we need to get additional properties of the elements that are statically or dynamically available in the DOM. Be it JavaScript or some other Selenium-supported programming language, getting specific attributes of the WebElements can be super useful in Selenium automation testing.&lt;/p&gt;

&lt;p&gt;In this blog, we deep dive into how to get the data attribute in JavaScript for building superlative Selenium automation test scenarios.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Attributes in HTML
&lt;/h2&gt;

&lt;p&gt;Attributes in HTML play an important role by giving additional information about the HTML elements. It also can be used to change the behavior of the elements by implementing events on them. Attributes in HTML are commonly defined using name-value pairs.&lt;/p&gt;

&lt;p&gt;The name is the property you want to set. For example, the image tag&lt;/p&gt;

&lt;p&gt;element in the example carries an attribute whose name is src, which indicates the source of the image.&lt;/p&gt;

&lt;p&gt;The value indicates the value to which the corresponding property needs to be set. It is always enclosed in quotations. Here is the example which shows the value of the image with the .jpeg extension.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src='imagename.jpeg'/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Attribute names and attribute values are case-insensitive. However, the World Wide Web Consortium (W3C) recommends lowercase attributes (or attribute values) as a part of the HTML 4 recommendation. You can check our earlier blog that helps you understand &lt;a href="https://www.lambdatest.com/blog/selenium-getattribute/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov08_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;how to get attribute value in Selenium WebDriver&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this &lt;a href="https://www.lambdatest.com/learning-hub/data-driven-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov08_kj&amp;amp;utm_term=kj&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Data driven testing&lt;/a&gt; tutorial, let us deep dive into what data driven testing is, its pros &amp;amp; cons, its types, data driven testing in an agile environment, benefits, and their best practices.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Commonly used Attributes in Automation Testing
&lt;/h2&gt;

&lt;p&gt;Though there are a number of attributes in HTML, only some from the lot are majorly used for automation testing. Here are some of the commonly used attributes in HTML:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;id&lt;/strong&gt;: The id attribute is used to identify unique WebElements across the DOM&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;class&lt;/strong&gt;: The class attribute provides a way of classifying similar WebElements&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;style&lt;/strong&gt;: The style attribute is used for adding CSS styling to the WebElements&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;title&lt;/strong&gt;: The title attribute is used for providing contextual information of the elements. In almost all web browsers, the title of the element can display as a tooltip on hovering the mouse over the window.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Major Types of Attributes
&lt;/h2&gt;

&lt;p&gt;Listed below are some of the major categories (or types) of attributes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Required Attributes&lt;/strong&gt;: These attributes cannot be omitted from HTML tags. For example, an image is not displayed on the page without src for &lt;a href="" class="article-body-image-wrapper"&gt;&lt;img&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Optional Attributes&lt;/strong&gt;: These attributes should be added to give more meaning to the elements. For example — title for &lt;a href="" class="article-body-image-wrapper"&gt;&lt;img&gt;&lt;/a&gt; provides a title to the image but it is not a compulsory attribute.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Event Attributes&lt;/strong&gt;: These attributes are events that are triggered based on the user actions. For example — The onmouseover event on any html element is triggered when the user hovers the mouse pointer to that particular WebElement.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Standard Attributes&lt;/strong&gt;: These are also known as global attributes. This category of attributes can be used in almost all the HTML tags (e.g. id, class, style, etc.).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Attributes in HTML play an increasingly important role in Selenium automation testing. Now that we have covered the basics of attributes in HTML, let’s look at the essential aspects of how to get data of attributes in Selenium JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why are Attributes important for Automation testing
&lt;/h2&gt;

&lt;p&gt;Attributes can change the behavior of WebElements depending on the scenarios (or events) used for performing automation testing. Let’s take the case of a bus booking application. Here, booked seats are normally represented with the “Grey” colour, whereas the “Green” colour indicates that the seats are available for booking. In case there is a misrepresentation of the colours, customers would face problems in booking tickets. Customers would lose trust in the brand, which in turn could hamper the revenue of the company.&lt;/p&gt;

&lt;p&gt;Hence, it becomes extremely critical to test whether booked and available tickets are represented with the right colour coding.&lt;/p&gt;

&lt;p&gt;Manual testing is not preferred since it is not a scalable and reliable approach. However, such scenarios can be tested by getting data of attributes in Selenium JavaScript. Thus, it is an ideal testing approach before the build goes to the production environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Run your &lt;a href="https://www.lambdatest.com/jest?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov08_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Jest automation&lt;/a&gt; tests in massive parallel across multiple browser and OS combinations with LambdaTest, Read more.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to get Data of Attributes in Selenium JavaScript Tests
&lt;/h2&gt;

&lt;p&gt;Selenium is a popular tool for web automation testing due to its large open source community support and ease of writing tests in the programming language of your choice. In addition, the Selenium automation framework is widely used for &lt;a href="https://www.lambdatest.com/learning-hub/cross-browser-compatibility?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov08_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser compatibility testing&lt;/a&gt; that ensures that the website (or web app) runs uniformly across different browser, platform, and device combinations.&lt;/p&gt;

&lt;p&gt;Using Selenium and JavaScript, you can get the data of the attributes of the HTML elements displayed in the current state on the website (or web application). In addition, you can also verify the changed data of the attributes once the occurrence of events changes in the properties (e.g. colour, link updates for anchor tags, etc.) of the WebElements.&lt;/p&gt;

&lt;h2&gt;
  
  
  getAttribute() In Selenium
&lt;/h2&gt;

&lt;p&gt;Selenium’s getAttribute() method is used to get attributes of HTML elements under test. This method is a part of the WebElement Class. The getAttribute() method can be used for getting values for different attributes like class, name,src, CSS style value, etc.&lt;/p&gt;

&lt;p&gt;More precisely, this Selenium method returns the data of the given attribute if that particular attribute is present else, it returns null. For example — the getAttribute() method can be used to fetch the ‘value’ property of the textarea element. The “style” attribute is converted to a text representation with a trailing semicolon.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var ele = driver.findElement(By.id('#'));
var attribute_value= ele.getAttribute('attribute_name');  // returns the attribute value
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Demonstration — How to get Data of Attributes in Selenium JavaScript
&lt;/h2&gt;

&lt;p&gt;Before we demonstrate how to get data of attributes in Selenium using JavaScript, it’s essential to have the basic setup ready for Selenium test automation. You can refer to our earlier blog titled &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=nov08_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Automation Testing With Selenium JavaScript&lt;/a&gt; to set up an environment for writing tests in Selenium with JavaScript bindings.&lt;/p&gt;

&lt;p&gt;Alternatively, you can also check out the &lt;a href="https://www.youtube.com/c/LambdaTest?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov08_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube channel&lt;/a&gt; for videos that guide you through the Selenium JavaScript journey.&lt;/p&gt;

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

&lt;p&gt;Consider a sample application that sells different types of pens online. This is what we plan to achieve as a part of the demonstration of how to get data of attributes using Selenium and JavaScript.&lt;/p&gt;

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

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

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

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

&lt;p&gt;Two scenarios will be automated using Selenium and JavaScript. First, we get data of the relevant attributes on the page.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Verify if the product colour is the same as what is displayed to the user when the user tries to hover over the colour swatches shown in the filter section.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Verify whether the user sees the correct product name as it is fetched from the backend.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;The tests are run on the cloud-based Selenium Grid by LambdaTest. The advantage of cloud-based Grid is that Selenium test automation can be performed across a range of browsers, platforms, and device combinations at scale.&lt;/p&gt;

&lt;p&gt;You can perform &lt;a href="https://www.lambdatest.com/blog/what-is-parallel-testing-and-why-to-adopt-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov08_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing in Selenium&lt;/a&gt; to leverage the advantages of speed and scale offered by the LambdaTest Grid. Once you create an account on LambdaTest, make a note of the username &amp;amp; access key from the &lt;a href="https://accounts.lambdatest.com/detail/profile?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov08_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest profile section&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Use the &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov08_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest capabilities generator&lt;/a&gt; to generate the desired browser capabilities against which Selenium test automation has to be performed. Set the environment variables LT_user &amp;amp; LT_token to LambdaTest username &amp;amp; access key respectively.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require('dotenv').config();
exports.config = {
  LT_user:  process.env.LT_user, // Your LambdaTest username
  LT_pass:process.env.LT_token, // Your LambdaTest token
  capabilities: {
  'build':  'Mocha-Selenium-Sample', //Build name
  'name':  'Test sample for getAttribute()', // Test name
  'platform':  'Windows 10', // OS name
  'browserName':  'chrome', // Browser name
  'version':  'latest', // Browser version
  'visual':  true, // To take step by step screenshot
  'network':  true, // To capture network Logs
  'console':  true, // To capture console logs.
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;For demonstration, we use the Selenium 4 (Beta 2) version of &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov08_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt;. To know more about the offerings of Selenium 4, please have a look at &lt;a href="https://www.lambdatest.com/learning-hub/selenium-4?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov08_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium 4 on LambdaTest Learning Hub&lt;/a&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "lambdatest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "mocha --recursive --timeout 300000 ./tests/tests.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "chromedriver": "^89.0.0",
    "dotenv": "^8.2.0",
    "mocha": "^8.3.2",
    "selenium-webdriver": "^4.0.0-beta.2"
  }
}



require('chromedriver');
const assert = require('assert');
const { Builder, By } = require('selenium-webdriver');
const { config } = require('../conf/conf.js');
const conf=require("../conf/conf.js").config;
const USERNAME = conf.LT_user
const KEY = conf.LT_pass;
const GRID_HOST = 'hub.lambdatest.com/wd/hub';

describe('Check Colours in filter section', function () {
    let driver;

    before(async function () {
        let caps=conf.capabilities;
        let gridUrl='https://' + USERNAME + ':' + KEY + '@' + GRID_HOST;
        console.log(gridUrl)
        driver = await new Builder().usingServer(gridUrl).withCapabilities(caps).build();
        await driver.get('https://www.pens.com/ie/c/pens-writing');

    });

    it('Verify the colour matches the swatch title', async function () {

        let list = await driver.findElements(By.css("a[class='colour-swatch ']"));
        let colour=[];
        for (item of list) {
            //Using getAttribute to get the data
            let col = await item.getAttribute("title");
            colour.push(col)
        }
        console.log(colour)

    });

    it('Check the Product name matches with data attribute', async function(){ 
        let product_data_attribute = await driver.findElement(By.id('product-card-1'));
        let product_name_displayed = await driver.findElement(By.className('product-card__name'));
        console.table([await product_data_attribute.getAttribute('data-prod-name') , await product_name_displayed.getText()])

    });

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

&lt;/div&gt;

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

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

&lt;p&gt;Browser capabilities that are declared in conf.js are used in the test implementation. The test will be run across Chrome 89.0 on the Windows 10 platform. The LambdaTest Grid on which Selenium web automation is performed is set to hub.lambdatest.com/wd/hub.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let caps=conf.capabilities;
let gridUrl='[https://'](https://') + USERNAME + ':' + KEY + '@' + GRID_HOST;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt;&lt;br&gt;
The get method of Selenium WebDriver is used for setting the test URL.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await driver.get('[https://www.pens.com/ie/c/pens-writing'](https://www.pens.com/ie/c/pens-writing'));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt;&lt;br&gt;
The findElements method in Selenium is used for locating the WebElements using the CSS Selector property. You can check our blog on &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=nov08_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;how pro testers make use of CSS Selectors for Selenium web automation&lt;/a&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let list = await driver.findElements(By.css("a[class='colour-swatch ']"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Inspect tool in the Chrome browser is used for locating the WebElements.&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%2F2048%2F0%2AgPeE6slg8RwAgddr.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%2F2048%2F0%2AgPeE6slg8RwAgddr.png" width="800" height="392"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Navigate through the entire list to get the attribute “title” for each element.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (item of list) {
            //Using getAttribute to get the data
            let col = await item.getAttribute("title");
            colour.push(col)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As shown below, the title of the corresponding element in the list is White. On similar lines, you would have titles like Black, Light Blue, Blue, etc. for elements in the list.&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%2F2048%2F0%2AhNWepfbF7Jm7t9UV.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%2F2048%2F0%2AhNWepfbF7Jm7t9UV.png" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt;&lt;br&gt;
In the function “Check the Product name matches with data attribute”, we first locate the WebElement using the ID property (i.e. product-card-1).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let product_data_attribute = await driver.findElement(By.id('product-card-1'));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt;&lt;br&gt;
Using the className property in Selenium, we locate the WebElement product-card__name&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let product_name_displayed = await driver.findElement(By.className('product-card__name'));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is how we located the WebElement using the Inspect Tool in Chrome (or Chrome DevTools):&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%2F2048%2F0%2ANSFiPLqWwAJMXMZO.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%2F2048%2F0%2ANSFiPLqWwAJMXMZO.png" width="800" height="382"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt;&lt;br&gt;
The console.table function in JavaScript is used for displaying the data in a tabular format. The getAttribute method in Selenium is used to fetch the data-prod-name attribute for each item.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.table([await product_data_attribute.getAttribute('data-prod-name') , await product_name_displayed.getText()])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is how the Inspect Tool in Chrome is used to get the details of the corresponding attribute:&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%2F2048%2F0%2Ao4sgQLZfV5o1alVy.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%2F2048%2F0%2Ao4sgQLZfV5o1alVy.png" width="800" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Trigger the following command on the terminal to run the example that demonstrates how to get data of attributes in Selenium using JavaScript.&lt;/p&gt;

&lt;p&gt;npm test&lt;/p&gt;

&lt;p&gt;Here is the execution snapshot from the terminal and the &lt;a href="https://automation.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov08_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest automation dashboard&lt;/a&gt; which indicates that the test execution was successful.&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%2AkR8k-vf6OcNvn4Uw.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%2AkR8k-vf6OcNvn4Uw.png" width="475" height="547"&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%2AtEO8-hVxYPnoQvnN.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%2AtEO8-hVxYPnoQvnN.png" width="565" height="469"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Run &lt;a href="https://www.lambdatest.com/appium-mobile-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov08_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Appium&lt;/a&gt; mobile testing of native and web apps. Improve your app quality with instant access to real devices on LambdaTest. Register now for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  That’s All Folks
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AFFURoWx2wtf2COp5.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%2AFFURoWx2wtf2COp5.gif" width="450" height="253"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this blog, we learnt how to read (or get) data of attributes using JavaScript and Selenium. This can be used in Selenium web automation scenarios where you have to read the values of the attributes on the page.&lt;/p&gt;

&lt;p&gt;The getAttribute() method in Selenium is used for reading the value of the corresponding attribute. We also implemented getAttribute() in the Selenium Grid cloud offered by LambdaTest and tested the same against the Chrome browser installed on Windows 10. Thus, browser compatibility testing at a large scale can be performed using a cloud-based Selenium Grid like LambdaTest. Furthermore, it lets you run automation tests across 2,000+ browsers and operating systems online.&lt;/p&gt;

&lt;p&gt;It’s best to leverage the advantages offered by cloud-based Selenium Grid so that you can get data of attributes in Selenium JavaScript in a more efficient manner.&lt;/p&gt;

&lt;p&gt;Happy Testing with Selenium and JavaScript!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>selenium</category>
      <category>javascript</category>
      <category>testing</category>
    </item>
    <item>
      <title>How To Generate Mocha Reports With Mochawesome?</title>
      <dc:creator>Sachinj34</dc:creator>
      <pubDate>Mon, 07 Nov 2022 09:28:23 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-generate-mocha-reports-with-mochawesome-564h</link>
      <guid>https://forem.com/testmuai/how-to-generate-mocha-reports-with-mochawesome-564h</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;“Testing leads to failure, and failure leads to understanding.”&lt;br&gt;
Burt Rutan&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It goes without saying that the very essence of testing lies in locating issues so that they can be worked upon. This results in a better-quality &amp;amp; well-performing web application (or website) that is important in building a positive customer experience. However, as the automation test builds grow with time, maintaining and organizing the tests in a more readable format becomes even more challenging. When writing Mocha scripts for JavaScript automation testing, I came across a handy Mocha report generator utility called Mochawesome.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What does Mochawesome do?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Mochawesome is a custom Mocha reporter that allows you to create standalone HTML/CSS test reports based on the execution of your Mocha test scripts. Mochawesome brings the intuitiveness that is sorely missing in default Mocha reports. This eventually helps in managing the Selenium test automation builds in a better way.&lt;/p&gt;

&lt;p&gt;In this article, I will showcase how to make the most of Mochawesome to generate visually appealing yet detailed test reports from your Mocha scripts.&lt;/p&gt;

&lt;p&gt;But, before we jump into Mocha reporter, let’s first understand what the Mocha test framework is all about in the Selenium test automation world.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Mocha?
&lt;/h2&gt;

&lt;p&gt;Mocha is the modern-day JavaScript test framework that executes on Node.js. It is used for writing unit tests and End-to-End (E2E) automated tests for API, Web UI, performance tests, and more. Popular frameworks like Cypress, &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov07_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt;, WebDriverIO all have supported Mocha as their core style of writing tests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/selenium-automation-testing-with-mocha-framework?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov07_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Mocha for Selenium automation testing&lt;/a&gt;, thus, has wide acceptance in the Javascript community because of its simple and rich features, using which you can write simply as well as complex test cases.&lt;/p&gt;

&lt;p&gt;To get detailed information on Mocha, please refer to the &lt;a href="https://www.lambdatest.com/blog/mocha-javascript-tutorial-with-examples-for-selenium-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov07_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Mocha Tutorial by LambdaTest&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Default Mocha Report Generator
&lt;/h2&gt;

&lt;p&gt;Spec is the default reporter in Mocha. The Spec Mocha reporter generates the report as a hierarchical view. The Spec reports are nested based on test cases.&lt;/p&gt;

&lt;p&gt;To generate reports via the default Mocha Report Generator (i.e., Spec), you don’t need to pass any particular command. The Mocha tests are executed with the help of a –spec modifier. This modifier generates a report while executing the tests.&lt;/p&gt;

&lt;p&gt;For example, consider a simple Mocha script as search_basic.js:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const assert = require('assert')
describe('Mocha Works?', () =&amp;gt; {
    it('Mocha Run test', () =&amp;gt; {
        assert.ok(true, 'Failed test')
    });
    it('Should return -1 if value not present', ()=&amp;gt;{ 
        assert.strictEqual([1,2,3].indexOf(5), 'Failed to find')
    });
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To execute the above tests and generate the report using Spec, run the following command on the terminal:&lt;/p&gt;

&lt;p&gt;npx mocha --spec search_basic.js&lt;/p&gt;

&lt;p&gt;Upon execution, the default Mocha report generator (i.e., Spec) will generate a report resembling the actual test case hierarchy. It provides the essential details about the test results.&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%2F2048%2F0%2AWR9831t6I0091g3-.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%2F2048%2F0%2AWR9831t6I0091g3-.png" width="800" height="284"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here are the other Mocha report generator tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;DOT Matrix&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Nyan&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;List&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Progress&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;h2&gt;
  
  
  Limitations Of Default Mocha Reporter
&lt;/h2&gt;

&lt;p&gt;While these Mocha reporters generate reports on the terminal window in their different styles, they lack sufficient details of the tests. This is particularly important when running many tests, or the tests are complex in nature.&lt;/p&gt;

&lt;p&gt;Reports are expected to visualize the test details, failures, screenshots, time for execution, logging details, and more. Hence, the Spec Mocha report generator might not be the one to meet your ‘detailed’ reporting needs.&lt;/p&gt;

&lt;p&gt;Luckily, other Mocha report generators generate the reports in popular formats like HTML/CSS, XML, and JSON. These reports have visual appeal and provide the much-needed intuitiveness in the reports. Mochawesome is one such Mocha reporter, which is extensively used with JavaScript automation testing with Selenium.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mochawesome — The Mocha Report Generator You Need
&lt;/h2&gt;

&lt;p&gt;Mochawesome is one such Mocha Reporter that generates standalone HTML/CSS reports to visualize your JavaScript Mocha tests simply and efficiently. Mochawesome runs on Node.js (&amp;lt;=10) and is supported on all the leading test frameworks that support the Mocha style of writing 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%2F2000%2F0%2ABMkL-VYCohWLam6V.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%2ABMkL-VYCohWLam6V.png" width="800" height="1006"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages Of Using Mochawesome Report Generator
&lt;/h2&gt;

&lt;p&gt;Here are the significant advantages of Mochawesome in comparison to the other Mocha reporting tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Mochawesome report is designed in a mobile-friendly and straightforward way. It uses chartJS for the visualization of test reports.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It has supports display of different types of hooks — before(), beforeEach(), after(),afterAll() and so on.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Failure at a particular line of code is directly visible in the report itself due to the inline code review feature in Mochawesome.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It has support for stack trace logs and failure messages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can add extra context information to tests like console logs, environment details, custom messages to tests as an attachment. This gives the additional hand of information about the test cases in the report.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Since the reports are generated with standalone HTML/CSS, they can be shared offline with .HTML extension.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How To Generate Reports With Mochawesome Report Generator
&lt;/h2&gt;

&lt;p&gt;To generate reports using the Mochawesome report generator, we first need to add them to our existing project. Follow the below steps to add Mochawesome to the project:&lt;/p&gt;

&lt;p&gt;npm install mochawesome mochawesome-report-generator --save-dev&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[Used to add Mochawesome only to the current directory]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;npm install -g mochawesome mochawesome-report-generator&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[Used to add Mochawesome globally]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2020%2F0%2Arsr9lQlyBaHYhq84.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%2F2020%2F0%2Arsr9lQlyBaHYhq84.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once Mochawesome is added, you can create Mocha reports using Mochawesome using the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx mocha --spec search_basic.js --reporter mochawesome
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The command for Mochawesome differs from the command used with the default Mocha report generator on two terms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;reporter is used to specify that we want to use the reporter option to generate Mocha reports.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;mochawesome is used to specify that we will be using the Mochawesome report generator instead of the default Mocha reporter.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is how you can run the command on the search_basic.js 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%2F2034%2F0%2AHoR41Pc92Yb41Jxp.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%2F2034%2F0%2AHoR41Pc92Yb41Jxp.png" width="800" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As soon as you run the above command, the single test file search_basic.js gets executed. Upon execution, the report will be generated using the Mochawesome report generator in the folder mochawesome-report, which is created at the root level of the current project. This folder will contain the Mochawesome in two formats — HTML and JSON.&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%2AICsnzS6yniKbYSGI.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%2AICsnzS6yniKbYSGI.png" width="209" height="513"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Mocha HTML Report By Mochawesome
&lt;/h2&gt;

&lt;p&gt;Let us have a closer look at the contents of the reports generated with the help of the Mochawesome report generator.&lt;/p&gt;

&lt;p&gt;First, let’s open the HTML report generated in the mochawesome.html 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%2F2048%2F0%2AiGUa1U9ldpucgSyI.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%2F2048%2F0%2AiGUa1U9ldpucgSyI.png" width="800" height="355"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The HTML report generated by Mochawesome shows the test execution time, passed/failed tests, and other relevant project information. If you click on the individual tests, you can even see whether the actual tests passed/failed along with the detailed error reports.&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%2F2048%2F0%2AaFY-1lKttg2NJHmK.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%2F2048%2F0%2AaFY-1lKttg2NJHmK.png" width="800" height="357"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Mocha JSON Report By Mochawesome
&lt;/h2&gt;

&lt;p&gt;Let’s have a closer look at the contents of the JSON report generated in the mochawesome.json file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "stats": {
    "suites": 1,
    "tests": 2,
    "passes": 1,
    "pending": 0,
    "failures": 1,
    "start": "2021-05-24T00:57:43.809Z",
    "end": "2021-05-24T00:57:43.840Z",
    "duration": 31,
    "testsRegistered": 2,
    "passPercent": 50,
    "pendingPercent": 0,
    "other": 0,
    "hasOther": false,
    "skipped": 0,
    "hasSkipped": false
  },
  "results": [
    {
      "uuid": "49dac235-26c3-4787-aa2a-3bb9f4b95c99",
      "title": "",
      "fullFile": "",
      "file": "",
      "beforeHooks": [],
      "afterHooks": [],
      "tests": [],
      "suites": [
        {
          "uuid": "2ee44ad6-1759-4923-b1c1-8a621be13ef8",
          "title": "Mocha Works?",
          "fullFile": "C:\\Users\\RishabhPrabhu\\Documents\\mocha-selenium-sample-master\\mocha-selenium-sample-master\\specs\\search_basic.js",
          "file": "\\specs\\search_basic.js",
          "beforeHooks": [],
          "afterHooks": [],
          "tests": [
            {
              "title": "Mocha Run test",
              "fullTitle": "Mocha Works? Mocha Run test",
              "timedOut": false,
              "duration": 1,
              "state": "passed",
              "speed": "fast",
              "pass": true,
              "fail": false,
              "pending": false,
              "context": null,
              "code": "assert.ok(true, 'Failed test')",
              "err": {},
              "uuid": "6a817446-6b84-46ea-aa32-43f100fce9b2",
              "parentUUID": "2ee44ad6-1759-4923-b1c1-8a621be13ef8",
              "isHook": false,
              "skipped": false
            },
            {
              "title": "Should return -1 if value not present",
              "fullTitle": "Mocha Works? Should return -1 if value not present",
              "timedOut": false,
              "duration": 3,
              "state": "failed",
              "speed": null,
              "pass": false,
              "fail": true,
              "pending": false,
              "context": null,
              "code": "assert.strictEqual([1,2,3].indexOf(5), 'Failed to find')",
              "err": {
                "message": "AssertionError: Expected values to be strictly equal:\n+ actual - expected\n\n+ -1\n- 'Failed to find'",
                "estack": "AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:\n+ actual - expected\n\n+ -1\n- 'Failed to find'\n    at Context.&amp;lt;anonymous&amp;gt; (specs\\search_basic.js:7:16)\n    at processImmediate (internal/timers.js:462:21)",
                "diff": null
              },
              "uuid": "fbc9b77c-2b64-4d25-9f32-2c3b29e957c5",
              "parentUUID": "2ee44ad6-1759-4923-b1c1-8a621be13ef8",
              "isHook": false,
              "skipped": false
            }
          ],
          "suites": [],
          "passes": [
            "6a817446-6b84-46ea-aa32-43f100fce9b2"
          ],
          "failures": [
            "fbc9b77c-2b64-4d25-9f32-2c3b29e957c5"
          ],
          "pending": [],
          "skipped": [],
          "duration": 4,
          "root": false,
          "rootEmpty": false,
          "_timeout": 2000
        }
      ],
      "passes": [],
      "failures": [],
      "pending": [],
      "skipped": [],
      "duration": 0,
      "root": true,
      "rootEmpty": true,
      "_timeout": 2000
    }
  ],
  "meta": {
    "mocha": {
      "version": "6.2.3"
    },
    "mochawesome": {
      "options": {
        "quiet": false,
        "reportFilename": "mochawesome",
        "saveHtml": true,
        "saveJson": true,
        "consoleReporter": "spec",
        "useInlineDiffs": false,
        "code": true
      },
      "version": "6.2.2"
    },
    "marge": {
      "options": null,
      "version": "5.2.0"
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The Mochawesome JSON report is very much extensive and contains every bit of information related to the tests. These JSON files can be very useful to transfer data via APIs, making them ideal for other applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Need a great solution for &lt;a href="https://www.lambdatest.com/safari-browser-for-windows?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov07_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Safari for windows&lt;/a&gt; browser testing on Windows? Forget about emulators or simulators — use real online browsers. Try LambdaTest for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Mochawesome Report For Parallel Tests
&lt;/h2&gt;

&lt;p&gt;Check out our blog to figure out &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=nov07_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;why parallel testing is important in Selenium automation testing&lt;/a&gt;. With Mochawesome, you can also create Mocha reports for tests run in parallel.&lt;/p&gt;

&lt;p&gt;To do so, just add –parallel modifier in the execution command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx mocha --spec specs/search_basic.js --reporter mochawesome --parallel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can also execute multiple test files in parallel and generate the report using the Mochawesome report generator. To do so, simply add the following script in 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": {
    "test": "mocha --spec ./tests/*.js --reporter mochawesome --parallel"
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;./tests/*.js indicates that all the test files inside the tests folder will be executed in parallel (with the help of –parallel modifier).&lt;/p&gt;

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

&lt;p&gt;npm test&lt;/p&gt;

&lt;h2&gt;
  
  
  Generating Mochawesome Report Under Custom Folder
&lt;/h2&gt;

&lt;p&gt;By default, Mochawesome generates the Mocha reports by creating a folder by the name mochawesome-reports. What if you want to use the Mocha reporter to generate reports in a specific folder. WellMochawesome lets you create reports under a custom folder.&lt;/p&gt;

&lt;p&gt;The --reporter-options modifier should generate reports under a custom folder with a custom filename. Pass the custom folder name to reportDir and custom filename path as the value to reportFilename.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx mocha --spec specs/search_basic.js --reporter mochawesome --reporter-options reportDir=myReport,reportFilename=reportFile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As soon as the command is executed, the tests will run in Mocha style, and the reports will be generated with the help of the Mochawesome report generator. This time, the reports will be saved in the specified directory with the filename passed in the command.&lt;/p&gt;

&lt;p&gt;As seen below, the reports were generated in the designated 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%2AKvmYpwGtAnbzP-Xn.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%2AKvmYpwGtAnbzP-Xn.png" width="211" height="536"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Mochawesome Advanced Reporter Options
&lt;/h2&gt;

&lt;p&gt;The Mochawesome Mocha report generator utility also provides advanced reporter-options that work with CLI and through the .mocharc.js file. This file has to be configured for overwriting default reporter settings.&lt;/p&gt;

&lt;p&gt;Here are the commonly used Mochawesome advanced reporter options for generating Mocha reports:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;FLAG&lt;/th&gt;
&lt;th&gt;TYPE&lt;/th&gt;
&lt;th&gt;DEFAULT&lt;/th&gt;
&lt;th&gt;DESCRIPTION&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;-f, –reportFilename&lt;/td&gt;
&lt;td&gt;string&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;Filename of saved report&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-o, –reportDir&lt;/td&gt;
&lt;td&gt;string&lt;/td&gt;
&lt;td&gt;[cwd]/mochawesome-report&lt;/td&gt;
&lt;td&gt;Path to save report&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-t, –reportTitle&lt;/td&gt;
&lt;td&gt;string&lt;/td&gt;
&lt;td&gt;mochawesome&lt;/td&gt;
&lt;td&gt;Report title&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-p, –reportPageTitle&lt;/td&gt;
&lt;td&gt;string&lt;/td&gt;
&lt;td&gt;mochawesome-report&lt;/td&gt;
&lt;td&gt;Browser title&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-i, –inline&lt;/td&gt;
&lt;td&gt;boolean&lt;/td&gt;
&lt;td&gt;FALSE&lt;/td&gt;
&lt;td&gt;Inline report assets (scripts, styles)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;–cdn&lt;/td&gt;
&lt;td&gt;boolean&lt;/td&gt;
&lt;td&gt;FALSE&lt;/td&gt;
&lt;td&gt;Load report assets via CDN (unpkg.com)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;–assetsDir&lt;/td&gt;
&lt;td&gt;string&lt;/td&gt;
&lt;td&gt;[cwd]/mochawesome-report/assets&lt;/td&gt;
&lt;td&gt;Path to save report assets (js/css)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;–charts&lt;/td&gt;
&lt;td&gt;boolean&lt;/td&gt;
&lt;td&gt;FALSE&lt;/td&gt;
&lt;td&gt;Display Suite charts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;–code&lt;/td&gt;
&lt;td&gt;boolean&lt;/td&gt;
&lt;td&gt;TRUE&lt;/td&gt;
&lt;td&gt;Display test code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;–autoOpen&lt;/td&gt;
&lt;td&gt;boolean&lt;/td&gt;
&lt;td&gt;FALSE&lt;/td&gt;
&lt;td&gt;Automatically open the report&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;–overwrite&lt;/td&gt;
&lt;td&gt;boolean&lt;/td&gt;
&lt;td&gt;TRUE&lt;/td&gt;
&lt;td&gt;Overwrite existing report files.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;–timestamp, –ts&lt;/td&gt;
&lt;td&gt;string&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;Append timestamp in specified format to report filename.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;–showPassed&lt;/td&gt;
&lt;td&gt;boolean&lt;/td&gt;
&lt;td&gt;TRUE&lt;/td&gt;
&lt;td&gt;Set initial state of “Show Passed” filter&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;–showFailed&lt;/td&gt;
&lt;td&gt;boolean&lt;/td&gt;
&lt;td&gt;TRUE&lt;/td&gt;
&lt;td&gt;Set initial state of “Show Failed” filter&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;–showPending&lt;/td&gt;
&lt;td&gt;boolean&lt;/td&gt;
&lt;td&gt;TRUE&lt;/td&gt;
&lt;td&gt;Set initial state of “Show Pending” filter&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;–showSkipped&lt;/td&gt;
&lt;td&gt;boolean&lt;/td&gt;
&lt;td&gt;FALSE&lt;/td&gt;
&lt;td&gt;Set initial state of “Show Skipped” filter&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;–showHooks&lt;/td&gt;
&lt;td&gt;string&lt;/td&gt;
&lt;td&gt;failed&lt;/td&gt;
&lt;td&gt;Set the default display mode for hooks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;–saveJson&lt;/td&gt;
&lt;td&gt;boolean&lt;/td&gt;
&lt;td&gt;FALSE&lt;/td&gt;
&lt;td&gt;Should report data be saved to JSON file&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;–saveHtml&lt;/td&gt;
&lt;td&gt;boolean&lt;/td&gt;
&lt;td&gt;TRUE&lt;/td&gt;
&lt;td&gt;Should report be saved to HTML file&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;–dev&lt;/td&gt;
&lt;td&gt;boolean&lt;/td&gt;
&lt;td&gt;FALSE&lt;/td&gt;
&lt;td&gt;Enable dev mode (requires local webpack dev server)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-h, –help&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;Show CLI help&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  LambdaTest — An Online Cloud-Based Solution To Meet All Your Testing Needs
&lt;/h2&gt;

&lt;p&gt;The size of the Mocha reports is bound to increase when more tests are added to the test suite. This might create issues when it comes to the maintenance of the report. To top it all, the lack of advanced visual options such as graphs, plots, etc., are the major drawbacks in local Mocha report generators.&lt;/p&gt;

&lt;p&gt;In addition to this, Mocha reporter can be used only on the local Selenium Grid. Here are some of the significant drawbacks of local Selenium setup (when used with Mocha):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Testing on a local Selenium Grid lets you test only on specific browser and OS combinations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Running Mocha tests on browser versions other than the ones installed on your machine is not possible.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Performing parallel testing on multiple browser versions is still a challenge for Selenium Grid setup.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To overcome these challenges of local Selenium setup and Mocha reporter, you can use a cloud-based Selenium Grid like LambdaTest. The cloud-based Selenium Grid helps run Mocha tests 24/7 and saves the trouble of maintaining local infrastructure.&lt;/p&gt;

&lt;p&gt;With LambdaTest, you can download the report of the automated tests in just a click, that too independent of the programming language being used for test case development. All you need to do is run your Mocha tests on the LambdaTest platform and use the Download Report option to download the detailed report.&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%2F2048%2F0%2ATS9RdbFRMCruh9rw.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%2F2048%2F0%2ATS9RdbFRMCruh9rw.png" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/windows-7-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov07_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Test on Windows 7&lt;/a&gt; across latest and legacy Windows 7 browsers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running Tests On LambdaTest Platform
&lt;/h2&gt;

&lt;p&gt;Let’s explore the benefits of using LambdaTest’s cloud-based Selenium Grid with an example. For demonstration, we perform a simple Google search and assert the first result with a fixed key:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var assert = require("assert"),
  webdriver = require("selenium-webdriver"),
  conf_file = process.argv[3] || "conf/single.conf.js";

var capabilities = require("../" + conf_file).capabilities;

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

capabilities.forEach(function(caps) {

  describe("Google's Search Functionality for " + caps.browserName, function() {
    var driver;
    this.timeout(0);

    beforeEach(function(done) {
      caps.name = this.currentTest.title;
      driver = buildDriver(caps);
      done();
    });

    it("can find search results" + caps.browserName, function(done) {
      driver.get("https://www.lambdatest.com").then(function() {
        driver.getTitle().then(function(title) {
          setTimeout(function() {
            console.log(title);
            assert(
              title.match(
                "Cross Browser Testing Tools | Test Your Website on Different Browsers | LambdaTest"
              ) != null
            );
            done();
          }, 10000);
        });
      });
    });

    afterEach(function(done) {
      if (this.currentTest.isPassed) {
        driver.executeScript("lambda-status=passed");
      } else {
        driver.executeScript("lambda-status=failed");
      }
      driver.quit().then(function() {
        done();
      });
    });
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let’s create a config file parallel.conf.js for defining the desired browser capabilities to execute the tests on LambdaTest. The capabilities are generated using the &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov07_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Lambdatest capabilities generator&lt;/a&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LT_USERNAME = process.env.LT_USERNAME || "&amp;lt;your username&amp;gt;";
LT_ACCESS_KEY = process.env.LT_ACCESS_KEY || "&amp;lt;your access key&amp;gt;";

var config = {
  commanCapabilities: {
    build: "Mocha-Reporter-Sample", //Build name
    tunnel: false // Make it true to run the localhost through tunnel
  },
  multiCapabilities: [
    {
      // Desired capabilities
      name: "Win10Firefox", // Test name
      platform: "Windows 10", // OS name
      browserName: "firefox",
      version: "latest",
      visual: true, // To take step by step screenshot
      network: true, // To capture network Logs
      console: true // To capture console logs.
    },
    {
      name: "Win10Chrome", // Test name
      platform: "Windows 10", // OS name
      browserName: "chrome",
      version: "75.0",
      visual: true, // To take step by step screenshot
      network: true, // To capture network Logs
      console: true // To capture console logs.
    },
    {
      name: "Win10Edge", // Test name
      platform: "Windows 10", // OS name
      browserName: "Edge",
      version: "latest",
      visual: true, // To take step by step screenshot
      network: true, // To capture network Logs
      console: true // To capture console logs.
    },
    {
      name: "Win7Chrome", // Test name
      platform: "Windows 7", // OS name
      browserName: "chrome",
      version: "75.0",
      visual: true, // To take step by step screenshot
      network: true, // To capture network Logs
      console: true // To capture console logs.
    },
    {
      name: "Win7ChromeLatest", // Test name
      platform: "Windows 7", // OS name
      browserName: "chrome",
      version: "latest",
      visual: true, // To take step by step screenshot
      network: true, // To capture network Logs
      console: true // To capture console logs.
    },
    {
      name: "MacOsBigSurChrome", // Test name
      platform: "macos bigsur", // OS name
      browserName: "chrome",
      version: "75.0",
      visual: true, // To take step by step screenshot
      network: true, // To capture network Logs
      console: true // To capture console logs.
    },
    {
      name: "MacOsBigSurFirefox", // Test name
      platform: "macos bigsur", // OS name
      browserName: "firefox",
      version: "latest",
      visual: true, // To take step by step screenshot
      network: true, // To capture network Logs
      console: true // To capture console logs.
    }
  ]
};

exports.capabilities = [];
// Code to support common capabilities
config.multiCapabilities.forEach(function(caps) {
  var temp_caps = JSON.parse(JSON.stringify(config.commanCapabilities));
  for (var i in caps) temp_caps[i] = caps[i];
  exports.capabilities.push(temp_caps);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Trigger the following command to run the tests in parallel:&lt;/p&gt;

&lt;p&gt;npm run parallel&lt;/p&gt;

&lt;p&gt;Here is the execution snapshot is taken from the LambdaTest platform:&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%2F2048%2F0%2A-uAFocPSrj575TGm.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%2F2048%2F0%2A-uAFocPSrj575TGm.png" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Downloading Most Detailed And Most Intuitive Report From LambdaTest
&lt;/h2&gt;

&lt;p&gt;Now to download the detailed test report, all you need to do is go to the automation dashboard and click on the three dots on the extreme right of the build. In the options that appear, click on the Download Report option. That’s it. The detailed report will be downloaded.&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%2F2048%2F0%2AsGfCn2roqOhocsHL.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%2F2048%2F0%2AsGfCn2roqOhocsHL.png" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you open the downloaded report, you can see detailed information on the build. We must represent the total number of tests run, tests passed, tests failed, and more.&lt;/p&gt;

&lt;p&gt;Below is the screenshot of the Mocha report downloaded from the LambdaTest platform.&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%2F2048%2F0%2Ahy3YjUmoi_uJTBKT.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%2F2048%2F0%2Ahy3YjUmoi_uJTBKT.png" width="800" height="450"&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%2F2048%2F0%2Aut8M0QkqrOx5-FFh.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%2F2048%2F0%2Aut8M0QkqrOx5-FFh.png" width="800" height="450"&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%2F2048%2F0%2A_8oZJP9-OfbgBG8W.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%2F2048%2F0%2A_8oZJP9-OfbgBG8W.png" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s not all…You can also use LambdaTest to get detailed network logs, console logs, and other relevant information obtained using &lt;a href="https://www.lambdatest.com/support/docs/api-doc/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov07_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Automation APIs from LambdaTest&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;With the increased focus on Selenium automation testing, it is important that we represent the reports of automation runs in a readable format. The automation test report should encompass all the details about the test runs. This makes it easy for all the stakeholders to grasp the underlying issues in the system.&lt;/p&gt;

&lt;p&gt;Though Mochawesome utility can be used to create HTML/CSS &amp;amp; JSON Mocha reports, the lack of test and report at scale makes it very difficult for enterprises to use these Mocha report generators. As a result, the cloud-based Selenium Grid like LambdaTest can be used to ensure cross-browser compatibility. It also helps in generating advanced visual reports.&lt;/p&gt;

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

</description>
      <category>mobile</category>
      <category>mocha</category>
      <category>testing</category>
    </item>
    <item>
      <title>Cypress Testing Framework Tutorial: Complete Guide to Test Automation with Cypress</title>
      <dc:creator>Sachinj34</dc:creator>
      <pubDate>Wed, 02 Nov 2022 12:41:22 +0000</pubDate>
      <link>https://forem.com/testmuai/cypress-testing-framework-tutorial-complete-guide-to-test-automation-with-cypress-2h18</link>
      <guid>https://forem.com/testmuai/cypress-testing-framework-tutorial-complete-guide-to-test-automation-with-cypress-2h18</guid>
      <description>&lt;p&gt;If you are from the automation testing field, you will know that Selenium is one of the leading test automation frameworks in the market. However, as per my experience in test automation, other modern automation frameworks like Cypress testing framework are picking up pace. As per a report by Slintel, Cypress testing framework has close to a 2.61 percent share in the cross browser testing market.&lt;/p&gt;

&lt;p&gt;I have used Selenium as well as Cypress testing framework for web automation projects, and so far, the experience with Cypress testing framework has been nothing short of fascinating. My earlier blog on &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;introduction to Cypress test automation&lt;/a&gt; can be a good starting point for someone willing to make an entry into web automation testing with &lt;a href="https://www.lambdatest.com/blog/getting-started-with-cypress/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress Testing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Do check out the detailed &lt;a href="https://www.lambdatest.com/learning-hub/cypress-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress tutorial&lt;/a&gt; on the LambdaTest YouTube channel in case you are looking to explore the immense number of features offered by Cypress Testing Framework:&lt;/p&gt;

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

&lt;p&gt;You can also Subscribe to the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/automated-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automated browser testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;p&gt;Cypress testing framework is definitely more reliable, faster, and less flaky in comparison to tests performed using other web automation frameworks. But, as it is rightly said, ‘Numbers don’t lie,’ and 3.5M+ weekly downloads for Cypress testing framework speaks a lot about the popularity of this open-source test automation 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%2F3998%2F0%2AZivW4JiPu22P5-Cs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3998%2F0%2AZivW4JiPu22P5-Cs.png" width="800" height="322"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this blog on getting started with &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress automation&lt;/a&gt;, I will deep dive into the integral aspects of Cypress — the popular open-source framework that has received huge acceptance from the developer &amp;amp; QA community.&lt;/p&gt;

&lt;p&gt;Starting your journey with Cypress Testing Framework? Check out how you can test your Cypress test scripts on LambdaTest’s &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress cloud&lt;/a&gt;.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  What is Cypress Testing Framework
&lt;/h2&gt;

&lt;p&gt;For starters, Cypress is an open-source automation testing framework based on JavaScript that supports Web and API application testing. Furthermore, Cypress testing framework executes tests on a real browser instance, avoiding the need to download without you needing to download browser drivers, which is normally the case with &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium test automation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In case you are planning to switch from Selenium to Cypress, do check out the &lt;a href="https://www.lambdatest.com/blog/cypress-vs-selenium-comparison/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium vs Cypress&lt;/a&gt; blog to make an informed decision. At the time of writing this blog on getting started with Cypress testing framework, the latest version of Cypress was 9.6.0.&lt;/p&gt;

&lt;p&gt;Unlike Selenium, which supports close to 6 popular programming languages, Cypress testing framework only supports the JavaScript language. Therefore, it is more suited for testing modern web applications that are built using popular frameworks like React, Angular, etc. Now, the important question is, does Cypress only support front-end testing? Well, definitely not!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress end-to-end testing&lt;/a&gt; is one of the major prime uses of the framework. It is also suited for writing unit tests and integration tests. In a nutshell, architectural differences and suitability for testing modern web applications are the major benefits of the Cypress framework. Like Selenium, &lt;a href="https://www.lambdatest.com/blog/how-to-perform-cypress-testing-at-scale-with-lambdatest/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress cloud testing&lt;/a&gt; lets you run Cypress tests at scale on a range of different browsers, browser versions, and operating systems online.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cypress Architecture
&lt;/h2&gt;

&lt;p&gt;As mentioned earlier, Cypress tests are run directly inside the browser. This essentially means that the Cypress testing framework has the flexibility to modify the browser behavior by listening to the altering the incoming network requests, that too on the fly!&lt;/p&gt;

&lt;p&gt;I have witnessed that Cypress tests show comparatively less flakiness in comparison to Selenium tests since the framework does not use any kind of WebDriver. Instead, spies and stubs in Cypress let you control the behavior of functions and times at the run time.&lt;/p&gt;

&lt;p&gt;Now that I have covered the essential aspects of the Cypress testing framework in this guide on getting started with Cypress, let me walk you through the Cypress architecture. Cypress executes on a NodeJS server that invokes the Browser (under test) for executing the application (one of the iFrames on the page) and the test code (that constitutes the other iFrame).&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%2AjheAy7JZUysGAqyP.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%2AjheAy7JZUysGAqyP.png" width="533" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These are on the same session, thereby allowing the Cypress code to mock and even change the JavaScript global objects. In addition, NodeJS’s running process acts as a proxy that helps intercept the requests over HTTP protocol, helping to mock it and change the response for testing.&lt;/p&gt;

&lt;p&gt;At the time of writing this blog on getting started with Cypress, Cypress has support for Chrome-family browsers (including Electron and Chromium-based Microsoft Edge), as well as Firefox.&lt;/p&gt;

&lt;h2&gt;
  
  
  Salient Features of Cypress
&lt;/h2&gt;

&lt;p&gt;Here are some of the unique features of Cypress when compared to other popular test automation frameworks that are used for &lt;a href="https://www.lambdatest.com/feature?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser compatibility testing&lt;/a&gt; –&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Cypress package comes with fully baked libraries, avoiding the need to install any major dependencies. Instead, all you need is to install Cypress!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test code and application share the browser session, thereby resulting in a faster response time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cypress offers automation waits and assertions, avoiding the need to add explicit or implicit waits. However, you can refer to &lt;a href="https://www.lambdatest.com/blog/explicit-fluent-wait-in-selenium-c/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Explicit Waits in Selenium&lt;/a&gt; blog to get more information about the types of waits in Selenium. Owing to this, Cypress tests are less flaky than their equivalent Selenium tests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Since the tests run inside the real browser, you can change the code and run only the changed test as soon as you save it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cypress test runner can be run seamlessly as a GUI application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Parallel test execution and detailed report generation are supported by default within the Cypress dashboard.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Debugging tests is super breezy in Cypress.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.lambdatest.com/full-page-screen-capture?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Full page screenshots&lt;/a&gt; are generated automatically for every event that is fired during the test execution. Over &amp;amp; above, video recording of the test execution is also possible in Cypress.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So does this mean that there are no downsides of Cypress? Definitely not. Since Cypress only supports JavaScript, you need to learn coding in JavaScript if you intend to use Cypress for web automation testing.&lt;/p&gt;

&lt;p&gt;We all know that &lt;a href="https://www.lambdatest.com/blog/web-scraping-using-selenium-and-python/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;web scraping in Selenium&lt;/a&gt; is easily doable. Furthermore, you have the flexibility to use popular Selenium-supported languages like C#, Python, Java, etc., to achieve the task. On the downside, Cypress is not a preferred option for web scraping (or web crawling) and performance testing.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  How to install Cypress?
&lt;/h2&gt;

&lt;p&gt;The Cypress dashboard and Cypress test runner are the two main components that will be installed with Cypress. Perform the below-mentioned steps to install Cypress on the local machine:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Since Cypress is built using &lt;a href="https://nodejs.org/en/download/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;NodeJS&lt;/a&gt;, you first need to install NodeJS v12+ before proceeding to install Cypress.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once NodeJS is installed, create a project folder under the appropriate directory and initialize the folder with the npm init command.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Cypress is a single module that bundles all the required properties that you need for running the tests. Add Cypress to node_modules Installing Cypress is just a command away since it’s a single module bundling all required properties.&lt;/p&gt;

&lt;p&gt;npm install cypress&lt;br&gt;
yard add cypress&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once Cypress packages are added to the project directory, you should be able to see the Cypress folder added to your project with pre-added tests for sample testing.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Installation of Cypress Test runner
&lt;/h2&gt;

&lt;p&gt;Run the command npx cypress open on the terminal to open Cypress GUI test runner and view all the preloaded tests. In case you are managing commands through the package.json file, you can add commands under scripts as shown below:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FileName — Package.json&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AeuwFLNCHnnmq2bfC.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%2AeuwFLNCHnnmq2bfC.png" width="520" height="706"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Upon execution, the test runner would show up as seen below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2756%2F0%2AqWOjm3BVZZBQL_QX.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%2F2756%2F0%2AqWOjm3BVZZBQL_QX.png" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You now have the option to run a single test or all the tests from the &lt;a href="https://github.com/cypress-io/cypress-example-kitchensink?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress kitchen sink&lt;/a&gt; example. Choose the root folder in case you intend to run all the Cypress tests.&lt;/p&gt;

&lt;p&gt;Run the Cypress CLI on the terminal since it provides the facility of extending the choice of running tests like selecting the browser for the test. The sample command to use the Chrome browser for testing is shown below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx cypress run -- --browser chrome
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Additionally, you can also choose a specific file to run using the –spec option:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx cypress run -- --browser chrome --spec '&amp;lt;path to test file&amp;gt;'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2224%2F1%2AJ9J-cUw8alj4KtM4mQhucA.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%2F2224%2F1%2AJ9J-cUw8alj4KtM4mQhucA.png" width="800" height="645"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, once we are accustomed to Cypress setup and basic sample (shown above), let us look into a simple test named checkboxes.spec.js. For demonstration, I am using the &lt;a href="https://lambdatest.com/selenium-playground?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Selenium Playground&lt;/a&gt; for verifying interactions with the WebElements on the page.&lt;/p&gt;

&lt;p&gt;Test code in Cypress is written by default in the Mocha style. Tests in Cypress start with a test suite that uses describe() or context() under which you can write multiple it() functions that correspond to a test scenario.&lt;/p&gt;

&lt;p&gt;Here is the list of the commands that are a part of the test case:&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%2F3220%2F0%2AzujvalN-TZNVF3OC.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%2F3220%2F0%2AzujvalN-TZNVF3OC.png" width="800" height="840"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Let us look into the integral aspects of the code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Enable Intellisense in the test code by including the statement ///&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The cy.visit() function is used for navigating to the target URL.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The cy.get() function is used to locate the required WebElements on the page. The &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=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;CSS Selector&lt;/a&gt; is used by Cypress for locating the elements in the DOM.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The type() function is used for entering the required text in the text box element that was located in the previous step. The type() function also accepts &lt;a href="https://www.lambdatest.com/blog/handling-keyboard-actions-in-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Keyboard actions&lt;/a&gt; that can be easily written with {keyCommand} like “{enter}” i.e. type(‘{enter}’)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the example, assert is raised if the ToDo element is not checked i.e., .should(‘be.checked’)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Shown below is the execution snapshot on the Chrome browser:&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%2F2758%2F0%2AbLCIqTV3GKDWXyLU.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%2F2758%2F0%2AbLCIqTV3GKDWXyLU.png" width="800" height="337"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The entire test execution is auto-recorded and stored in a .mp4 file so that the test execution details can be shared or viewed across teams.&lt;/p&gt;

&lt;p&gt;Now we have seen how to install Cypress. In the next section of this article on getting started with Cypress, we will know more about the Cypress Dashboard Service.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  The Cypress Dashboard Service
&lt;/h2&gt;

&lt;p&gt;Cypress test runner does an excellent job in running tests and storing the execution in the form of a recorded session. However, what if you want to store and run tests remotely without stressing a lot about browser updates, test history, test analytics, etc.?&lt;/p&gt;

&lt;p&gt;To cater to such requirements, Cypress offers amazing paid features that can be leveraged for CI integration and parallelization of test scenarios.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here are some of the salient features of Cypress Dashboard Service:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Cypress test runner is sufficient to run serial tests. However, you would need Cypress Dashboard Service to run tests in Parallel. I personally recommend a cloud Cypress testing platform like LambdaTest that lets you run tests in parallel on a number of browser and OS combinations&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dashboard service lets you group tests and runs them with multi-level environments and browsers&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It supports integration with the &lt;a href="https://www.lambdatest.com/blog/31-best-ci-cd-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;best CI/CD tools&lt;/a&gt; like Jenkins, Travis CI, and more&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It provides the facility to analyze previous test runs by deep diving into the analytics of the historical data of the runs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It auto balances load across parallel threads in order to reduce the load on CI servers.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;h2&gt;
  
  
  &lt;strong&gt;How to run Cypress Tests on Cypress Cloud Grid&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;**&lt;br&gt;
**Although Dashboard services provided by Cypress are useful, there are cases where test cases need to be run cross browser tests on a wide range of browsers, browser versions, and operating systems. But that’s not all. You would also need integration with a range of tools (and frameworks) like CI/CD tools, &lt;a href="https://www.lambdatest.com/blog/10-top-codeless-testing-tools-2021/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;codeless automation tools&lt;/a&gt;, reporting tools, and more.&lt;/p&gt;

&lt;p&gt;A cloud-based &lt;a href="https://www.lambdatest.com/cypress-ui-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress UI testing&lt;/a&gt; cloud-like LambdaTest solves the problems mentioned above. In addition, migrating tests to Cypress cloud grid helps improve overall browser coverage along with accelerating the speed of test case execution.&lt;/p&gt;

&lt;p&gt;In this section of this article on getting started with Cypress, let’s execute the earlier test in checkboxes.spec.js and see it in action on the LambdaTest Grid.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Configure LambdaTest config.&lt;/p&gt;

&lt;p&gt;Install lambdatest-cypress cli package using npm install lambdatest-cypress-cli under the project root directory&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%2F3336%2F1%2AOnupy0M4kqAbo3psxr-cYg.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%2F3336%2F1%2AOnupy0M4kqAbo3psxr-cYg.png" width="800" height="195"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once installed, lambdatest-config.json is created using the following command:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx lambdatest-cypress-cli 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%2Fcdn-images-1.medium.com%2Fmax%2F2424%2F1%2ACYfWKCQPA_wCB1b5BQ_Wxg.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%2F2424%2F1%2ACYfWKCQPA_wCB1b5BQ_Wxg.png" width="800" height="1319"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have specified Chrome and Firefox browsers (i.e., the browsers on which tests have to be performed) in the config file. Platform name and version are also specified in the config file.&lt;/p&gt;

&lt;p&gt;Shown below is the sample package.json 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%2F2660%2F1%2AAB6bAzpWt6q2yT3LDpn8VQ.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%2F2660%2F1%2AAB6bAzpWt6q2yT3LDpn8VQ.png" width="800" height="632"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run the tests using the lambdatest-cypress run to see the tests in action on LambdaTest Cypress Grid.&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%2F2758%2F1%2AU_--lN3B19Q7EiKnUNJZBQ.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%2F2758%2F1%2AU_--lN3B19Q7EiKnUNJZBQ.png" width="800" height="417"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Take this certification to showcase your expertise with end-to-end testing using the Cypress testing framework and stay one step ahead.&lt;/p&gt;

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

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

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

&lt;p&gt;Cypress is one of the widely used automation testing frameworks for automated testing of modern web applications. The features provided by the Cypress framework can be further enhanced by running tests at scale on a cloud-based Cypress Grid.&lt;/p&gt;

&lt;p&gt;This is where &lt;a href="https://www.npmjs.com/package/lambdatest-cypress-cli?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Cypress CLI&lt;/a&gt; comes into the picture. It lets you run tests at an expedited pace on a range of popular browsers and platforms. I hope that this guide on getting started with Cypress will help you kick-start your &lt;a href="https://www.lambdatest.com/cypress-ui-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov02_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress UI automation&lt;/a&gt; journey. Do leave your feedback in the comments section.&lt;/p&gt;

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

</description>
      <category>testing</category>
      <category>automation</category>
      <category>cypress</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
