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.
Changed @BeforeMethod to @BeforeTest and @AfterMethod to @AfterTest annotations in the Selenium TestNG test suite to ensure proper setup and teardown of the WebDriver instance.
The reason behind this change is due to TestNG annotations behavior. In TestNG, @BeforeMethod and @AfterMethod are executed before and after each @test method, respectively. As a result, the WebDriver instance was not being shared between the test methods as expected, leading to a 'null' reference error when trying to close the browser in the @AfterMethod.
By using @BeforeTest and @AfterTest annotations, the WebDriver setup is now performed before the entire test suite starts (@BeforeTest) and the teardown is done after all the tests have run (@AfterTest). This ensures the WebDriver instance is initialized once at the beginning of the test suite and closed after all the tests have completed, preventing the 'null' reference issue and ensuring a smoother execution of the test suite.
This adjustment ensures a more reliable and consistent handling of the WebDriver instance throughout the entire test suite, enhancing the stability and reliability of the test automation setup.