cypress - Timeout value for getAllByTestId?
问题描述
cy.wait(20 * 1000);
cy.getAllByTestId('test-field-one')
.first()
.within(() => cy.getByTestId('test-field-two'))
.should('contain', 'test');
I'm currently using the above code, but I don't like the wait. I'd much rather prefer a timeout value. Does anyone know if this is possible in cypress?
解决方案
这些getAll...
函数不能真正使用超时。
{ timeout: 20 * 1000 }
和之间的区别在于cy.wait(20 * 1000)
超时在满足条件时会提前返回。
但究竟有多少是“全部”?
进行“全部”查询的唯一方法是等待最长时间并在该时间点返回所有内容 - 这就是您已经使用 explicit 所做的cy.wait()
。
由于您正在使用.first()
,只需切换到cy.getByTestId()
cy.getByTestId('test-field-one', { timeout: 20 * 1000 })
.within(() => cy.getByTestId('test-field-two'))
.should('contain', 'test')
另请注意
.should('contain', 'test')
正在测试test-field-one
不是test-field-two
因为.within()
没有传递内部值,而是传递了前一个主题。
推荐阅读
- driver - 如何在 ubuntu 上安装以下驱动程序?(USRP1)
- java - Junit did not show any results using IntelliJ for UCB cs61B (org.junit.Assert.assertArrayEquals() )
- php - 数组循环从中间开始
- android - I am having an issue with linking QR code URL to my android app as deep link
- c# - issues with Identity and Authorize using Roles and Policy
- ios - UIViewController back button not shown
- sql - I have a SQL db file, I want to use it in Azure
- node.js - 在以太坊中部署智能合约时如何解决错误?
- ios - UIButton Gradient View 上未显示标题
- c# - Get variable from base of view model in c#