【问题标题】:Giving error on using async/await in jasmine-protractor functions在 jasmine-protractor 函数中使用 async/await 时出错
【发布时间】:2019-09-15 01:02:58
【问题描述】:

我正在使用 protractor-jasmine 在我的 Angular 网站上进行 e2e 测试。在使用异步函数并等待其余代码返回承诺时,Jasmine-protractor 会出错。

我什至包括:SELENIUM_PROMISE_MANAGER: false,

it('Sub-folder: Manage permission, Edit Folder name, Create Template, View Template', async ()=> {
await obj.getURL();
obj.TealoginUname.sendKeys(data.uname);
obj.TealoginPass.sendKeys(data.pass);
await obj.TealoginButton.click();
await browser.sleep(2000);
})

控制台错误:

Error: Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined.  This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping.  See http://git.io/v4gXM for details"

在 Eclipse 中,在写入 async/await 的那些行上显示错误。

我正在为动态元素使用页面对象模型。 var obj= require("./somefile.js");

somefile.js:-

function  globalVariables()
{
this.TealoginUname= element(by.model("vm.login.userid"));
this.TealoginPass= element(by.model("vm.login.password"));
this.TealoginButton= element(by.xpath("//*[@id='login-form']/form[1]/button"));

}

【问题讨论】:

  • obj 应该是什么?
  • 我正在使用 Page 对象模型来处理动态数据和元素。我已经更新了我的问题以包含它。

标签: angular eclipse async-await jasmine protractor


【解决方案1】:

在不导入定位器的情况下将其添加到您的测试文件中

const TealoginUname= element(by.model("vm.login.userid"));
const TealoginPass= element(by.model("vm.login.password"));
const TealoginButton= element(by.xpath("//*[@id='login-form']/form[1]/button"));

试试下面这个

it('Sub-folder: Manage permission, Edit Folder name, Create Template, View Template', async ()=> {
await broswer.get('add your url here');
await browser.waitForAngularEnabled(true); // To make protractor wait for all the http request to get compelted
await TealoginUname.sendKeys(data.uname);
await TealoginPass.sendKeys(data.pass);
await TealoginButton.click();
await browser.sleep(2000);
})

【讨论】:

  • 还是同样的错误。我尝试使用“const”更新代码。
  • 分享你的实现。尝试var 而不是const
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-31
  • 1970-01-01
  • 2020-08-13
  • 1970-01-01
  • 1970-01-01
  • 2018-01-06
相关资源
最近更新 更多