playwright
playwright copied to clipboard
Response modification not working sometimes for a route using page.route and route.fulfill
System info
- Playwright Version: [v1.41]
- Operating System: [All, Windows 11, Ubuntu 20, macOS 13.2, etc.]
- Browser: [All, Chromium, Firefox, WebKit]
- Other info:
We are trying to intercept responses from a particular api and modifying its response before fulfilling it using route.fulfill method. Response modification is being done for this api endpoint in all the test cases with different response. On running the test cases we noticed that few times we are not getting the intercepted responses in few test cases, rather we are getting the non intercepted responses from the server. On checking the trace for these failed test cases we are unable to locate the entry for the intercepted route. We also tried to print the debug logs, in the logs we are able to see the
page.route startedandpage.route succeededbut not theroute.fetch startedlog which is present in other test cases logs. Since this issue is not happening everytime we are unable to provide reproducable code. Attachments Test case code:
test('should update the week start day and check in calendar @ASC-50 wednesday to monday', async ({ page, calendarPreferences }) => {
await page.goto(config.qaLive);
await page.route('**/schedule.setmore.com/api/v1/services/calendar/new**', async (route) => {
const response = await route.fetch();
console.log('Settings route interceptor');
if (route.request().method() !== 'GET') {
route.fulfill({
response,
});
return;
}
const body = await response.text();
const responseBody = JSON.parse(body);
responseBody.data.calendars[0].metaData.calendarViewMeta = 'weekly';
responseBody.data.calendars[0].viewSetting.weekStartDay = 'WEDNESDAY';
route.fulfill({
response,
body: JSON.stringify(responseBody),
});
});
await waitForCalendarLoad(page);
const firstDay = page.locator('th.fc-col-header-cell p').first();
await expect(firstDay).toHaveText('Wed');
await page.getByTestId('calendar-settings-button').click();
await page.getByTestId('calendar-settings-option').click();
await page.getByTestId('calendar-preferences-overlay').waitFor({ state: 'visible', timeout: 5000 });
await calendarPreferences.weekStartsOnValue.click();
await calendarPreferences.monday.waitFor({ state: 'visible', timeout: 50000 });
await calendarPreferences.monday.click();
await page.getByTestId('calendar-preference-close-button').click();
await page.getByTestId('calendar-preferences-overlay').waitFor({ state: 'hidden', timeout: 5000 });
await expect(firstDay).toHaveText('Mon');
// expect(locator).toBeVisible({ timeout: 10000 })
});
PW logs
pw:api => selectors.setTestIdAttribute started +9s
pw:api <= selectors.setTestIdAttribute succeeded +7ms
pw:api => browser.newContext started +8ms
pw:api navigating to "https://destinationUrl/", waiting until "load" +946ms
pw:api "commit" event fired +40ms
pw:api navigated to "https://destinationUrl/" +0ms
pw:api "domcontentloaded" event fired +1ms
pw:api "load" event fired +0ms
pw:api <= browser.newContext succeeded +31ms
pw:api => browserContext.addInitScript started +128ms
pw:api <= browserContext.addInitScript succeeded +132ms
pw:api => browserContext.addInitScript started +0ms
pw:api <= browserContext.addInitScript succeeded +83ms
pw:api => browserContext.routeFromHAR started +1ms
pw:api <= browserContext.routeFromHAR succeeded +6ms
pw:api => browserContext.newPage started +79ms
pw:api <= browserContext.newPage succeeded +705ms
pw:api => page.goto started +5ms
pw:api navigating to "https://destinationUrl/", waiting until "load" +924ms
pw:api "commit" event fired +557ms
pw:api navigated to "https://destinationUrl/" +3ms
pw:api "networkidle" event fired +2s
pw:api "domcontentloaded" event fired +7s
pw:api "load" event fired +7ms
pw:api <= page.goto succeeded +724ms
pw:api => page.route started +3ms
pw:api "networkidle" event fired +549ms
pw:api <= page.route succeeded +3s
pw:api => locator.waitFor started +11ms
pw:api waiting for locator('#calendar-container') to be visible +639ms
pw:api locator resolved to visible <div id="calendar-container" class="calendar-canvas" …>…</div> +4s
pw:api <= locator.waitFor succeeded +5s
pw:api => locator.waitFor started +1ms
pw:api waiting for locator('.asc-spinner-loader').last() to be hidden +729ms
pw:api <= locator.waitFor succeeded +1s
pw:api => expect.toHaveText started +5ms
pw:api expect.toHaveText with timeout 5000ms +29ms
pw:api waiting for locator('th.fc-col-header-cell p').first() +1ms
pw:api locator resolved to <p data-testid="day-header-staff-name-" class="avat…></p> +28ms
pw:api unexpected value "" +1ms
pw:api locator resolved to <p data-testid="day-header-staff-name-" class="avat…></p> +298ms
pw:api unexpected value "" +0ms
pw:api locator resolved to <p data-testid="day-header-staff-name-" class="avat…></p> +219ms
pw:api unexpected value "" +0ms
pw:api locator resolved to <p data-testid="day-header-staff-name-" class="avat…></p> +287ms
pw:api unexpected value "" +0ms
pw:api locator resolved to <p d
pw:api locator resolved to <p data-testid="day-header-staff-name-" class="avat…></p> +1s
pw:api unexpected value "" +3ms
pw:api locator resolved to <p data-testid="day-header-staff-name-Lynne" class=…>Lynne</p> +1s
pw:api unexpected value "Lynne" +0ms
pw:api locator resolved to <p data-testid="day-header-staff-name-Lynne" class=…>Lynne</p> +1s
pw:api unexpected value "Lynne" +0ms
pw:api <= expect.toHaveText succeeded +544ms
Error: Timed out 5000ms waiting for expect(locator).toHaveText(expected)
Locator: locator('th.fc-col-header-cell p').first()
Expected string: "Wed"
Received string: "Lynne"
Call log:
- expect.toHaveText with timeout 5000ms
- waiting for locator('th.fc-col-header-cell p').first()
- locator resolved to <p data-testid="day-header-staff-name-" class="avat…></p>
- unexpected value ""
- locator resolved to <p data-testid="day-header-staff-name-" class="avat…></p>
- unexpected value ""
- locator resolved to <p data-testid="day-header-staff-name-" class="avat…></p>
- unexpected value ""
- locator resolved to <p data-testid="day-header-staff-name-" class="avat…></p>
- unexpected value ""
- locator resolved to <p data-testid="day-header-staff-name-" class="avat…></p>
- unexpected value ""
- locator resolved to <p data-testid="day-header-staff-name-" class="avat…></p>
- unexpected value ""
- locator resolved to <p data-testid="day-header-staff-name-Lynne" class=…>Lynne</p>
- unexpected value "Lynne"
- locator resolved to <p data-testid="day-header-staff-name-Lynne" class=…>Lynne</p>
- unexpected value "Lynne"
202 | await waitForCalendarLoad(page);
203 | const firstDay = page.locator('th.fc-col-header-cell p').first();
> 204 | await expect(firstDay).toHaveText('Wed');
| ^
205 | await page.getByTestId('calendar-settings-button').click();
206 | await page.getByTestId('calendar-settings-option').click();
207 | await page.getByTestId('calendar-preferences-overlay').waitFor({ state: 'visible', timeout: 5000 });
attachment #1: trace (application/zip) ─────────────────────────────────────────────────────────
test-results/settingsSidebar-should-update-the-week-start-day-and-check-in-calendar-ASC-50-wednesday-to-monday-chromium/trace.zip
Usage:
npx playwright show-trace test-results/settingsSidebar-should-update-the-week-start-day-and-check-in-calendar-ASC-50-wednesday-to-monday-chromium/trace.zip
────────────────────────────────────────────────────────────────────────────────────────────────
It is unlikely that we are able to help without the reliable repro. Please try reproducing it and add information here, otherwise we'll close it as non-actionable.
Closing as non-actionable due to the lack of repro. Please open a new bug if you manage to create a repro we can use.