I have a test scenario:
test(`add to cart`, async ({ page, isMobile, baseURL, platform }) => {
test.slow(isMobile, 'Assuming slower tests on mobile');
await page.goto(new URL(greatDealsUrl[platform], baseURL).href);
const I = new POM(page);
await I.clickOnRandomProduct({});
await I.addToCart();
await I.goToCartPage();
await I.waitForPageType('cart');
await I.closeDialogIfVisible();
await I.verifyPayboxButtonVisibility();
});
I'd like to know at which stage the scenario fails so that I can notify the corresponding team. For example, if the scenario fails on the shopping cart page, I'd like to notify the team in charge of the shopping cart. I don't know how to do it, but what if it's possible?
I imagine something like this, but I don't know how to catch err.
test(`add to cart`, async ({ page, isMobile, baseURL, platform }) => {
test.slow(isMobile, 'Assuming slower tests on mobile');
await page.goto(new URL(greatDealsUrl[platform], baseURL).href);
const I = new POM(page);
await I.clickOnRandomProduct({});
try {
await I.addToCart();
await I.goToCartPage();
await I.waitForPageType('cart');
} catch (err) {
// send slack notification
}
await I.closeDialogIfVisible();
await I.verifyPayboxButtonVisibility();
});
This thread is trying to answer question "Is using a try-catch block the right approach to catch errors in different stages of a test scenario and notify the corresponding team?"
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].