【问题标题】:How can I change .then function to async/await function?如何将 .then 函数更改为 async/await 函数?
【发布时间】:2020-11-30 21:25:51
【问题描述】:

我想用 .then 将此函数传递给 async / await 函数,但我找不到正确的方法。这是函数:

waitForCssClass = function(cssClass, waitTime) {
    var options = [],
    defer = protractor.promise.defer();
          
    browser.wait(function () {
            element.all(by.className(cssClass)).then(function (displayed) {
              options = displayed;
            }, waitTime);
            return options.length > 0;
          }, waitTime).then(function () {
            defer.fulfill(options);
    });
    
    return defer.promise;
};

【问题讨论】:

    标签: node.js async-await protractor


    【解决方案1】:
    waitForCssClass = async function(cssClass, waitTime) {
        return browser.wait(
            async () => await element.all(by.className(cssClass)).count() > 0,
            waitTime,
            'message on failure'
        );
    };
    

    【讨论】:

      猜你喜欢
      • 2017-11-08
      • 2019-11-06
      • 2021-10-19
      • 1970-01-01
      • 2018-12-23
      • 1970-01-01
      • 2021-08-06
      • 1970-01-01
      • 2021-04-10
      相关资源
      最近更新 更多