gpt4 book ai didi

javascript - wdio 异步调用在调用 promise 调用时丢弃 Selenium 连接

转载 作者:行者123 更新时间:2023-11-30 19:37:09 25 4
gpt4 key购买 nike

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

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

我在公司代理后面运行我的 wdio5 脚本。它在所有浏览器上成功运行。我尝试将 API 调用集成到框架中,但开始遇到多个问题。

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

Error: getaddrinfo ENOTFOUND qa.internalurl.co.ukqa.internalurl.co.uk:443

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

[chrome #0-0] $(...).waitForExist is not a function

[chrome #0-0] TypeError: $(...).waitForExist is not a function

不仅仅是 waitForExist, session 几乎无法记住任何 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 block 代码,成功登录到应用程序。

最佳答案

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

response = browser.call(() => {
return apiCheck.postApiLoginData(accountNo);
//Makes to call to API function to get the values
})

关于javascript - wdio 异步调用在调用 promise 调用时丢弃 Selenium 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55815751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com