尝试使用 lib protractor-intercept 时遇到问题:可能是 Javascript 异步问题
Trouble trying to use lib protractor-intercept : probably a Javascript async issue
我在尝试使用 lib protractor-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();
returns 的文档,但为了安全起见,我会选择 await
。然后我不会将 .then
与 await
混用。看看这是否会起作用
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();
});
我在尝试使用 lib protractor-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();
returns 的文档,但为了安全起见,我会选择 await
。然后我不会将 .then
与 await
混用。看看这是否会起作用
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();
});