赛普拉斯断言 has.length;greaterThan number 错误

时间:2021-03-19 11:33:59

标签: cypress

我是 Cypress 的新手,我编写了一个简单的测试:

/// <reference types="Cypress" />

describe('brand workflow', () => {
    it('List brands', () => {
        cy.login().then(() => {
            cy.visit('/brands');

            cy.listBrands().then(() => {
                // TODO: Test the table functions

                cy.get('[data-cy=data-table-row]').should('have.length', '25');
                cy.contains('[data-cy=pagination]', '50').click();

                cy.get('[data-cy=data-table-row]').should('have.length', '50');
                cy.contains('[data-cy=pagination]', 'All').click();

                cy.get('[data-cy=data-table-row]').should('have.length.greaterThan', '50');
            });
        });
    });
});

一切正常,直到这一行 cy.get('[data-cy=data-table-row]').should('have.length.greaterThan', '50'); 抛出此错误:

enter image description here

有人知道为什么会这样吗?

1 个答案:

答案 0 :(得分:2)

错误信息说上面的参数必须是数字,试试

cy.get('[data-cy=data-table-row]').should('have.length.greaterThan', 50);

为什么字符串参数在这里起作用?

cy.get('[data-cy=data-table-row]').should('have.length', '25');

我的猜测是 Javascript 将长度参数的类型强制为字符串并且 '25' === '25' 为真,但在更大的比较中 '100' > '50' 为假。