如何检查一个元素是否具有“任何”值 Cypress?

Lov*_*ndy 0 cypress

我正在编写一些基本的 cypress 测试,我只是想确保我们拥有的表具有所有正确的列并且所有数据都正在渲染。

我知道.contains()检查元素选择并允许文本匹配,但此表中可能有各种数据,我只想确保从后端呈现某些内容。

知道如何检查是否有任何(非特定)值吗?

describe('Data Source Table renders properly', () => {
  beforeEach(() => {
    cy.viewport(1920, 1080)
    cy.visit('http://localhost:3000/source')
    // Assert we are on the correct page /source
    cy.url().should('include', '/source')
  })
  it('Data Source header exists', () => {
    cy.contains('Data Source')
  })
  it('Data Source table exists, column headers are correct and there is data', () => {
    cy.get('table').should('exist')
    cy.wait(2000)
    cy.get('table').contains('th', 'Ip')
    cy.get('table').contains('th', 'Station')
    cy.get('table').contains('th', 'Table')
    cy.get('table').contains('th', 'Status')
  })
})
Run Code Online (Sandbox Code Playgroud)

Vis*_*sal 5

这更简洁,IMO 更不容易出错

cy.get('table thead th')
  .each($th => {
    expect($th.text()).not.to.be.empty
  })
Run Code Online (Sandbox Code Playgroud)

您可以删除cy.get('table').should('exist')cy.wait(2000)