microsoft / microsoft/playwright-java

[Feature]: OptionsFactory that has access to test instance fields

Open
#1,881 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.6k
Forks
298
Avg merge
3d 2h
Merged PRs (30d)
14

Description

🚀 Feature Request

I'd like the ability to populate Options for use with @UsePlaywright with values that are determined by the running test, not just statically.

The OptionsFactory approach to customizing @UsePlaywright has a big gap - it can't access instance fields of the test. A non-static inner class doesn't work as it requires the outer class as a constructor argument.

Example
@UsePlaywright
@MicronautTest
class MyTest {

  @Inject
  EmbeddedServer server;

  Options getOptions() {
    return new Options().setBaseUrl(server.getUrl())
  }

  @Test
  void myTest(Page page) {
  }
}
Motivation

I'm trying to use Playwright with a fake server (Spring MockMVC, Micronaut EmbeddedServer, etc). These approaches all inject a server into an instance field of the test class, and one retrieves the base URL from that server. However, OptionsFactory is initialized outside of the test instance scope, and so can't make use of that injected server.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the @UsePlaywright OptionsFactory integration and how it is initialized relative to the test instance. Review the example with an injected EmbeddedServer and determine the lifecycle needed to access instance fields. Done means Options can use values from the running test while existing @UsePlaywright behavior remains supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.