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:

https://i.sstatic.net/dCmpt.png

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

A guide to entering information into an input field with JavaScript for logging in successfully

https://i.stack.imgur.com/TF51Z.gif https://i.stack.imgur.com/HHsax.png https://i.stack.imgur.com/HUztt.png When attempting to input text using document.getelement('').value="" , it doesn't behave as expected. The text disappear ...

The 'undefined' type cannot be assigned to the 'never' type

interface A { name?: string age: number } var a: A = { name: '', age: 23 } var result:A = (Object.keys(a) as Array<keyof A>).reduce((prev, key) => { if (a[key] || a[key] === 0) { prev[key] = a[key] // an error was reporte ...

The selected plugin appears to be incompatible with mobile browsers

My project involves implementing the Chosen plugin for a select field, allowing users to type-search through lengthy lists. It functions perfectly on desktop but is disabled on both Apple and Android phones, reverting to the default user interface for sele ...

The Angular NgFor directive can only be used to bind data to Iterables like Arrays

I am encountering an issue when attempting to iterate through and display data using ngFor. The specific error appearing in the console is "Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only su ...

Can I incorporate NodeJS modules such as "oauth" into my Firefox extension?

I am diving into the world of Firefox addons for the first time. My project entails making calls to Twitter's APIs, which means I require an oauth library to kick things off. After some research, I came across an existing library in the npm package r ...

When passing an invalid value to the Props in TypeScript, no errors are being thrown

const enum ColumnValues { one = 1, two = 2, three = 3, } interface Props { style?: StyleProp<ViewStyle>; title?: string; titleContainerStyle?: StyleProp<ViewStyle>; titleStyle?: StyleProp<TextStyle>; textInputStyle?: Styl ...

Transforming a base64 string into a uint8Array or Blob within Typescript/Angular8

I'm new to handling Base64 encoded strings, uint8Array, and Blobs. I've integrated a pdf viewer library from this repository https://github.com/intbot/ng2-pdfjs-viewer into our Angular 8 web application. I'm facing an issue where I am sendin ...

Merging two arrays of objects from the same response in JavaScript

How can I efficiently merge two arrays of objects from the same response? let data = [{ "testLevel":"mid", "testId":"m-001", "majorCourse": [ { "courseName":"C++" ...

Dealing with Challenges in Constructing JQuery URLs

I'm facing an issue with loading a website into a specific div (div.content). The website I'm trying to load requires a login through a POST request. When the javascript attempts to load the site, it recognizes the redirection to the login form ...

Unable to retrieve information from Excel spreadsheet during automated testing

Kindly review the following code for any necessary corrections: package com.framework; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.time.Duration; import org.apache.poi.ss.usermodel.Sheet; import org.apache. ...

Using jQuery to insert a div class with PHP referenced

My variable stores a color name. Here is an example: <?php $myvar = blueColour; ?> I want to apply this value to the body of an html page using jQuery: <script type="text/javascript"> jQuery(body).addClass("<?php echo $myvar; ?>"); < ...

A tutorial on dynamically adding fields with a dropdown list (populated from a database) and a text box using PHP and JQuery

I have multiple form components that I need to add dynamically, allowing users to add more than one. Firstly, there is a dropdown list with values populated from MySQL, followed by a text box for inquiries entry. The dropdown list displays a list of users, ...

Display a block by using the focus() method

My objective is : To display a popin when the user clicks on a button To hide the popin when the user clicks elsewhere I previously implemented this solution successfully: Use jQuery to hide a DIV when the user clicks outside of it However, I wanted to ...

When attempting to utilize the dispatch function in a class-based component, an invalid hook call error may

I am a beginner with react-redux. I currently have this code that uses react, redux, and TypeScript. The code utilizes a class-based component and I am attempting to use dispatch to trigger an action to increment the value of counter. However, I encountere ...

What is the best way to continuously execute the 'onclick' function using AJAX inside a specific ID?

My challenge involves implementing a new AJAX upload feature to insert a data element from the onClick event in multiple rows. The issue I am facing is that it works fine for the first row, but when I add subsequent rows, the function no longer works upon ...

Discover the ins and outs of integrating YAML front matter into your destination directory path

I am looking to customize the path of my blog posts to include a fancy date format like /blog/2013/09/17 so that the links from my previous octopress blog remain intact. Within the YAML front matter on each markdown page, I have included the date informat ...

Is there a way to access the rear camera on a mobile device using webcam.js?

Currently, I am utilizing webcam.js from the following link: https://github.com/jhuckaby/webcamjs. When accessing the website on mobile devices, the front camera tends to open by default. My objective is to switch this default setting to access the rear ...

The assignment of Type Observable<Observable<any[]>> to Observable<any[]> is not valid

Working on implementing autocomplete using data from a database service: @Injectable() export class SchoolService { constructor(private db: AngularFirestore) { } getSchools(): Observable<School[]> { return this.db.collection<School> ...

Error message: The object is not visible due to the removal of .shading in THREE.MeshPhongMaterial by three-mtl-loader

Yesterday I posted a question on StackOverflow about an issue with my code (Uncaught TypeError: THREE.MTLLoader is not a constructor 2.0). Initially, I thought I had solved the problem but now new questions have surfaced: Even though I have installed &apo ...

Type to match the data type of the enum, not strictly one specific value

enum X { A = 'x', B = 'y' } type A<T> = { prop1: T prop2: X } let r:A<X> = { prop1: X.A, prop2: X } What specific type must be assigned to A.prop2 in order for only X and no other item to also be assigned to i ...