NoamGaash / playwright-advanced-har

MIT License
26 stars 0 forks source link

feat: advanced matchers with post-process option #11

Closed NoamGaash closed 6 months ago

NoamGaash commented 6 months ago

apply post-proccessing on the chosen HAR entry:

test("get the largest number... squared!", async ({ page, advancedRouteFromHAR }) => {
    // the file contains 3 responses - 42, 1234, 5
    await advancedRouteFromHAR("tests/har/differentNumbers.har", {
        matcher: {
            postProcess(entry) {
                entry.response.content.text = (parseInt(entry.response.content.text || "0") ** 2).toString();
                return entry;
            },
            matchFunction: customMatcher({
                scoring: (request, entry) => parseInt(entry.response.content.text || "0"),
            }),
        }
    });
    await page.goto("https://noam-gaash.co.il");
    await page.getByText((1234**2).toString()).waitFor();
});