If statement CYPRESS-无法生成一个THEN=>;如果可见语句

If statement CYPRESS-无法生成一个THEN=>;如果可见语句,if-statement,testing,null,cypress,visible,If Statement,Testing,Null,Cypress,Visible,好, 情况如下: 在我在网站上做的一个测试中,它总是有一个表,但当该表没有元素时,它就被隐藏了。仅当该表具有可见元素时,我才需要执行操作。如果没有,继续进行下一个测试 例如,如果表是空的,我写这个--cy.get('element',{timeout:60000}).should('be.visible')--测试超时,这是正确的,因为表是空的,因此不会变为可见 但是,当然,我需要测试不要超时,我需要在规定的时间过后,它继续进行下一个测试 所以,我想到了这个: 问题是,它总是在测试时输入if

好,

情况如下:

在我在网站上做的一个测试中,它总是有一个表,但当该表没有元素时,它就被隐藏了。仅当该表具有可见元素时,我才需要执行操作。如果没有,继续进行下一个测试

例如,如果表是空的,我写这个--cy.get('element',{timeout:60000}).should('be.visible')--测试超时,这是正确的,因为表是空的,因此不会变为可见

但是,当然,我需要测试不要超时,我需要在规定的时间过后,它继续进行下一个测试

所以,我想到了这个:



问题是,它总是在测试时输入if并打印控制台日志。这意味着“如果可见”条件不起作用

有什么想法吗


谢谢

因此有两种情况需要测试,一种是表中有元素,另一种是表中没有元素。我会将其分为两个测试用例,并填充/不填充该表,使其显示或不显示。IMHO,在一个测试用例中这样做并不能证明这个表是否工作,因为你如何知道你看到的是正确的。您可能会遇到这样的情况:表应该显示,因为它有内容,但没有,但您的测试将始终通过,因为它不知道表的状态应该是什么。所以有点像

describe('Testing my table', () => {
  context('table is populated', () => {
  beforeEach {
  // populate the table with data
  }
  it('should show the table, () => {
    // Some testing stuff in here to check the table is showing
  });

  context('table is NOT populated', () => {
  beforeEach {
  // Any set up you need for a non-populated table
  }
  it('shouldn't show the table, () => {
    // Check we can't see the table
  });
describe('Testing my table', () => {
  context('table is populated', () => {
  beforeEach {
  // populate the table with data
  }
  it('should show the table, () => {
    // Some testing stuff in here to check the table is showing
  });

  context('table is NOT populated', () => {
  beforeEach {
  // Any set up you need for a non-populated table
  }
  it('shouldn't show the table, () => {
    // Check we can't see the table
  });