admin管理员组文章数量:1024091
(node:13276) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict
(see .html#cli_unhandled_rejections_mode). (rejection id: 2)
Hi guys, I am getting the warning above from the title after I am calling this function 2 times:
async function delete_page(page, page_id) {
await page.goto('http://127.0.0.1:3000/page/' + page_id,
{ waitUntil: 'domcontentloaded' });
const navPromise = page.waitForNavigation();
page.on('dialog', async function(dialog) {
await dialog.accept();
});
await page.click("#delete-page-button");
await navPromise;
}
I am calling the function delete_page() here:
after(async function() {
this.timeout(0);
await logout(page);
await login(page, 'AdminTester', 'password');
await delete_page(page, 'test');
await delete_page(page, 'test2');
await logout(page);
await page.close();
});
How can I get rid of this warning? Thanks!
(node:13276) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict
(see https://nodejs/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
Hi guys, I am getting the warning above from the title after I am calling this function 2 times:
async function delete_page(page, page_id) {
await page.goto('http://127.0.0.1:3000/page/' + page_id,
{ waitUntil: 'domcontentloaded' });
const navPromise = page.waitForNavigation();
page.on('dialog', async function(dialog) {
await dialog.accept();
});
await page.click("#delete-page-button");
await navPromise;
}
I am calling the function delete_page() here:
after(async function() {
this.timeout(0);
await logout(page);
await login(page, 'AdminTester', 'password');
await delete_page(page, 'test');
await delete_page(page, 'test2');
await logout(page);
await page.close();
});
How can I get rid of this warning? Thanks!
Share Improve this question edited Feb 13, 2020 at 17:38 webprogrammer 2,4773 gold badges22 silver badges27 bronze badges asked Feb 13, 2020 at 17:13 Samoila AndreiSamoila Andrei 3482 silver badges15 bronze badges2 Answers
Reset to default 3The error is saying that you can't do this twice.
await dialog.accept();
You are doing that twice because you are registering a new event every time you call delete_page
.
You could solve that doing this inside your after
function instead of inside delete_page
.
page.on('dialog', async function(dialog) {
await dialog.accept();
});
You could also use the once
function which will be called only ... once. But you need to be sure that you are going to get a dialog on every call, so you don't get more than one registration.
page.once('dialog', async function(dialog) {
await dialog.accept();
});
using page.once resolved my issue. Page.once will create dialog listener only for once. In this case each time you have to handle a dialog, you have to create dialog listener with page.once.
page.once('dialog', async (dialog) => {
expect(dialog.message()).toEqual('to what day?');
expect(dialog.type()).toEqual("prompt");
await page.waitForTimeout(3000);
await dialog.accept("5");
})
(node:13276) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict
(see .html#cli_unhandled_rejections_mode). (rejection id: 2)
Hi guys, I am getting the warning above from the title after I am calling this function 2 times:
async function delete_page(page, page_id) {
await page.goto('http://127.0.0.1:3000/page/' + page_id,
{ waitUntil: 'domcontentloaded' });
const navPromise = page.waitForNavigation();
page.on('dialog', async function(dialog) {
await dialog.accept();
});
await page.click("#delete-page-button");
await navPromise;
}
I am calling the function delete_page() here:
after(async function() {
this.timeout(0);
await logout(page);
await login(page, 'AdminTester', 'password');
await delete_page(page, 'test');
await delete_page(page, 'test2');
await logout(page);
await page.close();
});
How can I get rid of this warning? Thanks!
(node:13276) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict
(see https://nodejs/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
Hi guys, I am getting the warning above from the title after I am calling this function 2 times:
async function delete_page(page, page_id) {
await page.goto('http://127.0.0.1:3000/page/' + page_id,
{ waitUntil: 'domcontentloaded' });
const navPromise = page.waitForNavigation();
page.on('dialog', async function(dialog) {
await dialog.accept();
});
await page.click("#delete-page-button");
await navPromise;
}
I am calling the function delete_page() here:
after(async function() {
this.timeout(0);
await logout(page);
await login(page, 'AdminTester', 'password');
await delete_page(page, 'test');
await delete_page(page, 'test2');
await logout(page);
await page.close();
});
How can I get rid of this warning? Thanks!
Share Improve this question edited Feb 13, 2020 at 17:38 webprogrammer 2,4773 gold badges22 silver badges27 bronze badges asked Feb 13, 2020 at 17:13 Samoila AndreiSamoila Andrei 3482 silver badges15 bronze badges2 Answers
Reset to default 3The error is saying that you can't do this twice.
await dialog.accept();
You are doing that twice because you are registering a new event every time you call delete_page
.
You could solve that doing this inside your after
function instead of inside delete_page
.
page.on('dialog', async function(dialog) {
await dialog.accept();
});
You could also use the once
function which will be called only ... once. But you need to be sure that you are going to get a dialog on every call, so you don't get more than one registration.
page.once('dialog', async function(dialog) {
await dialog.accept();
});
using page.once resolved my issue. Page.once will create dialog listener only for once. In this case each time you have to handle a dialog, you have to create dialog listener with page.once.
page.once('dialog', async (dialog) => {
expect(dialog.message()).toEqual('to what day?');
expect(dialog.type()).toEqual("prompt");
await page.waitForTimeout(3000);
await dialog.accept("5");
})
本文标签:
版权声明:本文标题:javascript - (node:13276) UnhandledPromiseRejectionWarning: Error: Cannot accept dialog which is already handled - Stack Overflo 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745520162a2154278.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论