Skip to content

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

@MariusVolkhart

Description

@MariusVolkhart

🚀 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 do can't make use of that injected server.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions