Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(expect) - add ignoreCase option for toHaveURL (#30192)
Козынченко Вячеславe58a33a0ae27
diff --git a/docs/src/api/class-pageassertions.md b/docs/src/api/class-pageassertions.mdindex 75a3ec5e80..17c217503e 100644--- a/docs/src/api/class-pageassertions.md+++ b/docs/src/api/class-pageassertions.md@@ -116,6 +116,13 @@ The opposite of [`method: PageAssertions.toHaveURL`].Expected URL string or RegExp.+### option: PageAssertions.NotToHaveURL.ignoreCase+* since: v1.44+* langs: js+- `ignoreCase` <[boolean]>++Whether to perform case-insensitive match. [`option: ignoreCase`] option takes precedence over the corresponding regular expression flag if specified.+### option: PageAssertions.NotToHaveURL.timeout = %%-csharp-java-python-assertions-timeout-%%* since: v1.18@@ -325,6 +332,13 @@ await Expect(Page).ToHaveURL(new Regex(".*checkout"));Expected URL string or RegExp.+### option: PageAssertions.toHaveURL.ignoreCase+* since: v1.44+* langs: js+- `ignoreCase` <[boolean]>++Whether to perform case-insensitive match. [`option: ignoreCase`] option takes precedence over the corresponding regular expression flag if specified.+### option: PageAssertions.toHaveURL.timeout = %%-js-assertions-timeout-%%* since: v1.18diff --git a/packages/playwright/src/matchers/matchers.ts b/packages/playwright/src/matchers/matchers.tsindex c7a5ebde7a..1e3bdf9a45 100644--- a/packages/playwright/src/matchers/matchers.ts+++ b/packages/playwright/src/matchers/matchers.ts@@ -326,13 +326,13 @@ export function toHaveURL(this: ExpectMatcherContext,page: Page,expected: string | RegExp,- options?: { timeout?: number },+ options?: { ignoreCase?: boolean, timeout?: number },) {const baseURL = (page.context() as any)._options.baseURL;expected = typeof expected === 'string' ? constructURLBasedOnBaseURL(baseURL, expected) : expected;const locator = page.locator(':root') as LocatorEx;return toMatchText.call(this, 'toHaveURL', locator, 'Locator', async (isNot, timeout) => {- const expectedText = toExpectedTextValues([expected]);+ const expectedText = toExpectedTextValues([expected], { ignoreCase: options?.ignoreCase });return await locator._expect('to.have.url', { expectedText, isNot, timeout });}, expected, options);}diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.tsindex 5d9911f07c..d4662d4498 100644--- a/packages/playwright/types/test.d.ts+++ b/packages/playwright/types/test.d.ts@@ -7210,6 +7210,12 @@ interface PageAssertions {* @param options*/toHaveURL(urlOrRegExp: string|RegExp, options?: {+ /**+ * Whether to perform case-insensitive match. `ignoreCase` option takes precedence over the corresponding regular+ * expression flag if specified.+ */+ ignoreCase?: boolean;+/*** Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.*/diff --git a/tests/page/expect-misc.spec.ts b/tests/page/expect-misc.spec.tsindex 91f4178735..3d09341468 100644--- a/tests/page/expect-misc.spec.ts+++ b/tests/page/expect-misc.spec.ts@@ -245,6 +245,11 @@ test.describe('toHaveURL', () => {const error = await expect(page).toHaveURL('wrong', { timeout: 1000 }).catch(e => e);expect(error.message).toContain('expect.toHaveURL with timeout 1000ms');});++ test('support ignoreCase', async ({ page }) => {+ await page.goto('data:text/html,<div>A</div>');+ await expect(page).toHaveURL('DATA:teXT/HTml,<div>a</div>', { ignoreCase: true });+ });});test.describe('toHaveAttribute', () => {