Rayrun
← Back to Discord Forum

Reflection: How to catching errors ?

guillaumecamusposted in #help-playwright
Open in Discord
guillaumecamus
guillaumecamus

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?"

1 reply
guillaumecamus
guillaumecamus

In your opinion, is this the right approach? do you see a problem doing it this way? would you see it another way?

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

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].