尝试使用lib量角器拦截时遇到问题:可能是Javascript异步问题



我在尝试使用libprotractor-intercept时遇到问题,我认为这可能是我遇到的Javascript异步问题。此代码有效,但不会打印出console.log行。你知道我怎么会错的吗?

When('the {string} button is clicked', async (buttonName: string) => {
var intercept = new Intercept(browser);
intercept.addListener();
await page.submitApplication(buttonName);
intercept.getRequests().then(function(reqs) {
console.log("Intercepted!! " + reqs);
//TODO extract a value from submit http query response
});
await page.waitForSpinnerButtonFinish();
});

这是我的页面对象方法:

submitApplication(buttonName: string) {
return new Promise(function (resolve) {
var promised = element(by.css('app form')).element(
by.cssContainingText('button span', buttonName)).click();
return resolve(promised);
});
}

我没有找到intercept.addListener();返回的文档,但为了安全起见,我选择了await。然后我就不会把.thenawait混在一起了。看看这是否能完成的工作

submitApplication(buttonName: string) {
return element(by.css('app form'))
.element(by.cssContainingText('button span', buttonName))
.click();
});
}
When('the {string} button is clicked', async (buttonName: string) => {
var intercept = new Intercept(browser);
await intercept.addListener();
await page.submitApplication(buttonName);
let reqs = await intercept.getRequests()
console.log("Intercepted!! " + reqs);
await page.waitForSpinnerButtonFinish();
});

相关内容

  • 没有找到相关文章

最新更新