调用promise调用时,wdio异步调用会丢弃Selenium连接

问题描述 投票:1回答:1

版本:“webdriverio”:“^ 5.7.5”,

如果我不清楚,请提前道歉,请让我知道并相应地传递我的意见。

我在公司代理后面运行我的wdio5脚本。它在所有浏览器中成功运行。我试图将api调用集成到框架中并开始出现多个问题。

像supertest,axios [httpsProxyAgent included],sync-request,then-request这样的Api库不会读取wdio使用的npm代理变量。因此,我在API调用上收到以下错误消息

错误:getaddrinfo ENOTFOUND qa.internalurl.co.uk qa.internalurl.co.uk:443

Api库(例如 - request,fetch-with-proxy)通过使用代理设置成功调用API。我需要“等待”他们的响应,因此将我的块作为异步函数移动。但在作为异步调用成功响应后,我收到以下错误消息

[chrome#0-0] $(...)。waitForExist不是一个函数

[chrome#0-0] TypeError:$(...)。waitForExist不是函数

不仅仅是waitForExist,会话几乎无法记住任何selenium / webdriverio命令。很明显,当它切换到异步调用以获取promise响应时,它会丢失selenium连接。

有办法解决这个问题吗?

let accountNo = "123456";
it.only('verify the dashboard page ',async () => {

            //launches the browser url and cleans the cookies 

            try {
                response = await apiCheck.postApiLoginData(accountNo);
  //Makes to call to API function to get the values
            } catch (err) {
                console.error(err);
            }

            console.log(response);    //prints the successful response data 
            lPage.enterLoginData(accountNo, 'pass1234'); //Fails here as the data is 

            addStep(`Login to the Standard application using username as ${accountNo} and PIN as 74437`);

            lPage.assertSummaryPage(response); 

}

如果没有Try阻止代码,请成功登录到应用程序。

javascript selenium-webdriver async-await webdriver-io
1个回答
1
投票

要处理非wdio异步代码,您需要使用the browser.call function。例如:

response = browser.call(() => {
    return apiCheck.postApiLoginData(accountNo);
    //Makes to call to API function to get the values
})
© www.soinside.com 2019 - 2024. All rights reserved.