<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Narayanan Palani</title>
    <description>The latest articles on DEV Community by Narayanan Palani (@narayananpalani09).</description>
    <link>https://dev.to/narayananpalani09</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%2F980472%2F401a1574-0d21-426e-b803-ac97e6f1fbb6.png</url>
      <title>DEV Community: Narayanan Palani</title>
      <link>https://dev.to/narayananpalani09</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/narayananpalani09"/>
    <language>en</language>
    <item>
      <title>Handling Touch And Mouse Events In Cypress [Tutorial]</title>
      <dc:creator>Narayanan Palani</dc:creator>
      <pubDate>Mon, 28 Nov 2022 11:52:45 +0000</pubDate>
      <link>https://dev.to/testmuai/handling-touch-and-mouse-events-in-cypress-tutorial-28ed</link>
      <guid>https://dev.to/testmuai/handling-touch-and-mouse-events-in-cypress-tutorial-28ed</guid>
      <description>&lt;p&gt;Cypress is one of the selected-few JavaScript test automation tools that has climbed the ranks when it comes to modern web testing. Though I have extensively used Selenium, I am fascinated with the speed at which the Cypress team comes with innovative features to help developers and testers around the world. What I particularly liked about Cypress test automation is its extensive support for accessibility automation over HTML Semantic Element properties such as aria-label, etc.&lt;/p&gt;

&lt;p&gt;Most of the QA engineers that are inclined towards accessibility testing assume that Cypress events like mouse clicks should not be used for automation testing. As per my extensive experience in the testing field, I would like to mention that it’s incorrect to assume that the keyboard is the only point of communication. Awareness of the general public is also not accurate, as many have the notion that laptop touchpad is accessible to differently-abled users.&lt;/p&gt;

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

&lt;p&gt;Manually testing all the mouse operations with mouse alternatives (e.g., trackpad, joystick, etc.) can be cumbersome for the dev and QA teams. Fortunately, Cypress lets you automate accessibility tests with Cypress-Axe. However, the handling of Cypress events is completely different from how events are handled in the Selenium framework. In case you are curious to know the difference between Selenium and Cypress, make sure to check out our blog on &lt;a href="https://www.lambdatest.com/blog/cypress-vs-selenium-comparison/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress vs. Selenium&lt;/a&gt; comparison.&lt;/p&gt;

&lt;p&gt;In the meantime, if you’d like to run your Cypress test scripts over a Selenium Grid online then leverage LambdaTest for your test automation.👇&lt;/p&gt;

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

&lt;p&gt;Selenium uses the Action APIs (i.e., action.moveToelement) function to simulate the mouse behavior but comes with a huge flakiness. On the other hand, Cypress events involving peripherals like mouse, keyboards, etc., have been exceptionally handled in the framework. In this blog of &lt;a href="https://www.lambdatest.com/learning-hub/cypress-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;cypress tutorial&lt;/a&gt;, I would deep dive into mouse event a&lt;a href="https://www.lambdatest.com/cross-browser-testing-with-cypress?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;utomation with the Cypress&lt;/a&gt; framework. It would help you in the efficient handling of Cypress events when running Cypress test automation scripts.&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=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" 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;
  
  
  Cypress UI Interaction Commands
&lt;/h2&gt;

&lt;p&gt;The Cypress framework provides a number of commands that let you interact or trigger some events in the DOM. These Cypress events are fired similarly as the web browser would fire. We would cover Cypress touch and mouse events and examples of how you can use them in your Cypress test scripts.&lt;/p&gt;

&lt;p&gt;You can go through the following video to learn Cypress commands that can help you write tests that interact with the user interface of an application. However, you can also visit the LambdaTest YouTube channel for videos that will guide you through the Cypress testing journey.&lt;/p&gt;

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

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

&lt;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=nov28_sd&amp;amp;utm_term=sd&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;h2&gt;
  
  
  Cypress Trigger Command
&lt;/h2&gt;

&lt;p&gt;The trigger command in Cypress helps trigger an event on the DOM element. X, Y positions can also be supplied to the trigger command. Shown below is the syntax of the trigger command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.trigger(eventName)
    .trigger(eventName, position)
    .trigger(eventName, options)
    .trigger(eventName, x, y)
    .trigger(eventName, position, options)
    .trigger(eventName, x, y, options)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can have log, force, bubbles, timeout, and cancelable as the options in the trigger command. Here are some of the ways in which Cypress trigger command can be used to perform events on the WebElement:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cy.get('a').trigger('mousedown')
    cy.get('sample_button').trigger('mousedown', 'topLeft')
    cy.get('sample_button').trigger('mouseover', { bubbles: false })
    cy.get('sample_button').trigger('mouseup', 20, 30)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let’s look at some of the in-depth examples that demonstrate the usage of Cypress mouse events so that you can perform the relevant mouse operations using the Cypress framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mouse Down Events using Cypress
&lt;/h2&gt;

&lt;p&gt;Mouse interactions such as mouse down and mouse up are some of the most common operations you would normally perform with a mouse. For demonstration, we perform a mouse down event on the Admin tab available on the OrangeHRM website.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;When('I move mouse down on admin tab section', () =&amp;gt; {
      homeOrangehrmPage.mousedownAdminTab()
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Function&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mousedownAdminTab () {
        cy.xpath('//a[@id="menu_admin_UserManagement"]')
          .invoke('show')
          .should('be.visible')
          .trigger('mousedown')
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As seen above, the admin menu is located using the XPath locator. Once the element is located, the invoke method is used to call the JQuery method ‘show’ on the element. The corresponding WebElement should be visible.&lt;/p&gt;

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

&lt;p&gt;On detecting the desired element’s visibility, a mouse down event is triggered on the element.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mouse Over Events using Cypress
&lt;/h2&gt;

&lt;p&gt;Using the trigger command, you can also perform Cypress mouse over Event. The only prerequisite is that the DOM element must be in an ‘interactable’ state before this Cypress event is triggered. Interactable means that the button must be visible and should not be disabled.&lt;/p&gt;

&lt;p&gt;To showcase the usage of Cypress mouse over event, we use the same HRM website example:&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;When('I mouseover on first row of results table of admin tab', () =&amp;gt; {
        homeOrangehrmPage.mouseOverAdminResultTableR1C2()
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Function&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mouseOverAdminResultTableR1C2 () {
        cy.xpath('//a[@id="menu_admin_UserManagement"]')
          .invoke('show')
          .should('be.visible')
          .trigger('mouseover')
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;As seen above, the desired element is located using the XPath locator. Once the element is located and checked for its visibility, the mouse over event is invoked to interact with the corresponding element.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mouse Leave Events using Cypress
&lt;/h2&gt;

&lt;p&gt;Once the mouse over event is performed, mouseleave event helps in going back to the earlier stage of the UI display.&lt;/p&gt;

&lt;p&gt;We demonstrate the mouseleave option using the OrangeHRM website.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;When('I mouseleave on first row of results table of admin tab', () =&amp;gt; {
        homeOrangehrmPage.mouseleaveAdminResultTableR1C2()
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Function&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mouseleaveAdminResultTableR1C2 () {
        cy.xpath('//a[@id="menu_admin_UserManagement"]')
          .invoke('show')
          .should('be.visible')
          .trigger('mouseleave')
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Mouse Move Events using Cypress
&lt;/h2&gt;

&lt;p&gt;If you are new to this particular mouse event, I would recommend trying out the mouse move event. Try the sample code here: &lt;a href="https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onmousemove" rel="noopener noreferrer"&gt;https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onmousemove&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Function to perform mouse left and mouse right events:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mousActionsonDashboardGraph () {
        cy.xpath('//*[@id=\"div_graph_display_emp_distribution\"]')
          .as('graph')
          .trigger('mousedown')
          .trigger('mousemove')
          .trigger('mouseup')
          .trigger('mouseleft', { which: 1, pageX: 600, pageY: 100 })
          .trigger('mouseright', { which: 1, pageX: 600, pageY: 600 })
          .trigger('mouseleave')
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;Once we are inside the Employee Distribution chart, we use the mouseleft and mouseright options offered with the trigger command to move the mouse to the desired X and Y coordinates.&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;&lt;em&gt;Check this out: &lt;a href="https://www.lambdatest.com/learning-hub/smoke-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Smoke Testing&lt;/a&gt; Tutorial- A Comprehensive Guide With Examples And Best Practices&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Cypress Click Command
&lt;/h2&gt;

&lt;p&gt;In case you want to perform a Cypress mouse event like click, you can use the .click() method offered by the Cypress framework. It lets you click on any DOM element. Like the .trigger() method, the .click() method can also be invoked in different ways.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.click()
    .click(options)
    .click(click_pos)
    .click(click_pos, options)
    .click(x, y)
    .click(x, y, options)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Click position (i.e. click_pos) could be center, topLeft, topRight, left, right, bottom, bottomLeft, bottomRight, etc. The possible values of options are log, force, multiple, and timeout.&lt;/p&gt;

&lt;p&gt;Here is a sample demonstration of the click method in Cypress using the Orange HRM website:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const admin_tabxPath_Homepage = '//*[@id=\'menu_admin_viewAdminModule\']'
    clickAdminTab () {
        cy.xpath(admin_tabxPath_Homepage)
          .invoke('show')
          .should('be.visible')
          .click()
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Once the required WebElement is visible, then the click() method is used for clicking on that element.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Cypress Double Click Command
&lt;/h2&gt;

&lt;p&gt;The .dblclick() method in Cypress is used for double clicking on a DOM element. Like the .click() method, the .dblclick() method can also be used in a number of ways:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.dblclick()
    .dblclick(options)
    .dblclick(dblclick_pos)
    .dblclick(dblclick_pos, options)
    .dblclick(x, y)
    .dblclick(x, y, options)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The method accepts the same options as mentioned in the .click() method.&lt;/p&gt;

&lt;p&gt;Shown below is the demonstration of .dblclick() method that double clicks on the Admin module of the OrangeHRM website:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const admin_tabxPath_Homepage = '//*[@id=\'menu_admin_viewAdminModule\']'
    dblclickAdminTab () {
        cy.xpath(admin_tabxPath_Homepage)
          .invoke('show')
          .should('be.visible')
          .dblclick()
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Cypress Right Click Command
&lt;/h2&gt;

&lt;p&gt;The .rightclick() method in Cypress is used for right clicking on a DOM element. It will not open context menus that are native to the web browser. The method can also be invoked in a number of ways:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.rightclick()
    .rightclick(options)
    .rightclick(click_pos)
    .rightclick(click_pos, options)
    .rightclick(x, y)
    .rightclick(x, y, options)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Shown below is the demonstration of .rightclick() method that opens up the context menu when right clicked on the Admin module of the OrangeHRM website:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const admin_tabxPath_Homepage = '//*[@id=\'menu_admin_viewAdminModule\']'
    rhtclickAdminTab () {
        cy.xpath(admin_tabxPath_Homepage).rightclick()
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Cypress Check/Uncheck Commands
&lt;/h2&gt;

&lt;p&gt;The .check() and .uncheck() method in Cypress is used for checking and unchecking the checkboxes and radio buttons respectively. This method can also be invoked in a number of ways:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.check()
    .check(value)
    .check(values)
    .check(check_ops)
    .check(value, check_ops)
    .check(values, check_ops)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Shown below is the syntax of the .uncheck() method:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.uncheck()
    .uncheck(value)
    .uncheck(values)
    .uncheck(uncheck_ops)
    .uncheck(value, uncheck_ops)
    .uncheck(values, uncheck_ops)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The possible value of options (i.e. check_ops/uncheck_ops) are log, force, and timeout.&lt;br&gt;
Shown below is the demonstration of check and uncheck methods of the Cypress framework:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const selectAll_pimTab = '//*[@id=\'ohrmList_chkSelectAll\']'
    /* Check the radio button if the tab is enabled */
    checkEmployees () {
        cy.xpath(selectAll_pimTab).not('[disabled]').check()
    }
    /* Check if the appropriate radio options are checked or not */
    allEmployeesSelected () {
        cy.xpath(selectAll_pimTab).not('[disabled]').should('be.checked')
    }
    /* Uncheck if the options are checked */
    uncheckEmployees () {
       cy.xpath(selectAll_pimTab).not('[disabled]').should('be.checked').uncheck()
    }
&lt;/code&gt;&lt;/pre&gt;

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

&lt;p&gt;Apart from these methods that let you perform Cypress operations, Cypress also supports Type, Clear, and Select commands.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to run mobile browser tests using Cypress
&lt;/h2&gt;

&lt;p&gt;All you need to do is to launch the browser and reload the page with the respective viewport of the particular mobile or tablet version I wanted to test against. Entire viewport combinations ranging from different iPhone versions, MacBook versions, iPad versions, and popular android versions are listed in Cypress documentation.&lt;/p&gt;

&lt;p&gt;After reloading the page with a particular viewport, you just need to perform the trigger event to perform mobile interactions such as touchstart.&lt;/p&gt;

&lt;p&gt;Feature File:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    Feature: MouseEvents verification in various compatibility models of devices

    Scenario: Mouseactions on Dashboard Tab Graph using iPhone6 Mobile
          Given I open OrangeHRM homepage
          When I SignIn as user
          When I see the page in iphone6 version
          When I perform move actions on dashboard graph
          Then text insights displayed below dashboard successfully

    Scenario: Mouseactions on Dashboard Tab Graph using iPhonexr Mobile
          Given I open OrangeHRM homepage
          When I SignIn as user
          When I see the page in iphonexr version
          When I perform move actions on dashboard graph
          Then text insights displayed below dashboard successfully

    Scenario: Mouseactions on Dashboard Tab Graph using macbook-15 device
          Given I open OrangeHRM homepage
          When I SignIn as user
          When I see the page in macbook-15 version
          When I perform move actions on dashboard graph
          Then text insights displayed below dashboard successfully 

    Scenario: Mouseactions on Dashboard Tab Graph using iPad2 device
          Given I open OrangeHRM homepage
          When I SignIn as user
          When I see the page in iPad2 version
          When I perform move actions on dashboard graph
          Then text insights displayed below dashboard successfully
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Step Definition to launch or reload the page with IPhone 6 viewport:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;When('I see the page in iphone6 version', () =&amp;gt; {
      homeOrangehrmPage.viewPortIphone6()
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Function:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   viewPortIphone6 () {
        cy.viewport('iphone-6')
      },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Step Definition to launch or reload the page with IPhoneXR viewport:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;When('I see the page in macbook-15 version', () =&amp;gt; {
      homeOrangehrmPage.viewPortmac15()
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Function:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; viewPortmac15 () {
        cy.viewport('macbook-15')
      },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Step Definition to launch or reload the page with Macbook-15 viewport:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;When('I see the page in iPad2 version', () =&amp;gt; {
      homeOrangehrmPage.viewPortipad2()
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Function:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; viewPortmac15 () {
        cy.viewport('macbook-15')
      },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Step Definition to launch or reload the page with iPad2 viewport:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;When('I see the page in iPad2 version', () =&amp;gt; {
      homeOrangehrmPage.viewPortipad2()
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Function:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    viewPortipad2 () {
        cy.viewport('ipad-2')
      },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fijegtok3kjl583emezxp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fijegtok3kjl583emezxp.png" width="800" height="154"&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=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress automation&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;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: &lt;a href="https://www.lambdatest.com/learning-hub/usability-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Usability Testing&lt;/a&gt;- A Comprehensive Guide With Examples And Best Practice&lt;/em&gt;&lt;/strong&gt;&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=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" 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;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;If you are trying to master the test automation profession, you need to be a test automation architect with capabilities that include automating mouse events most smartly.&lt;/p&gt;

&lt;p&gt;Automating mouse events and Cypress touch interactions not only reduces the workload but also facilitates helping to find more defects when small code changes are being made in the complex development code repository. Since it is difficult to perform mouse interactions every time through manual tests, automated mouse tests and getting them run through cypress-jenkins integrated tests are smarter ways to spot defects!&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>testing</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Web Performance Testing With Cypress and Google Lighthouse</title>
      <dc:creator>Narayanan Palani</dc:creator>
      <pubDate>Mon, 28 Nov 2022 08:55:25 +0000</pubDate>
      <link>https://dev.to/testmuai/web-performance-testing-with-cypress-and-google-lighthouse-2dd3</link>
      <guid>https://dev.to/testmuai/web-performance-testing-with-cypress-and-google-lighthouse-2dd3</guid>
      <description>&lt;blockquote&gt;
&lt;h1&gt;
  
  
  “Your most unhappy customers are your greatest source of learning.”
&lt;/h1&gt;
&lt;h1&gt;
  
  
  Bill Gates
&lt;/h1&gt;
&lt;/blockquote&gt;

&lt;p&gt;Since the time the pandemic struck the world, mobile applications and websites have become the go-to source for fulfilling all the major requirements (e.g., grocery shopping, bill payments, etc.). It would be catastrophic if the website or app takes ages to load:( In such cases, tables might turn against you, and your customers might jump ship to embrace your competitors’ services!&lt;/p&gt;

&lt;p&gt;As performance and user experience go hand-in-hand, it is imperative to consider web performance testing on high priority. Google Lighthouse is one of the widely used tools for realizing client-side performance testing. Like me, if you are also an ardent user of 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=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress automation&lt;/a&gt; testing, you might know that you can run Lighthouse audits from your Cypress tests.&lt;/p&gt;

&lt;p&gt;In this blog &lt;a href="https://www.lambdatest.com/learning-hub/cypress-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Cypress Tutorial&lt;/a&gt;, I deep dive into how you can leverage the potential of Cypress and Google Lighthouse for web performance testing.&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=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" 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;p&gt;Before we get started with Cypress performance testing using Lighthouse, let’s look at the ‘what’ and ‘why’ of performance tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are performance metrics KPIs for websites
&lt;/h2&gt;

&lt;p&gt;The standard load time of any NodeJS-based web application is 2 seconds which also includes loading of interactive content present on the website. Needless to mention that you need to fix it in case the load time exceeds more than 2 seconds! The story is not over yet!&lt;/p&gt;

&lt;p&gt;Even when the page loads the content, the entire page should get loaded in not more than 3 seconds.&lt;br&gt;
The Lighthouse plugin from Google Chrome is one of the powerful tools to get a performance score similar to the performance tab of Chrome Dev Tools. In addition, Lighthouse CLI can also be used for performing audits right from the command line! Though there are six performance metrics in Lighthouse 6.0, FCP (First Contentful Paint) and Time to Interactive (TTI) are the major ones that should be considered as a top priority.&lt;/p&gt;

&lt;p&gt;Here are the ideal values for the important Lighthouse performance metrics that should be considered for websites (or web applications):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
    &lt;tr&gt;
        &lt;td&gt;Metrics Type&lt;/td&gt;
        &lt;td&gt;Best Score/Minimum Standards&lt;/td&gt;
        &lt;td&gt;Location of the tool&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Performance Metrics Score&lt;/td&gt;
        &lt;td&gt;     95 percent&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;First Contentful Paint&lt;/td&gt;
        &lt;td&gt;Maximum 1-2 seconds&lt;/td&gt;
        &lt;td&gt;Lighthouse plugin (from Google Chrome → More Tools → Developer Tools)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Time to Interactive&lt;/td&gt;
        &lt;td&gt;Maximum 2-3 seconds&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;With numerous programming languages coming up for test automation, choosing one can be a tough call. This is why we are highlighting the top 7 &lt;a href="https://www.lambdatest.com/blog/top-7-programming-languages-for-test-automation-in-2020/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jun_19&amp;amp;utm_term=bh&amp;amp;utm_content=bog" rel="noopener noreferrer"&gt;automation testing languages&lt;/a&gt; to look out for test automation in 2020.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For more accurate results, it is recommended to disable cache from the network tab (inside Developer Tools of Google Chrome). Post that, you should retry to get the metrics from Google Lighthouse. Lighthouse v6 is available from Google Chrome v84 onwards. Since Lighthouse is available as a plugin for Cypress, it is recommended to use Cypress and Google Lighthouse combination for web performance testing.&lt;/p&gt;

&lt;p&gt;Scripting is a key metric calculated to determine how fast the web pages are getting loaded for the end-user. On similar lines, rendering and painting give the CSS load time depending on the type and category of React apps.&lt;/p&gt;

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

&lt;p&gt;For starters, Cypress is a JavaScript-based front-end testing tool that is primarily suited for testing modern web applications. Unlike other test automation frameworks like Selenium, Cypress operates directly inside the web browser and comes with a unique DOM manipulation technique. Check out our &lt;a href="https://www.lambdatest.com/blog/cypress-vs-selenium-comparison/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress vs Selenium&lt;/a&gt; comparison if you want to check out the best of both the test automation frameworks.&lt;/p&gt;

&lt;p&gt;Getting started with Cypress is easy in case you are coming from a JavaScript background. Cypress is one of the few test automation frameworks ideal for E2E (End-to-End) testing, integration testing, unit testing, and more.&lt;/p&gt;

&lt;p&gt;Check out the video from the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=youtube" rel="noopener noreferrer"&gt;LambdaTest YouTube channel &lt;/a&gt;that deep dives into how to get started with Cypress automation testing:&lt;/p&gt;

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

&lt;p&gt;QA engineers prefer Cypress automation testing since there are minimal chances of witnessing flakiness in Cypress tests. Recently, Cypress has come up with a retry mechanism in which you can set the retry value as 2 in cypress.json to get the same test retried twice if it had earlier failed due to issues like delayed load time.&lt;/p&gt;

&lt;p&gt;Getting performance metrics for each page based on its load time can be extremely time-consuming if the project has close to 40 to 200 web pages. The number of pages depends on the user journey. Now that we have covered the essentials of &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;What is Cypress&lt;/a&gt;, let’s look at how to implement web performance testing to automate those web pages using Cypress and Google Lighthouse in Jenkins.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Learn why Python is the top choice for automation testing. This comprehensive tutorial provides a step-by-step guide to &lt;a href="https://www.lambdatest.com/blog/python-automation-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jun_19&amp;amp;utm_term=bh&amp;amp;utm_content=bog" rel="noopener noreferrer"&gt;automation testing in python&lt;/a&gt; to help you streamline your testing process.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The cypress-audit plugin is used for Cypress performance testing since it integrates Lighthouse into the Cypress tests.&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=nov28_sd&amp;amp;utm_term=sd&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;Check this out: &lt;a href="https://www.lambdatest.com/appium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Appium Automation&lt;/a&gt; Tutorial - A Detailed Guide To Appium Testing&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use cypress-audit plugin for Cypress performance testing
&lt;/h2&gt;

&lt;p&gt;Before installing the cypress-audit plugin, you need to make sure that you have Cypress installed on your machine. If not, please follow the below-mentioned steps for setting up the Cypress framework:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;npm install&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;npm link&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;npm link cypress-cucumber-preprocessor&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;npm install through&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now that Cypress is installed on your machine, it’s time to install the cypress-audit plugin for taking the first step towards web performance testing.&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;Yarn users can install cypress-audit by triggering the following command on the terminal:&lt;/p&gt;

&lt;p&gt;yarn add -D cypress-audit&lt;/p&gt;

&lt;p&gt;Add the following constant in index.js that is present inside the plugins folder:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { lighthouse, pa11y, prepareAudit } = require(“cypress-audit”);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;After updating index.js, the next step is to write the feature file for verifying the web audit results, including the performance metrics pertaining to your area of interest. Our test scenario involves logging on to the OrangeHRM website and checking the web audit results once successfully logged in.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Learn about the &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=jun_19&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing javascript&lt;/a&gt; frameworks and choose the best suited frameworks depending on your project requirements.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Feature: Login Page Verification on OrangeHRM website

    Scenario: check web page health through lighthouse audit and pa11y audit on valid login page display with login fields
          Given I open OrangeHRM homepage
          Then I should see title "OrangeHRM"
          Then I should see "LOGIN Panel" text displayed
          And I should see "Alternative Login" text displayed
          And I should see web audit results
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now that we have the feature file ready, we write the step definition in a shared js file for common usage across the framework as below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Then('I should see web audit results', function () {
      cy.lighthouse();
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now that the test is partially ready, we can measure the website’s performance against the standards we are interested in. For example, when using Cypress and Google Lighthouse, it is required to set the test threshold based on which the tests would be declared pass/fail.&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;&lt;em&gt;Check this out: Most Comprehensive &lt;a href="https://www.lambdatest.com/blog/selenium-ide-what-is-it-why-is-it-must-for-every-qa/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium IDE&lt;/a&gt; Tutorial&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Thresholds For Cypress Performance Testing
&lt;/h2&gt;

&lt;p&gt;Thresholds for performance testing using Cypress and Google Lighthouse can be set in two different ways. The first option is by adding the threshold within the step definition file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding Threshold in step definition file&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Then('I should see web audit results', function () {
      cy.lighthouse({
        performance: 95,
        accessibility: 100,
        "best-practices": 95,
        seo: 85,
        pwa: 100,
      }
    );
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;Now that the thresholds are set, it’s time to run the tests. Since the tests are using Cypress installed on the local machine, trigger the following command on the terminal to run the Cypress test:&lt;/p&gt;

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

&lt;p&gt;Choose the right browser and launch the test on the corresponding 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4tg00qlefqph43gywcsz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4tg00qlefqph43gywcsz.png" width="800" height="443"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the snapshot that indicates the progress of the test execution:&lt;/p&gt;

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

&lt;p&gt;On a different note, I was running the same site in a different open-source tool to check the speed of the webpage, and the automation tool itself timed out, waiting for the page to load most of the time. As a laugh or cry moment, I dropped the plan of continuing the script in that tool 🙂&lt;/p&gt;

&lt;blockquote&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=jun_19&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;emulator 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;/blockquote&gt;

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

&lt;p&gt;A major benefit of Cypress automation testing is that it provides an interactive playback on each step and provides options to pause &amp;amp; re-run the test at any moment in time.&lt;/p&gt;

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

&lt;p&gt;When Cypress runs the tests for cy.lighthouse command, it loads the same page in a new tab of the browser for collecting the required metrics.&lt;/p&gt;

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

&lt;p&gt;Note that I have not used any thresholds inside my cy.lighthouse command; hence the tests show a log indicating that it is appropriate to add thresholds and rerun the tests:&lt;/p&gt;

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

&lt;p&gt;In few milliseconds, my tests failed due to the same reason of not having a threshold to my test:&lt;/p&gt;

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

&lt;p&gt;This is where we can switch to the other option for adding the required thresholds.&lt;/p&gt;

&lt;blockquote&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=jun_19&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;safari for windows&lt;/a&gt; testing? Forget about emulators or simulators — use real online browsers.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Adding Threshold in a constant&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this option, we add the thresholds in a constant and call the same inside the requisite step definitions.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const lighthousemetrics = {
        performance: 95,
        accessibility: 100,
        "best-practices": 95,
        seo: 85,
        pwa: 100,
      };

    Then('I should see web audit results', function () {
      cy.lighthouse(lighthousemetrics);
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The cypress-audit plugin will run the tests based on the score of 100 for every metric, and the options highlighted in this section helps in adjusting the metrics as per the specific requirements. We have run the tests on Cypress that is installed on my local machine, but the approach might pose scalability challenges.&lt;/p&gt;

&lt;p&gt;&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=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress testing on cloud&lt;/a&gt; like LambdaTest lets you perform Cypress automation testing on a range of browser and OS combinations at an expedited pace. It is the best way to leverage the benefits offered by cloud testing.&lt;/p&gt;

&lt;p&gt;Now Run your &lt;a href="https://www.lambdatest.com/cypress-parallel-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;free Cypress parallel testing&lt;/a&gt; online.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Test Execution using Lighthouse Threshold
&lt;/h2&gt;

&lt;p&gt;When rerunning the tests through the ‘npx cypress open’ command, it shows the metrics after loading the page in a new tab that immediately closes after the metrics are shown. However, it shows the path of the code and the specific location in the code that has failed due to poor performance.&lt;/p&gt;

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

&lt;p&gt;I was more interested in checking how Cypress evaluates the metrics on any web page in a more dynamic manner. This will also give a clear indication of the components involved in generating the required metrics.&lt;/p&gt;

&lt;p&gt;This is possible through the ‘view trace’ option that displays the metrics of the stack trace:&lt;/p&gt;

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

&lt;p&gt;When running performance metrics tests using cypress-audit based Lighthouse, it is possible to get timeouts during the test run. Hence, it is recommended to adjust the retry configuration in cypress.json while running performance tests using Cypress and Google Lighthouse.&lt;/p&gt;

&lt;p&gt;On encountering a timeout, test execution is retried if the test has failed the first time. Alternatively, it is advisable to install the latest Cypress version, such as v7 to run the tests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Funso6dvn8r7e96zotzwq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Funso6dvn8r7e96zotzwq.png" width="800" height="154"&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;&lt;strong&gt;&lt;em&gt;Check this out: Automated &lt;a href="https://www.lambdatest.com/blog/automated-functional-testing-what-it-is-how-it-helps/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Functional Testing&lt;/a&gt;: What it is &amp;amp; How it Helps?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Cypress-Lighthouse — Alternate Plugin for Cypress Performance Testing
&lt;/h2&gt;

&lt;p&gt;Cypress comes with a best-in-class plugin called cypress-lighthouse that adds the cy.lighthouse command for auditing the website against lighthouse performance metrics.&lt;/p&gt;

&lt;p&gt;Cypress Lighthouse plugin can be installed by triggering the following command on the terminal:&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;Add the following lines in command.js to use the Lighthouse plugin for performance testing with Cypress.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import ‘cypress-lighthouse’;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Use the commands such as .lighthouse to verify your results.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cy.lighthouse(‘https://www.orangehrm.com/’).as('results')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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=nov28_sd&amp;amp;utm_term=sd&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;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Improving the website performance is extremely important for meeting the &lt;a href="https://www.lambdatest.com/blog/core-web-vitals-expert-tips-to-improve-website-performance/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov28_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;core web vitals&lt;/a&gt;. Cypress and Google Lighthouse are an ideal combination for running performance tests on modern websites (or web applications). Lighthouse plugins on Cypress make it easy to perform Cypress performance testing by adding a couple of changes to the existing codebase.&lt;/p&gt;

&lt;p&gt;A well-optimized website eventually helps build an everlasting user experience and positively impacts search engine rankings. So, if you are a user of the Cypress framework, it’s time you leverage the benefits of Cypress and Google Lighthouse for building a top-performing website (or web application).&lt;/p&gt;

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

</description>
      <category>watercooler</category>
    </item>
  </channel>
</rss>
