WebdriverIo 对于异步测试和钩子,确保“done()";叫做;如果返回 Promise,请确保它已解决 [英] WebdriverIo For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves

查看:100
本文介绍了WebdriverIo 对于异步测试和钩子,确保“done()";叫做;如果返回 Promise,请确保它已解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看过这个解决方案,但没有帮助.

我正在尝试使用 mocha 运行 webdriver.io 测试,这里我使用的是 webdriver.io 中的 browser.waitUntil() 方法,可以在此处找到更多详细信息:https://webdriver.io/docs/api/browser/waitUntil.html我已经尝试了一个不同的解决方案来解决这个问题,包括在方法调用中添加完成",并且我还在 conf.js 中给出了最大超时时间 10000 毫秒,但是,页面似乎仍然挂在结果页面上.

这里增加超时:

 mochaOpts: {ui: 'bdd',超时:100000},

将 mocha 的默认等待时间更改为 100000 毫秒添加完成作为承诺解决

it('should see product and version selected', () => {browser.url('//某个网址');browser.maximizeWindow();browser.waitUntil(() => {返回 $(ProductPage.productSelector()).isDisplayed()}, 100000, '预期页面已加载');让 productSelector = ProductPage.otherProductSelector();让 isEnabled = productSelector.isEnabled();if(isEnabled == true){const spanEle = $('//span[contains(text(),"text")]');isDisplayed = spanEle.isDisplayed();console.log(isDisplayed);assert.equal(isDisplayed, true, "Passed");}})

错误:

超时超过 100000 毫秒.对于异步测试和钩子,确保调用done()";如果返回 Promise,请确保它已解决.

解决方案

这里我从测试中删除了 browser.waitUntil(() => { .. } 语句,并添加了 WebdriverIO 提供的不同等待.似乎有与此方法中的 promise 返回相关的一些问题无法通过满足 promise 或任何其他方法来解决它.我有人知道,请在此答案中添加评论.以下是更多详细信息:https://github.com/webdriverio/webdriverio/issues/2361

所以我改变的内容如下:

it('should see product and version selected', () => {browser.url('url');browser.maximizeWindow();让 productSelector = $('#product-dropdown-toggle')让 isEnabled = productSelector.isEnabled();if(isEnabled == true){const spanEle = $('//span[contains(text(),"text")]');isDisplayed = spanEle.isDisplayed();console.log(isDisplayed);assert.equal(isDisplayed, true, "Passed");}})

 waitForElemenDisplayed(element,timeout){element.waitForDisplayed(超时);}

I have already seen this solution, but it did not help.

I am trying to run webdriver.io tests using mocha, here I am using browser.waitUntil() method from webdriver.io, more details can be found here: https://webdriver.io/docs/api/browser/waitUntil.html I have tried a different solution to the issue including adding 'done' to the method call and also I am giving max timeout in conf.js as well here 10000ms, but still, the page seems to get hang on the result page.

Here increase timeout:

   mochaOpts: {
        ui: 'bdd',
        timeout: 100000
    },

Changed default wait time of mocha to at 100000ms Added done as promise resolution

it('should see product and version selected', () => {
        browser.url('//some url');
        browser.maximizeWindow();
        browser.waitUntil(() => {
            return $(ProductPage.productSelector()).isDisplayed()
        }, 100000, 'expected page is loaded');
        let productSelector = ProductPage.otherProductSelector();
        let isEnabled = productSelector.isEnabled();
        if(isEnabled == true){
            const spanEle = $('//span[contains(text(),"text")]');
            isDisplayed = spanEle.isDisplayed();
            console.log(isDisplayed);
            assert.equal(isDisplayed, true, "Passed");
        }
    })

Error:

Timeout of 100000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. 

解决方案

Here I have removed browser.waitUntil(() => { .. } statement from the test and added different waits provided by the WebdriverIO. It seems there are some issues related to promise returning in this method was not able to resolve it by satifying promise or any other. I anyone knows please add a comment to this answer. Here are more details with this: https://github.com/webdriverio/webdriverio/issues/2361

So what I have changed is as below:

it('should see product and version selected', () => {
        browser.url('url');
        browser.maximizeWindow();
        let productSelector = $('#product-dropdown-toggle')
        let isEnabled = productSelector.isEnabled();
        if(isEnabled == true){
            const spanEle = $('//span[contains(text(),"text")]');
            isDisplayed = spanEle.isDisplayed();
            console.log(isDisplayed);
            assert.equal(isDisplayed, true, "Passed");
        }
    })


 waitForElemenDisplayed(element,timeout){
        element.waitForDisplayed(timeout);
    }

这篇关于WebdriverIo 对于异步测试和钩子,确保“done()";叫做;如果返回 Promise,请确保它已解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