Skip to content

Conversation

@agg23
Copy link
Collaborator

@agg23 agg23 commented Jan 21, 2025

Addresses the requested functionality of #32708 in a generic way, enabling the user to match on the native rich URL object. This enables patterns for checking for search params, hostnames, and other specific fields of the entire URL.

await expect(page).toHaveURL(url => url.searchParams.entities().has('foo'));

Care was taken to ensure rich error messages are provided. Examples:

String match failure

await expect(page).toHaveURL('wrong');
Error: Timed out 1000ms waiting for expect(page).toHaveURL(expected)

Expected string: "wrong"
Received string: "data:text/html,<div>A</div>"

Predicate failure

await expect(page).toHaveURL(_url => false);
Error: Timed out 5000ms waiting for expect(page).toHaveURL(expected)

Expected predicate to succeed
Received string: "data:text/html,<div>A</div>"

Predicate .not failure

await expect(page).not.toHaveURL(_url => true);
Error: Timed out 5000ms waiting for expect(page).not.toHaveURL(expected)

Expected predicate to fail
Received string: "data:text/html,<div>A</div>"

Invalid argument failure

await expect(page).toHaveURL({});
Error: expect(page).toHaveURL(expected)



Matcher error: expected value must be a string, regular expression, or predicate

Expected has type:  object
Expected has value: {}

@agg23 agg23 requested review from Skn0tt and pavelfeldman January 21, 2025 20:30
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

} else if (expression === 'to.have.title') {
received = this.document.title;
} else if (expression === 'to.have.url') {
received = this.document.location.href;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Side note, ports are now on their own with this)

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

Test results for "tests 1"

2 failed
❌ [webkit-library] › tests/library/browsercontext-viewport-mobile.spec.ts:206:5 › mobile viewport › view scale should reset after navigation @webkit-ubuntu-22.04-node18
❌ [webkit-library] › tests/library/video.spec.ts:441:5 › screencast › should work for popups @webkit-ubuntu-22.04-node18

20 flaky ⚠️ [firefox-page] › tests/page/page-evaluate.spec.ts:403:3 › should throw for too deep reference chain @firefox-ubuntu-22.04-node18
⚠️ [playwright-test] › tests/ui-mode-trace.spec.ts:341:5 › should work behind reverse proxy @macos-latest-node18-1
⚠️ [chromium-library] › tests/library/video.spec.ts:379:5 › screencast › should capture navigation @ubuntu-20.04-chromium-tip-of-tree
⚠️ [playwright-test] › tests/ui-mode-trace.spec.ts:341:5 › should work behind reverse proxy @ubuntu-latest-node22-1
⚠️ [webkit-library] › tests/library/browsercontext-reuse.spec.ts:50:1 › should reset serviceworker @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/browsercontext-viewport-mobile.spec.ts:87:5 › mobile viewport › should support window.orientation emulation @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/browsercontext-viewport-mobile.spec.ts:97:5 › mobile viewport › should fire orientationchange event @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/browsercontext-viewport-mobile.spec.ts:116:5 › mobile viewport › default mobile viewports to 980 width @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/browsercontext-viewport-mobile.spec.ts:157:5 › mobile viewport › mouse should work with mobile viewports and cross process navigations @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/browsercontext-viewport-mobile.spec.ts:175:5 › mobile viewport › should scroll when emulating a mobile viewport @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/defaultbrowsercontext-2.spec.ts:28:3 › should work in persistent context @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/inspector/pause.spec.ts:417:5 › pause › should highlight on explore @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/popup.spec.ts💯3 › should inherit touch support from browser context @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/popup.spec.ts:129:3 › should use viewport size from window features @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/screenshot.spec.ts:206:14 › element screenshot › element screenshot should work with a mobile viewport @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/selector-generator.spec.ts:437:5 › selector generator › should ignore empty aria-label for candidate consideration @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › tests/page/page-leaks.spec.ts:82:5 › click should not leak @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › tests/page/page-leaks.spec.ts:107:5 › fill should not leak @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › tests/page/page-leaks.spec.ts:161:5 › waitFor should not leak @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › tests/page/page-screenshot.spec.ts:868:5 › page screenshot animations › should wait for fonts to load @webkit-ubuntu-22.04-node18

37638 passed, 648 skipped
✔️✔️✔️

Merge workflow run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants