【问题标题】:Protractor test + manage order of execution量角器测试+管理执行顺序
【发布时间】:2019-05-27 23:16:26
【问题描述】:

我有一个量角器测试,看起来像

pageObject1.method1();
pageObject1.method2();
pageObject2.method1();
expect(pageObject2.method2());
let allDataList = pageObject2.method3();
expect(allDataList.includes('test1')).toBeTruthy();

如何确保对pageObject2.method3() 的调用发生在下一个期望调用之前? method3() 返回所有 span 元素的文本数组。

【问题讨论】:

  • 您在 method3() 中使用 async 和 await 吗?请分享method3模板
  • 方法3 getCurrDataAcsGrps(): Array<string>{ let allGroupsList = new Array(); this.currAcsGrpList.each(function(element,index){ element.getText().then(function(text) { //console.log(index, text); allGroupsList.push(text); }); }); return allGroupsList; }
  • method3 - 将所有 span 元素的值放入数组中
  • 试过 async/await 但它给出了不同的错误
  • async getCurrDataAcsGrps(): Array{ let allGroupsList = new Array(); await this.currAcsGrpList.each( async=> (element,index){ await element.getText().then(async=> (text) { //console.log(index, text); await allGroupsList.push(text) ; }); });返回所有组列表; }

标签: promise protractor


【解决方案1】:

这种情况你需要使用promises

方式一:

await pageObject1.method2();
await pageObject2.method1();
expect(pageObject2.method2());
let allDataList = await pageObject2.method3();
expect(allDataList.includes('test1')).toBeTruthy();

Description On await

方式二:

pageObject1.method2().then(function() {
    pageObject2.method1().then(function() {
        expect(pageObject2.method2());
        pageObject2.method3().then(function(allDataList) {
            expect(allDataList.includes('test1')).toBeTruthy();
        });
    });
});

【讨论】:

  • 我尝试了 Way2,但出现错误 - 类型 'string[]'.ts(2339) 上不存在属性 'then'。 Method3是这样的getCurrDataAcsGrps(): Array<string>{ let allGroupsList = new Array(); this.currAcsGrpList.each(function(element,index){ element.getText().then(function(text) { //console.log(index, text); allGroupsList.push(text); }); }); return allGroupsList; }
  • 为此,您需要从您的函数中返回承诺。默认情况下,所有量角器函数都会返回一个 Promise。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-19
  • 1970-01-01
  • 2016-08-11
  • 2018-03-25
  • 1970-01-01
相关资源
最近更新 更多