gpt4 book ai didi

javascript - 如何在 Protractor 中使用异步等待?

转载 作者:行者123 更新时间:2023-11-28 04:40:18 25 4
gpt4 key购买 nike

我已经将我的node.js版本更新到7.6以上,并且我正在使用ES6。我还附加了错误消息。我正在使用jasmine和javascript来编写测试。没有aysnc-await它工作正常..我无法弄清楚为什么会出现以下错误。任何帮助将不胜感激

  My code is :-
SELENIUM_PROMISE_MANAGER: false,
describe("testing login functionalties", function() {

it("entering the text", async function () {

browser.get("https://weather.com/en-IN");
//console.log('ddd')
browser.ignoreSynchronization= true;
element(by.xpath("//button[@class='user-login']")).click()
//browser.ignoreSynchronization= true;
console.log('ddd')
element(by.xpath("//input[@type='email']")).sendKeys("offsite.mail1@gmail.com");
element(by.xpath("//input[@type='password']")).sendKeys("xxxxx");
var a= element(by.xpath("//button[@class='btn btn-disabled sign-button login-button']"));
await a.getText();
console.log(a);
a.click();


});

});

    And the error i am getting is:-
/usr/local/Cellar/node/7.9.0/bin/node /usr/local/lib/node_modules/protractor/built/cli.js /Users/amrit/WebstormProjects/E2E/conf.js
(node:13230) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
(node:13230) DeprecationWarning: `DEBUG_FD` is deprecated. Override `debug.log` if you want to use a different log function (https://git.io/vMUyr)
[16:03:41] I/local - Starting selenium standalone server...
[16:03:41] I/launcher - Running 1 instances of WebDriver
[16:03:42] I/local - Selenium standalone server started at http://10.101.23.28:60360/wd/hub
Started
F

Failures:
1) testing login functionalties encountered a declaration exception
Message:
Error: async function () {

browser.get("https://weather.com/en-IN");
//console.log('ddd')
browser.ignoreSynchronization= true;
element(by.xpath("//button[@class='user-login']")).click()
//browser.ignoreSynchronization= true;
console.log('ddd')
element(by.xpath("//input[@type='email']")).sendKeys("offsite.mail1@gmail.com");
element(by.xpath("//input[@type='password']")).sendKeys("xxxxx");
var a= element(by.xpath("//button[@class='btn btn-disabled sign-button login-button']"));
await a.getText();
console.log(a);
a.click();


} is not a function
Stack:
Error: async function () {

browser.get("https://weather.com/en-IN");
//console.log('ddd')
browser.ignoreSynchronization= true;
element(by.xpath("//button[@class='user-login']")).click()
//browser.ignoreSynchronization= true;
console.log('ddd')
element(by.xpath("//input[@type='email']")).sendKeys("offsite.mail1@gmail.com");
element(by.xpath("//input[@type='password']")).sendKeys("xxxxx");
var a= element(by.xpath("//button[@class='btn btn-disabled sign-button login-button']"));
await a.getText();
console.log(a);
a.click();


} is not a function
at validateFunction (/usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:30:11)
at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:116:16
at Suite.<anonymous> (/Users/amrit/WebstormProjects/E2E/Describe.js:8:5)
at Object.<anonymous> (/Users/amrit/WebstormProjects/E2E/Describe.js:6:1)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)

1 spec, 1 failure
Finished in 0.011 seconds
[16:03:44] I/local - Shutting down selenium standalone server.
[16:03:44] I/launcher - 0 instance(s) of WebDriver still running
[16:03:44] I/launcher - chrome #01 failed 1 test(s)
[16:03:44] I/launcher - overall: 1 failed spec(s)
[16:03:44] E/launcher - Process exited with error code 1

Process finished with exit code 1

最佳答案

刚刚运行了快速测试并能够重现您的错误。经过一点调试,问题似乎出在 Jasmine 上(至少是 Protractor 5.1.1 附带的那个)。我能够通过安装 Mocha 来让 async-await 工作。 ,并在配置中选择它作为framework

关于javascript - 如何在 Protractor 中使用异步等待?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43845695/

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