Skip to content
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

Equivalent of await page.waitForEvent("load"); #11

Closed
Boscop opened this issue Mar 30, 2021 · 13 comments
Closed

Equivalent of await page.waitForEvent("load"); #11

Boscop opened this issue Mar 30, 2021 · 13 comments

Comments

@Boscop
Copy link

Boscop commented Mar 30, 2021

What's the equivalent of await page.waitForEvent("load"); when using this crate? :)
So that I can call it after e.g. page.click_builder("#login-button").click().await?;.

When I try page.expect_event(EventType::Load).await?; it hangs here forever, even after the page loaded.

@octaltree
Copy link
Owner

octaltree commented Mar 30, 2021

You don't have to wait explicitly because it will wait automatically after clicking.
https://playwright.dev/docs/api/class-page#pageclickselector-options

noWaitAfter <boolean> Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. Defaults to false.

@octaltree
Copy link
Owner

expect_event timeout works even with single-threaded runtimes, but if it runs forever, let me know the environment.

@Boscop
Copy link
Author

Boscop commented Mar 30, 2021

The environment is manjaro Linux and I'm using playwright-rust with the chromium browser.
I'm using the standard Tokio main function like in your readme.
And yes, it hangs forever.
But if I don't wait after click, it gives me still the old url if I do an assert_eq of page.url() and the expected url it should have after loading finishes.
And btw, when I call expect_event I see in the browser window that the url actually changes to the expected url after the loading has finished. Just my expect_event call doesn't return.

@octaltree octaltree reopened this Mar 30, 2021
@octaltree
Copy link
Owner

playwright::api::page::Event::Load is implemented in 0.0.7.
While this test passes, many functions wait automatically, so there is no need to wait explicitly.

If it hangs, please let me know with a code.

@Boscop
Copy link
Author

Boscop commented Apr 6, 2021

Now I'm getting:

Error: Arc(ErrorResponded(ErrorMessage { name: "Error", message: "net::ERR_CERT_AUTHORITY_INVALID

Even though I'm using .ignore_https_errors(true).
Any idea why? :)

@octaltree
Copy link
Owner

Sorry, I forgot ignoreHTTPSErrors isn't a camelCase. 0.0.8 is ready.

@Boscop
Copy link
Author

Boscop commented Apr 6, 2021

Thanks for the quick fix.
But now my program returns with Error: Arc(ReceiverClosed):

#[tokio::main]
async fn main() -> Result<(), playwright::Error> {
    let playwright = Playwright::initialize().await?;
    playwright.prepare()?;
    let chromium = playwright.chromium();
    let browser = chromium
        .launcher()
        .headless(false)
        .launch()
        .await?;
    let context = browser
        .context_builder()
        .ignore_https_errors(true)
        .build()
        .await?;
    let page = context.new_page().await?;
    page.goto_builder(LOGIN_URL).goto().await?; // here

    Ok(())
}

@octaltree
Copy link
Owner

When I tried to reproduce the error, it was caused by parsing consolemessage, which was released at the same time. 0.0.9, how about this?

@Boscop
Copy link
Author

Boscop commented Apr 8, 2021

Thanks for the quick fix. But now, at the same source line, it returns this error:

Error: Arc(Serde(Error("invalid type: map, expected a string", line: 0, column: 0)))

Any idea why?

@octaltree
Copy link
Owner

I tried it on a page with NET::ERR_CERT_AUTHORITY_INVALID, but unfortunately it did not reproduce.

If you use env_logger and give me the output of RUST_LOG=trace cargo run, I might be able to figure it out. Just don't forget to cut off the credential information.

@Boscop
Copy link
Author

Boscop commented Apr 20, 2021

Thanks, it works now (with v0.0.14).

@Boscop
Copy link
Author

Boscop commented Apr 28, 2021

@octaltree Btw, is there a way to get the HTTP response from the latest request that was made?

@octaltree
Copy link
Owner

Would page::EventType::Request and Request::response help, I haven't written any tests for them yet.

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

No branches or pull requests

2 participants