1

Im new in cypress, trying to login to my practice web, but I got problem with this gtag. The actual testing with cypress is done (user success login) but there is one error that keeps make this testing failed, does anyone can help me?. this my pic and my cypress code and my config

This is my error pic

1

describe('Login user', () => {
  beforeEach(() => {
    cy.viewport(1392, 768)
    cy.visit('thiswebcom')

  })

  it('Login as user', () => {
    cy.get('a[href*="/login"]').first().click()
    cy.get('#buttonLoginTrack').should('have.text', '\n                                                        Login\n                                                    ')
    
    const userName = '[email protected]'
    const password = 'mypassword'

    cy.get('#email').type(`${userName}`)
    cy.get('#password').type(`${password}`).type('{enter}')

  })

this is my cypress code for login in

module.exports = {
  e2e: {
    setupNodeEvents(on, config) {
      // implement node event listeners here

    },
  },
};

this is my cypress.config.js file

I tried with blockHosts but no idea how to put it in, thanks

2 Answers 2

0

Since you have "uncaught exception" in the picture there, it means that the application itself is creating that error - which is not visible to the user under normal circumstances unless you check for it in the devtools.

The trick is to put a catcher into the top of the test like this

Cypress.once('uncaught:exception', (err, runnable) => {
  return false;
})

That stops the test from failing just because of a potentially harmless error in the app.

Here is some documentation: Uncaught exceptions.

Generally speaking, as a tester you will be a bit worried about such an error, but it can't be fixed from the test, only from the application itself.

Sign up to request clarification or add additional context in comments.

2 Comments

this is simple answer for any1 that understand, its work!, thank you very much
Change to Cypress.once() to handle the error one time only, then automatically switch off the catcher.
-1

Kitty.Flanagan's answer is a good one but should be cautious when using Cypress.on() as it will have a global impact, whereas cy.on() will only persist for the test file.

Furthermore, returning false will bypass all uncaught exceptions and can lead to issues not being caught by your tests.

Ultimately, you want raise issues for any uncaught exceptions to your dev team. In the chance that the uncaught exception is something thrown by 3rd party and cannot be addressed, then I would suggest adding the following to your test file.

cy.on('uncaught:exception', (err, runnable) => {
  return !e.message.includes('ReferenceError: gtag is not defined in Cypress')
})

3 Comments

wow, thx for your correction, this is what Im using now
Does not really make sense to me, why would you catch one error but not another?
Third party integrations can throw uncaught exceptions, which don't typically interfere with the functional use. You can stub those integrations, when the test is not using that feature. Otherwise, catching exceptions by your app should be caught.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.