When I tried to automate the SAP official website using Cypress, I got the following error message:
The following error originated from your application code, not from Cypress.
top.$ is not a function
When Cypress detects uncaught errors originating from your application it will automatically fail the current test.
This behavior is configurable, and you can choose to turn this off by listening to the uncaught:exception event.
Top.$is not a function error message: SAP www.sap.com, not Cypress One option for such cases is to ignore such application exceptions through exception capture in Cypress test code.
On a technical note, Cypress considers uncaught exceptions to be any error that is uncaught by your application, whether they are “standard” errors or unhandled promise rejections. If the error triggers the window’s global error handler or its unhandledrejection handler, Cypress will detect it and fail the test.
It is important to note that Cypress will also detect an exception thrown by an application that eventually triggers the Windows Global Error Handler or its UnHandledrejection handler. And terminates its tests in a failed state.
Complete code to disable application error messages in Cypress:
/// <reference types="Cypress" />
describe('My First Test'.() = > {
it('finds the content "type"'.() = > {
cy.visit('https://www.sap.com');
cy.url().should('include'.'index.html');
/* cy.contains('type').click(); cy.url().should('include', '/commands/actions'); cy.get('.action-email') .type('[email protected]') .should('have.value', '[email protected]'); * /
});
});
Cypress.on('uncaught:exception'.(err, runnable) = > {
// returning false here prevents Cypress from
// failing the test
console.log('Jerry errors! ');
return false
})
Copy the code
Final effect:
SAP web Page error message does not affect the continuation of Cypress test:
More of Jerry’s original articles can be found in “Wang Zixi” :