【问题标题】:Mocha conditional testing - If else always passesMocha 条件测试 - If else 总是通过
【发布时间】:2020-05-21 19:51:52
【问题描述】:

我正在尝试对我的一个元素进行条件测试,但 mocha 完全跳过了“if else”语句,只显示了“it("")”的输出

这是我的做法:

    it('if test case', async function () {

        var cardProcZero = await driver.hasElementByAccessibilityId("card_proc_0"); // looks up the element

        let visivel = expect(cardProcZero).to.be.ok; // expects it to exist 
        let naoVisivel = expect(cardProcZero).to.not.be.ok; // expects it not to exist

        if (cardProcZero == naoVisivel) { // if it's not visible, it creates the element
            let adicionarProc = await driver.waitForElementByAccessibilityId("button_addProcedimento"); // adds the element
            await adicionarProc.click();
            return false;

        } else if (cardProcZero == visivel) { // if it is visible, it clicks on it
            await cardProcZero.click(); // clicks on existing element
            return true;
        }
    });

在终端中,mocha 在我最后一个测试用例之后输出:

✓ if test case (527ms)

它甚至不尝试做其他现有的“它”。它只是跳过它。

我到底做错了什么?

【问题讨论】:

    标签: javascript mocha.js appium chai appium-ios


    【解决方案1】:

    尝试在没有 chai.js 期望的情况下这样做,它可以工作。

    如果有人有同样的问题,我是这样做的:

    it('if test case', async function () {
        var cardProcZeroVerify = await driver.hasElementByAccessibilityId("card_proc_0"); 
    
        if (cardProcZeroVerify === false || undefined || null) { 
            console.warn('Adicionando novo procedimento');
            let adicionarProc = await driver.waitForElementByAccessibilityId("button_addProcedimento"); 
            await adicionarProc.click();
        }
    
        else {
            console.warn('Abrindo um procedimento já existente');
            let cardProcZero = await driver.waitForElementByAccessibilityId("card_proc_0"); 
            await cardProcZero.click();
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2018-01-11
      • 1970-01-01
      • 2018-04-17
      • 1970-01-01
      • 1970-01-01
      • 2021-10-03
      • 2021-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多