feat(expect) - add ignoreCase option for toHaveURL

This commit is contained in:
KozynchenkoVS 2024-03-31 23:18:43 +04:00
parent 7afd4170ea
commit 416a68ef9a
4 changed files with 27 additions and 2 deletions

View file

@ -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.18

View file

@ -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);
}

View file

@ -8257,6 +8257,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`.
*/

View file

@ -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', () => {