Skip to content

[WIP] customizable test template display names #591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

gtaylor-exactsciences
Copy link
Contributor

Purpose of changes

The current Test Template generates JUnit test cases with names similar to "[Browser [type=chrome, version=latest]]". This is often just fine in an IDE where there is context about the test method that was executed, but when uploading the xml test results to other consumers it becomes difficult to tell the different test cases apart. This could be improved by including the test method name in the generated JUnit test case name. It would be even nicer to allow the developer to customize the display names for their own needs (similar to a JUnit @ParameterizedTest).

This is one possible implementation for #590 that prioritizes backwards compatibility by only offering the updated display names if developers opt-in with the @BrowserScenarioTest annotation. Existing @TestTemplate tests will behave identically.

Types of changes

  • Bug-fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How has this been tested?

I've included unit tests for the BrowserScenarioTest.NameFormatter class methods and validated the new @BrowserScenarioTest annotations produce the expected JUnit test case names on a separate project.

@gtaylor-exactsciences
Copy link
Contributor Author

@bonigarcia, this is my first time contributing to this project and am very happy to take feedback on your preferred ways of working. Please let me know if there is a more appropriate way to submit this feature request / implementation proposal. Thank you for this library, it is very useful!

@bonigarcia
Copy link
Owner

@gtaylor-exactsciences Thanks again for contributing. The code seems good but there is a problem somewhere since the new template test is not working. The error we have is the following:

Error:  Tests run: 8, Failures: 0, Errors: 4, Skipped: 0, Time elapsed: 44.05 s <<< FAILURE! -- in io.github.bonigarcia.seljup.test.template.TemplateTest
Error:  io.github.bonigarcia.seljup.test.template.TemplateTest.namePatternTest(WebDriver)[1] -- Time elapsed: 0.003 s <<< ERROR!
org.junit.jupiter.api.extension.ParameterResolutionException: Discovered multiple competing ParameterResolvers for parameter [org.openqa.selenium.WebDriver arg0] in method [void io.github.bonigarcia.seljup.test.template.TemplateTest.namePatternTest(org.openqa.selenium.WebDriver)]: io.github.bonigarcia.seljup.SeleniumJupiter@365af87d, io.github.bonigarcia.seljup.SeleniumJupiter$1$1@78072f48
	at java.base/java.util.Optional.ifPresent(Optional.java:178)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Can you please take a look?

…upportsParameter to prevent ParameterResolutionException with competing TestTemplate ParameterResolver
@gtaylor-exactsciences
Copy link
Contributor Author

ParameterResolutionException

@bonigarcia thank you for pointing that out! The SeleniumJupiter and TestTemplate ParameterResolvers were competing because isTestTemplate checked for an immediately present TestTemplate annotation but did not check for a meta-present annotation (where the BrowserScenarioTest annotation is itself annotated with TestTemplate). I've resolved the issue using the JUnit AnnotationSupport::isAnnotated utility to check for both cases.

@bonigarcia bonigarcia merged commit 3b98163 into bonigarcia:master Apr 21, 2025
2 checks passed
@bonigarcia
Copy link
Owner

Many thanks for contributing, @gtaylor-exactsciences! I am going to release a new version of Selenium-Jupiter by today.

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.

2 participants