Skip to content

Detect driver lifecycle setup and teardown methods - #13

Merged
shossain786 merged 3 commits into
seleniumboot:mainfrom
PUSHPAK-JAISWAL:feat/threadlock-driver
Sep 27, 2026
Merged

shossain786 merged 3 commits into
seleniumboot:mainfrom
PUSHPAK-JAISWAL:feat/threadlock-driver

Conversation

@PUSHPAK-JAISWAL

@PUSHPAK-JAISWAL PUSHPAK-JAISWAL commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds MIG-017 to detect WebDriver construction or .quit() calls in TestNG @BeforeMethod, @AfterMethod, and @BeforeClass methods; JUnit 4 @Before and @After methods; and JUnit 5 @BeforeEach and @AfterEach methods.

Findings recommend deleting the lifecycle glue and extending BaseTest, with advice aligned to the Selenium Boot migration guide. Lifecycle methods without driver setup or teardown are ignored.

Adds TestNG, JUnit 4, and JUnit 5 fixtures and documents the rule in the README.

Validation

  • All 10 analyzer tests pass.

closes #5

@shossain786 shossain786 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @PUSHPAK-JAISWAL. The TestNG, JUnit 4 and JUnit 5 fixtures are what #5 asked for, and the checkout builds and passes. Two changes before merge.

1. Common lifecycle annotations are missing.
The set only has BeforeMethod, AfterMethod, BeforeClass, Before, After, BeforeEach and AfterEach. The most common teardown shape, @AfterClass calling driver.quit(), is not detected, and neither are @BeforeAll / @AfterAll (JUnit 5), @BeforeTest or @BeforeSuite / @AfterSuite. Please add those and a fixture for at least @AfterClass and @BeforeAll/@AfterAll.

2. The AUTO status can overpromise.
The advice says to delete the lifecycle glue. If the method also does login, navigation, cookies or data setup, deleting it loses behaviour. Please mark the finding AUTO only when every statement in the body is driver creation, driver assignment or quit. Otherwise mark it MANUAL with advice like Remove the driver setup; keep the rest. A test for a mixed method would cover this.

A nit while you are there: .quit() matches any receiver, so please limit it to a call on the driver field or local variable if that is easy.

@PUSHPAK-JAISWAL

Copy link
Copy Markdown
Contributor Author

@shossain786 ok i see the changes requested working on it

@PUSHPAK-JAISWAL

Copy link
Copy Markdown
Contributor Author

@shossain786 i have added common life cycle annotations.
AUTO now requires every top-level statement to be driver creation.
Added lifecycle fixtures and regression tests in AnalyzerTest.java and the lifecycle resources.
all the 12 test have passed.

@shossain786 shossain786 mentioned this pull request Sep 26, 2026

@shossain786 shossain786 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @PUSHPAK-JAISWAL, this covers what I asked for. The missing lifecycle annotations are added, mixed methods are now MANUAL with the "keep the rest" advice, quit is limited to the driver variable, and there are tests for each. The branch builds and the tests pass. Approved.

Nit, non-blocking: the new helper methods in Analyzer are indented inconsistently. Please fix that when you rebase.

Once #12 is merged, this PR will have a conflict in AnalyzerTest.java (the imports). Please rebase onto main and resolve it, and I'll merge right after.

@shossain786

Copy link
Copy Markdown
Contributor

@PUSHPAK-JAISWAL #12 is now merged into main, so this branch has a conflict in AnalyzerTest.java (the imports). Please rebase or merge main into your branch, resolve the conflict, run mvn test, and push again. I'll merge as soon as it's green. Thank you!

@PUSHPAK-JAISWAL

Copy link
Copy Markdown
Contributor Author

@shossain786 done you may go ahead a merge now.

@shossain786
shossain786 merged commit 8982385 into seleniumboot:main Sep 27, 2026
shossain786 added a commit that referenced this pull request Sep 27, 2026
Analyzer.java used MethodDeclaration in three places without importing it;
main failed to compile after #13 merged.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

Detect ThreadLocal driver setup in TestNG @BeforeMethod/@AfterMethod base classes

2 participants