Cypress之动态忽略测试用例

发布时间 2023-04-16 22:29:46作者: 俊king

Cypress之动态忽略测试用例

示例代码:

describe('Login', () => {
    const username = '';
    const password = '';
    
    context('Test Login', () => {
        if(Cypress.env('funFlag') == 1) {
            cy.visit('');
            
        }else {
            this.skip();
            cy.log("runFlage === 0");
        }
    });
})

Cypress之动态生成测试用例

数据文件:

export const testLoginUser = 
[
    {
        summary: "Login Pass",
        username: "",
        password: "Jw123456"
    },
    {
        summary: "Login fail",
        username: "",
        password: "Jw1234567"
    }
]

用例文件:

import { testLoginUser } from '../data/test_login_data';

describe('Test', () => {
    beforeEach('After All', () => {
        cy.visit('https://console-pre.raylink.live/login');
    });
    /**
     * 这样就实现了多种场景的覆盖,例如:
     * 1. 正确账号,正确密码,测试通过
     * 2. 正确账号,错误密码,测试失败
     */
    context('Many login cases', () => {
        for(const user of testLoginUser) {
            it(user.summary, function() {
                cy.get('ul>li:nth-child(2)')
                .as('change_Btn');
                cy.get('@change_Btn')
                .click();

                cy.get('input[id=agree]')
                .click();
                cy.get('input[id=name]')
                .type(user.username);
                cy.get('input[id=password]')
                .type(user.password);

                cy.get('button[type=submit]')
                .should('have.class', 'button__StyledButton-sc-1xvpoi0-0')
                .should('have.class', 'DNJh atom__SumbitButton-sc-1f08aeq-3')
                .should('have.class', 'jdbddl')
                .as('submit_Btn');
                cy.get('@submit_Btn')
                .click();
            });
        }
    });
});