我的需求是:先判断是否登录,当检测到有未登录的文字时,认定为未登录,再进行登录输入账号密码操作。

结果是,可以在 text() 异步回调里判定为未登录,可是在异步回调里增加一个 it 登录输入账号密码操作时,后台无法进行下一步,提示 Cannot read property 'title' of undefined 的错误


describe('测试测试场景:登录', function () {
    //判断是否登录
    jym_userCenterActions.checkisLogin(function (isLogin) {
        console.log("是否登录===>" + isLogin);
        if (isLogin === true){

        } else {
            //登录 #这里会出错...求解#
            it('点击账号输入', function(){
                driver.wait('//*[@text="手机"]', 5000).sendElementActions('tap');
            });
            ........
        }
    });
});

exports.checkisLogin = function (callback) {
    it('检测是否登录?', function(){
        console.log("start check is Login...");
        driver.wait(jym_userCenterComponents.accountDisplay.androidElem, 5000).text().then(function (text){
            if (text === jym_userCenterComponents.accountDisplay.elementDesc) {
                callback(false);
            } else {
                callback(true);
            }
        });
    });
};

错误日志如下:
Problem with mochawesome: TypeError: Cannot read property 'title' of undefined
at copyScreenShots (/home/jacklai/MacacaProjects/jym_uiautotest/node_modules/_mochawesome-uirecorder@1.5.20@mochawesome-uirecorder/lib/mochawesome.js:315:39)
at cleanSuite (/home/jacklai/MacacaProjects/jym_uiautotest/node_modules/_mochawesome-uirecorder@1.5.20@mochawesome-uirecorder/lib/mochawesome.js:244:3)
at /home/jacklai/MacacaProjects/jym_uiautotest/node_modules/_mochawesome-uirecorder@1.5.20@mochawesome-uirecorder/lib/mochawesome.js:225:9
at arrayEach (/home/jacklai/MacacaProjects/jym_uiautotest/node_modules/_lodash@3.10.1@lodash/index.js:1289:13)
at Function. (/home/jacklai/MacacaProjects/jym_uiautotest/node_modules/_lodash@3.10.1@lodash/index.js:3345:13)
at traverseSuites (/home/jacklai/MacacaProjects/jym_uiautotest/node_modules/_mochawesome-uirecorder@1.5.20@mochawesome-uirecorder/lib/mochawesome.js:224:9)
at Runner. (/home/jacklai/MacacaProjects/jym_uiautotest/node_modules/_mochawesome-uirecorder@1.5.20@mochawesome-uirecorder/lib/mochawesome.js:97:9)
at emitNone (events.js:91:20)
at Runner.emit (events.js:185:7)
at /home/jacklai/MacacaProjects/jym_uiautotest/node_modules/_mocha@3.1.2@mocha/lib/runner.js:813:12
at /home/jacklai/MacacaProjects/jym_uiautotest/node_modules/_mocha@3.1.2@mocha/lib/runner.js:661:9
at next (/home/jacklai/MacacaProjects/jym_uiautotest/node_modules/_mocha@3.1.2@mocha/lib/runner.js:295:14)
at Immediate. (/home/jacklai/MacacaProjects/jym_uiautotest/node_modules/_mocha@3.1.2@mocha/lib/runner.js:339:5)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate as _immediateCallback


↙↙↙阅读原文可查看相关链接,并与作者交流