playwright-java icon indicating copy to clipboard operation
playwright-java copied to clipboard

Added test fixture for Browser.NewContextOptions

Open uchagani opened this issue 6 months ago • 7 comments

Resolves #1781

uchagani avatar May 07 '25 02:05 uchagani

Looks like the new tests are failing.

yury-s avatar May 07 '25 18:05 yury-s

yea i need to figure out what's going. they pass locally for me

uchagani avatar May 07 '25 18:05 uchagani

@yury-s can we re-run? looks like they're mostly failing to connect to the test server

uchagani avatar May 07 '25 18:05 uchagani

Restarted the jobs.

yury-s avatar May 07 '25 18:05 yury-s

@yury-s I'm trying to fix these tests and running into an odd issue. When the base url is set to http://localhost:9066/empty.html via

  public static class CustomOptions implements OptionsFactory {
    @Override
    public Options getOptions() {
      System.out.println("Empty Page URL: " + serverMap.get(TestFixtureContextOptions.class).EMPTY_PAGE);

      return new Options()
        .setApiRequestOptions(new APIRequest.NewContextOptions()
          .setBaseURL(serverMap.get(TestFixtureContextOptions.class).EMPTY_PAGE))
        .setContextOptions(new Browser.NewContextOptions()
          .setBaseURL(serverMap.get(TestFixtureContextOptions.class).EMPTY_PAGE));
    }
  }

and I run page.navigate("/");

I will get the error:

23:47:52 [ERROR]   TestFixtureContextOptions.testCustomBrowserContext:49 » Playwright Error {
  message='Protocol error (Page.navigate): Cannot navigate to invalid URL
  name='Error
  stack='Error: Protocol error (Page.navigate): Cannot navigate to invalid URL

Is this not supported?

uchagani avatar Jun 04 '25 03:06 uchagani

Also this only happens when I'm running all tests together.

I've verified via logging that the URL used in the options is the same as the url in the test.

Might need to do more digging. Maybe some race condition with the httpserver

uchagani avatar Jun 04 '25 13:06 uchagani

Yeah, sounds like a race condition. I'd check with DEBUG=pw:protocol to see what's being sent to the browser. My hunch is that sometimes it sends just '/' instead of the the base url.

yury-s avatar Jun 04 '25 16:06 yury-s