【问题标题】:Same Cypress tests reporting different results on different machines using Chrome & Electron相同的 Cypress 测试使用 Chrome 和 Electron 在不同的机器上报告不同的结果
【发布时间】:2021-04-29 15:45:06
【问题描述】:

我和我的同事在我们的机器上运行相同的赛普拉斯测试套件,但得到不同的结果。

我们使用的 Cypress 版本是3.8.3

当他们运行.\node_modules\.bin\cypress run 时,所有测试都通过了。

但是当我尝试在我的机器上运行相同的命令时,其中一项测试失败了。

我收到以下错误消息:

<failure message="cy.type() can only be called on a single element. 
Your subject contained 8 elements." type="CypressError">
<![CDATA[CypressError: cy.type() can only be called on a single element. Your subject contained 8 elements.

我能理解测试在说什么,但我不知道为什么我们在不同的机器上运行相同的测试时会得到不同的结果。

我发现的一个区别是他们可以选择在 Chrome 上运行测试,而我只能选择在 Electron 上运行。

有人可以帮忙解释一下是什么原因造成的,以及如何解决这个问题

【问题讨论】:

  • 这个错误听起来对您正在测试的 DOM 非常具体(听起来像是一个具有多个输入的表单),您能否详细说明 DOM 的详细信息以及在其上使用的测试?

标签: google-chrome electron cypress


【解决方案1】:

赛普拉斯会自动检测本地计算机上安装的浏览器。所以请检查您是否安装了chrome。 Electron 直接自带 cypress。

应用程序的行为可能因机器而异,也因浏览器而异,具体取决于配置和互联网速度。因此,使用Test Retries 总是好的,它将根据定义的值重试测试,然后最终将测试标记为失败。 cypress 5.0 中引入了测试重试。

您可以通过cypress.json在全球范围内应用它们

{
  "retries": {
    // Configure retry attempts for `cypress run`
    // Default is 0
    "runMode": 2,
    // Configure retry attempts for `cypress open`
    // Default is 0
    "openMode": 0
  }

或者,您也可以将其添加到特定测试中 -

describe('User sign-up and login', () => {
  // `it` test block with no custom configuration
  it('should redirect unauthenticated user to sign-in page', () => {
    // ...
  })

  // `it` test block with custom configuration
  it(
    'allows user to login',
    {
      retries: {
        runMode: 2,
        openMode: 1,
      },
    },
    () => {
      // ...
    }
  )
})

或者到特定的测试套件 -

// Customizing retry attempts for a suite of tests
describe('User bank accounts', {
  retries: {
    runMode: 2,
    openMode: 1,
  }
}, () => {
  // The per-suite configuration is applied to each test
  // If a test fails, it will be retried
  it('allows a user to view their transactions', () => {
    // ...
  }

  it('allows a user to edit their transactions', () => {
    // ...
  }
})

【讨论】:

    猜你喜欢
    • 2021-06-23
    • 1970-01-01
    • 2021-08-21
    • 2016-11-08
    • 1970-01-01
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    相关资源
    最近更新 更多