CYPRESS-Cant make THEN => IF VISIBLE语句

问题描述 投票:0回答:1

好,

这里是情况:

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

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

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

所以,我想到了:


cy.get('element').then(($table) => {  
    if ($table.is(':visible')){
        cy.log('JUST TESTING')
    }
}) 

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

有什么想法吗?

谢谢!

if-statement testing null cypress visible
1个回答
0
投票

因此,您有两种情况需要测试,一种情况是表中是否包含元素,另一种情况是表中没有元素。我将其分为两个测试用例,然后填充/不填充表,以便显示或不显示。恕我直言,在一个测试用例中执行此操作并不能证明表在工作或不工作,因为您如何知道自己所看到的是正确的。您可能会遇到这样的情况,表格应该显示,因为它具有内容,但是没有,但是您要测试总是通过,因为它不知道表格的状态应该是什么。所以像...

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
  });
© www.soinside.com 2019 - 2024. All rights reserved.