Skip to content

Add waitForURL in frame and page #4920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Add waitForURL in frame and page #4920

wants to merge 6 commits into from

Conversation

ankur22
Copy link
Contributor

@ankur22 ankur22 commented Jul 10, 2025

What?

This adds support for a asked for API from Playwright -- page.waitForURL. This API does a few things more than the equivalent page.waitForNavigation({ url: ... }):

  1. It will compare the current page's URL to see if it matches the input url;
  2. If there's a match it will then wait for the load state of the navigation;
  3. Otherwise it will use page.waitForNavigation({ url: ... }).

Why?

This is a more robust API than page.waitForNavigation when a user wants to wait for a specific URL, since it builds on page.waitForNavigation to prevent race conditions where a page completes navigation before page.waitForNavigation is setup.

It's just another convenient way of waiting for something specific when a navigation occurs, which is especially important when many redirects occur.

Note: It's still recommended that the user wait for specific elements or just work with the locator API which auto waits when the page does navigate to the specified URL.

Example usage:

  await Promise.all([
    page.waitForURL('https://quickpizza.grafana.com/login'),
    page.locator('a[href="Login/Profile"]').click()
  ]);

Checklist

  • I have performed a self-review of my code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests for my changes.
  • I have run linter and tests locally (make check) and all pass.

Checklist: Documentation (only for k6 maintainers and if relevant)

Please do not merge this PR until the following items are filled out.

  • I have added the correct milestone and labels to the PR.
  • I have updated the release notes: link
  • I have updated or added an issue to the k6-documentation: grafana/k6-docs#NUMBER if applicable
  • I have updated or added an issue to the TypeScript definitions: grafana/k6-DefinitelyTyped#NUMBER if applicable

Related PR(s)/Issue(s)

#4385

@ankur22 ankur22 added this to the v1.2.0 milestone Jul 10, 2025
@ankur22 ankur22 changed the base branch from master to add/url_waitForNavigation July 10, 2025 22:24
@ankur22 ankur22 force-pushed the add/url_waitForNavigation branch from 8b84803 to 2af3f2c Compare July 10, 2025 22:44
@ankur22 ankur22 force-pushed the add/url_waitForNavigation branch from 0e59b82 to a05d7b7 Compare July 15, 2025 09:11
@ankur22 ankur22 force-pushed the add/waitForUrl branch 2 times, most recently from 82d6e92 to e651203 Compare July 15, 2025 09:19
@ankur22 ankur22 force-pushed the add/url_waitForNavigation branch 2 times, most recently from 17a3e84 to 8639485 Compare July 15, 2025 15:49
@ankur22 ankur22 force-pushed the add/waitForUrl branch 3 times, most recently from 2a7395a to afdd0d8 Compare July 15, 2025 16:07
@ankur22 ankur22 force-pushed the add/url_waitForNavigation branch 2 times, most recently from 6614b61 to 0c0050c Compare July 15, 2025 16:21
@ankur22 ankur22 force-pushed the add/url_waitForNavigation branch 3 times, most recently from ff4ae78 to daa30bb Compare July 16, 2025 15:28
Base automatically changed from add/url_waitForNavigation to master July 18, 2025 10:40
Comment on lines +432 to +438
var val string
switch url.ExportType() {
case reflect.TypeOf(string("")):
val = fmt.Sprintf("'%s'", url.String()) // Strings require quotes
default: // JS Regex, CSS, numbers or booleans
val = url.String() // No quotes
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will refactor this into a helper method once this PR is merged in. There are several other PRs which work with similar/same logic to differentiate between regex and strings.

@ankur22 ankur22 marked this pull request as ready for review July 18, 2025 10:55
@ankur22 ankur22 requested a review from a team as a code owner July 18, 2025 10:55
@ankur22 ankur22 requested review from codebien and AgnesToulet and removed request for a team July 18, 2025 10:55
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.

1 participant