The error you are seeing is a result of your application code and not generated by Cypress

I attempted to test the following simple code snippet:

type Website = string;
it('loads examples', () => {
    const website: Website = 'https://www.ebay.com/';
    cy.visit(website);
    cy.get('input[type="text"]').type('book');
    cy.get('#gh-btn').click();
})

After running this code, I encountered the following error:

How can I go about solving this issue?

Answer №1

To prevent the uncaught:exception error in the click() method, try including the following code snippet inside your support/index.js file:

import './commands'
Cypress.on('uncaught:exception', (err, runnable) => {
  // By returning false here, you can stop Cypress from failing the test
  return false
})

Adding this code should help you avoid encountering the uncaught:exception issue.

Answer №2

To prevent Cypress from being disturbed by any uncaught exceptions within the application, it is advised to acknowledge the accepted answer. Detecting these exceptions usually indicates a bug within your app that requires fixing.

While linking to the global Cypress object, ensure that the event remains connected throughout the entire test run. However, this may not always be the most ideal scenario for your testing needs.

In cases where you specifically want to dismiss the exceptions, make sure to link the event with the cy object so that it only stays relevant for the individual test where it is utilized.

it('my test', () => {
  cy.once('uncaught:exception', () => false);
  
  // action that triggers exception
  cy.get('body').click();
});

Answer №3

I encountered a similar issue recently Cypress Error

This error is arising from your application code, not Cypress itself. Cannot read properties of null (reading 'textContent')
When Cypress detects uncaught errors coming from your application, it will cause the current test to fail.
You can configure this behavior by toggling off the option and listening to the uncaught:exception event. Find out more about this.

No need to panic.

Simply add this code snippet to your index.js file :)

import './commands'
   Cypress.on('uncaught:exception', (err, runnable) => {
   // returning false here prevents Cypress from
 // failing the test
   return false
   })

Answer №4

By simply clicking on the Learn more link included in the error message, you will find all the necessary information.

https://docs.cypress.io/guides/references/error-messages#Uncaught-exceptions-from-your-application


According to other users:

Will this solution lead to disregarding all errors generated by the application? The accepted response implies that Cypress will overlook any uncaught exceptions.

This assertion holds true.

In my case, @DJSDev's method did not yield results while using Cypress v10.0.3.

The provided link offers a functional alternative:

it('is carrying out a crucial task', (done) => {
  // this event will automatically be removed when this
  // test concludes as it is linked to 'cy'
  cy.on('uncaught:exception', (err, runnable) => {
    expect(err.message).to.include('details about the error')

    // employing mocha's async done callback to complete
    // this test and demonstrate that an uncaught exception
    // occurred
    done()

    // returning false to avoid the error from
    // causing this test to fail
    return false
  })

  // assuming this triggers an error
  cy.get('button').click()
})

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Implementing Dual Submit Buttons in Node.js using Express Framework

Struggling with implementing a like and dislike function in my node js app. Currently, I can only do one at a time. Below is the HTML code snippet: <form method="post" name="ratings"> <input type="submit" name="vote" value="like"> < ...

Webpack in Vuejs does not have access to the keys defined in dev.env.js file

The framework utilized here is vuejs-webpack, with build and config files located here. No modifications have been made to these files. According to the information on Environment Variables, the keys specified in dev.env.js should be accessible during the ...

Is it possible to encounter a MongoDB error for the $or operator in a correctly formatted query?

Here is the problem I am facing: const users = this.mongo.db.collection('Users') let query = { '$or': [ { "email": {'$eq': req.body.email }}, {"username": {'$eq': req.body.username }} ] } users.fi ...

Is it possible to use Selenium with Python for copying and pasting

Is there a way to use control + A in Selenium Python to select text and then retrieve the highlighted text? ...

Using Vue to display a Div inside a TD element of a table does not result in a reactive behavior

I am encountering an issue with a table where the last column contains a div with three options (View, Edit, and Delete). This submenu is initially hidden, but when clicking on the options button in the last column of the table, the array used to control i ...

