Here we find a technical issue. The Test class creates a WebDriver instance; The Test Listener need a reference to the WebDriver instance. Then 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 set.
Issue1 : utils.listener.TestListener extends tests.BaseTest, which is unnecessary
I 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. Here is a brief introduction how to utilize @ITestContext`
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
WebDriver
which was created by the LoginTest class.Here we find a technical issue. The Test class creates a WebDriver instance; The Test Listener need a reference to the WebDriver instance. Then 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 set.
Issue1 :
utils.listener.TestListener
extendstests.BaseTest
, which is unnecessaryI think that the author possibly forgot to erase the inheritance.
Issue2 : Should use ITestContext
we should rather use TestNG
ITestContext
to share the WebDriver instance between the Test class and the TestListener. Here is a brief introduction how to utilize @ITestContext`