octaltree / playwright-rust

Playwright port to Rust
298 stars 31 forks source link

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

Closed Boscop closed 3 years ago

Boscop commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

Boscop commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

Boscop commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

Boscop commented 3 years ago

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

octaltree commented 3 years ago

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