Rayrun
← Back to Discord Forum

Error: route.fetch() unable to verify first certificate

Hello, in my tests I use route.fetch() to get the body of a response and check some conditions. All the tests using fetch() fail because of the errore in the title. I googled the error and it seems to be a certificate error but when using the platform there are no issues with certificate as the browsers do not complain. Here's a sample test:

test('should return ZARAGOZA with spain for /getStatesForRegions', async ({request, page}) => {
        test.slow();
        const promise = new Promise(async resolve => {
            await page.route('**/getStatesForRegions', async (route) => {
                const response = await route.fetch();
                const json:[] = await response.json();
                await route.continue();
                resolve(json);
            });
        });
        await page.locator('#select-country').selectOption(['Spain']);
        await page.locator('#select-region').selectOption(['ARAGON']);
        const body:any = await promise;
        expect(body).toContain('ZARAGOZA');
        expect(hasDuplicates(body)).toBeFalsy();
    });

This thread is trying to answer question "How can I resolve the 'route.fetch() unable to verify first certificate' error in my tests?"

2 replies
refactoreric

Hi, if all you need to do is intercept a response, then page.waitForResponse is a much better choice than page.route. https://playwright.dev/docs/api/class-page#page-wait-for-response

page.route is more for manipulating responses, for example to mock APIs. It is overkill to use it for mere interception.

If you do want to stick to page.route, then I don't know how to solve the certificate problem. Maybe ignoreHTTPSErrors will work: https://playwright.dev/docs/next/api/class-testoptions#test-options-ignore-https-errors

Adding ignoreHTTPSErrors seems to do the trick, thank you

Related Discord Threads

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