What method does jQuery Validation use to configure the validation message?

A custom method was developed for the jQuery validation plugin to validate whether a given value meets the length requirements set during validation. The method is structured as follows: jQuery.validator.addMethod("exactLength", function(value, ...

The functionality of AngularJS routing is malfunctioning

I'm having trouble with implementing angularJS routing on my page. Initially, it was working fine but now the browser is not returning anything. Here's the code snippet: angular.module('myRoutingApp', ['ngRoute']) .conf ...

Options for validating data in the igGrid component within igniteui-angular

I am currently working with an igniteui-angluar <ig-grid> and I am interested in validating cells using the checkValue event within the validatorOptions framework. Below is my configuration for the features section: HTML: <features> < ...

Regular expression that matches a string with optional leading and trailing spaces and a hyphen in the middle

I need help creating a JavaScript regex that can match strings like the examples provided. The string may have whitespace at the front, back, or both but not within the string itself. Examples: 'Z5LW-KRT2' MATCH ' Z5LW-krt2' ...

The POST request functions flawlessly on the local server, but encounters issues once deployed to Google Cloud Platform

Even though the Axios post request works fine on my local server, it throws a 404 not found error after I deploy the project on Google Cloud. On localhost, all requests are directed to URLs starting with http://localhost:9000/api/..., handling post reques ...

What is the best way to select the destination folder for output in Webpack?

Whenever I run webpack using "webpack --mode development", it generates a dist folder and places the bundle.js file inside it. My aim is to have it created and placed in the same directory instead. How can I achieve this? module.exports = { entry: " ...

Updating switch data on click using Vuejs: A step-by-step guide

Could someone please explain to me how to swap two different sets of data when clicked? For instance, let's say we have the following data: data() { return { data_one: [ { name: "Simo", ...

Utilizing d3.js to implement a scatterplot with zoom functionality that focuses solely on zooming the axis without affecting

Having trouble creating a scatterplot with zoom functionality where only the axis is getting zoomed, not the data itself. Can anyone provide some assistance or insight on what might be wrong? If you're interested in checking out the project, here&apo ...

JavaScript For Each loops are really starting to frustrate me

My issue seems to be straightforward. I am attempting to update a list of objects called localData with another list of objects that I received after making an AJAX request (referred to as data). The process involves using two loops, however, when I atte ...

Tips for preventing the use of nested functions while working with AJAX?

Consecutively making asynchronous calls can be messy. Is there a cleaner alternative? The issue with the current approach is its lack of clarity: ajaxOne(function() { // do something ajaxTwo(function() { // do something ajaxThree() }); }); ...

Dynamic Assignment of Object Values Based on Enum Keys in Typescript

Check out this TS Playground for this piece of code. Dynamically Assigning Object Values Based on Enum Key I am attempting to achieve the following: in the interface iAnimals, each animal key in the enum Animals should have its associated interface value, ...

Incorporate data from a CSV file into an HTML table on the fly with JavaScript/jQuery

I have a CSV file that is generated dynamically by another vendor and I need to display it in an HTML table on my website. The challenge is that I must manipulate the data from the CSV to show corrected values in the table, only displaying products and not ...

Live JSON sign-up feature on site

Is there a way to retrieve user email in real-time without using JSON? Currently, I am utilizing JSON for this purpose but it poses the risk of exposing emails that are stored in $resEmailsJson. Ideally, I would like to find a solution to hide all JSON $ ...

In Angular, the process of duplicating an array by value within a foreach function is not

I have been attempting to duplicate an array within another array and make modifications as needed. this.question?.labels.forEach((element) => { element["options"] = [...this.question?.options]; // I've tried json.stringify() as wel ...

Adding the Edit action in React-Redux is a crucial step towards creating a dynamic

I am looking to add an edit action to my blog page in addition to the existing ADD, DELETE and GET actions. Any suggestions on how I can implement the EDIT action to make my blog editable with just a button click? Your help would be greatly appreciated. ...