Skip to content

feat(junit): allow OptionsFactory to access test instance fields - #2008

Open
Yury Semikhatsky (yury-s) wants to merge 2 commits into
microsoft:mainfrom
yury-s:fix-1881
Open

Yury Semikhatsky (yury-s) wants to merge 2 commits into
microsoft:mainfrom
yury-s:fix-1881

Conversation

@yury-s

Copy link
Copy Markdown
Member

Summary

  • OptionsFactory passed to @UsePlaywright can now be a non-static inner class of the test class, so options can depend on instance fields (e.g. a server injected by Spring/Micronaut).
  • Options are re-created for each test instance; Playwright and Browser are still created once from the first instance's options.

Fixes #1881

Comment on lines +80 to +81
Constructor<? extends OptionsFactory> constructor = factoryClass.getDeclaredConstructor(factoryClass.getDeclaringClass());
constructor.setAccessible(true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we need to use extensionContext.getExecutableInvoker().invoke(constructor, enclosingInstance) instead so JUnit creates the factory with its existing access as otherwise this would fail in named modules that open the test package to JUnit but not Playwright

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

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

2 participants