[testng] implement as a test listener instead of requiring inheritance #331
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
One-line summary
implement as a test listener instead of requiring inheritance
Description
This is
the same assimilar to what we did for JUnit 4 & JUnit 5; unlike the others I couldn't make the startup happen automatically before the test's before hook (@BeforeMethod
) executes. So, you have to explicitly tell the listener class to start things, and because the values are stored in the test context you have to explicitly pull them out to use them.Update: Turns out Context was not completely Thread Safe, so I had to re-re do it the way JUnit 5 was redone storing sessions as a unique key in the context. Created a separate SessionContext to manage everything since we can't use a constructor for the Listener and it stopped making sense to put all the unrelated things into that listener class.
Reasoning:
We need to make it easier for people to add this into their existing code
That means we don't want to force a specific inheritance on the user
Using a Listener instead of a SuperClass should make this more extensible/compatible
Types of Changes
Considerations
This should be easier to work with, but TestNG gets complicated quickly with XML files and ThreadLocals
The implementation here is using TestContext to store the session and driver variables to get around Threading limitations
I even added a parameterized example as proof of concept.
Ideally this is included as part of Sauce Bindings 2.0
I need to make sure toggling local/remote works