Reputation: 434
Scenario:
After Click on submit button a post navigation occurs, and 3 situations can happen:
This is my code
await Promise.all([
page.waitForNavigation({waitUntil: "networkidle0"}),
page.click(BUTTON_SIGN)
]
).then (ok => {
if(page.$("img-ok") != null) {
//Case 1
} else {
//Case 2
}
}).catch (err => {
//case 3
})
When 3) happens, process does not goes through catch, instead it ends with default timeout.
How can I make it go through catch? Should I follow a different approach?
Upvotes: 0
Views: 911
Reputation: 13792
I think this doc note for page.goto()
may also be valid for page.waitForNavigation()
:
page.goto
will not throw an error when any valid HTTP status code is returned by the remote server, including 404 "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by callingresponse.status()
.
So maybe try something like this:
const [response] = await Promise.all([
page.waitForNavigation({waitUntil: "networkidle0"}),
page.click(BUTTON_SIGN)
]);
if (response.status() === 500) {
//Case 3
} else if(page.$("img-ok") != null) {
//Case 1
} else {
//Case 2
}
Upvotes: 1