如果在柏树中不起作用,则仅在以下情况下进入

时间:2020-05-12 10:02:15

标签: cypress

这仅在条件不为if()时执行 如何与柏树一起做??

if(cy.get('div> div> span.fa.fa-exclamation-triangle.ns-icon')。应该('be.visible')){

        cy.log("This user is already Exist")

    }

    else if( cy.get('.login-message')
    .should('have.text', 'An email has been sent to you to verify the email address you provided with 
     a link to activate your account.'))
    {

        cy.log('New user has been signed up successfully')
        cy.wait(5000)

        //Assertion
        //cy.get('.login-message')
            //.should('have.text', 'An email has been sent to you to verify the email address you provided with a link to activate your account.')

        cy.wait(5000)
        cy.get('.icon').click();
        cy.url().should('include', '/Public/Login')

        cy.wait(10000)

    }

1 个答案:

答案 0 :(得分:0)

cy.get('selector').should('clause')并不意味着返回布尔值,因此永远不要将其用于条件检查。

在以下代码段中,$ el是一个jquery(赛普拉斯自动包含jquery)实例,该实例用于任何必需的值。

cy.get('div > div > span.fa.fa-exclamation-triangle.ns-icon').then(($el) => {
    if ($el.is(':visible')) {
        cy.log("This user is already Exist");
    }
});

cy.get('.login-message').then(($el) => {
    const message = 'An email has been sent to you to verify the email address you provided with a link to activate your account.'
    if ($el.text() !== message) {
        return;
    }

    cy.log('New user has been signed up successfully')
    cy.wait(5000)

    //Assertion
    //cy.get('.login-message')
        //.should('have.text', message);

    cy.wait(5000)
    cy.get('.icon').click();
    cy.url().should('include', '/Public/Login')

    cy.wait(10000)
});