tests.LoginTest need to share an instance of WebDriver with utils.listener.TestListener; an possible alternative implementation using ITestContext#12
Open
kazurayam wants to merge 1 commit intoswtestacademy:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Thank you for your great article https://www.swtestacademy.com/extent-reports-in-selenium-with-testng/ It helped me a lot. Let me post my small pull request.
utils.listener.TestListner#onTestFailure() is designed to take a screenshot of the browser on a failure detected by the @Test-annotated method of tests.LoginTest. TestListener need to have a reference to the instance of
WebDriverwhich was created by the LoginTest class.Here is a technical issue. The Test class creates a WebDriver instance; The Test Listener need a reference to the WebDriver instance. How to share the WebDriver instance between the two?
There could be multiple design options. The original utils.listener.TestListner#onTestFailure() gets access to the WebDriver instance by the following 2 lines of code:
OK. This certainly works. However I find two issues in the original code.
Issue1 :
utils.listener.TestListenerextendstests.BaseTest, which is unnecessaryI think that the author possibly forgot to erase the inheritance.
Issue2 : Should use ITestContext
we should rather use TestNG
ITestContextto share the WebDriver instance between the Test class and the TestListener. For example, thetest.BaseTestshould sayThe following article told me of the coding gotcha.
Is there any official documentation that describes that we can write
ITestContextobject as a prameter for@BeforeXXX-annotated method? ... Yes. See the following.