playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[BUG] Escaping ? in glob pattern does not work

Open Exoow opened this issue 1 year ago • 0 comments

System info

  • Playwright Version: [v1.33.2]
  • Operating System: Windows 10
  • Browser: Chromium

Source code

Run the below code on https://try.playwright.tech/ The test will fail but it should pass.

import { test, expect } from '@playwright/test';

test('basic test', async ({ page }) => {
  await page.goto('https://playwright.dev/');
  // Set up the route stub
  await page.route('**/task*', (route) => {
    route.fulfill({
      status: 200,
      contentType: 'application/json',
      body: JSON.stringify({ message: 'YES' }),
    });
  });

  // Set up the route stub that matches query params only
  //  (escaping \? should match a literal question mark)
  // This stub should not be triggered when calling the route below
  // as the route called has no question mark
  await page.route('**/task\?*', (route) => {
    route.fulfill({
      status: 200,
      contentType: 'application/json',
      body: JSON.stringify({ message: 'NO' }),
    });
  });

  await page.evaluate(() => {
    fetch('https://api.example.com/task/test');
  });

  const response = await page.waitForResponse(/.+task.*/);
  const responseBody = await response.json();
  expect(responseBody.message).toEqual('YES')
});

Exoow avatar May 26 '23 11:05 Exoow