(uncaught exception)TypeError: Cannot read properties of null (reading 'length') type error while executing in cypress

huangapple go评论111阅读模式
英文:

(uncaught exception)TypeError: Cannot read properties of null (reading 'length') type error while executing in cypress

问题

以下是已翻译的内容:

来自您的应用程序代码而不是Cypress的以下错误。
> 无法读取null的属性(读取'length')
当Cypress检测到源自您的应用程序的未捕获错误时,它将自动使当前测试失败。
此行为可配置,您可以选择通过侦听uncaught:exception事件来关闭此功能。

英文:

enter image description here
The following error originated from your application code, not from Cypress.
> Cannot read properties of null (reading 'length')
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.L

答案1

得分: 3

在Cypress测试中,您可以在顶部添加一行代码来阻止此错误(在应用程序中)导致测试失败。

当然,您需要确保错误与您正在测试的内容无关。

代码如下:

Cypress.on('uncaught:exception', () => { return false })

cy.visit('/');
cy.get('#LoginUser').type('**')
cy.get('#password-field').type('**')
cy.get('#Login').click()

cy.contains('Dashboard')  // 通过

Cypress运行器仍然会在日志中显示错误,但您可以继续测试登录后的页面。

在这种情况下,看起来错误是由缺少元素 #myPieChart 导致的。

英文:

In the Cypress test you can add a line at the top that stops this error (in the app) from failing the test.

Of course, you will want to be sure that the error is not related to what you are testing.

The code would be

Cypress.on('uncaught:exception', () => { return false })

cy.visit('/');
cy.get('#LoginUser').type('**')
cy.get('#password-field').type('**')
cy.get('#Login').click()

cy.contains('Dashboard')  // passes

The Cypress runner will still show the error in the log, but you can continue and test the page after login.

In this case, it looks like the error is caused by a missing element #myPieChart.

huangapple
  • 本文由 发表于 2023年5月24日 17:59:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76322285.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定