Upgrade to Java 21 (Selenium/TestNG test framework)#14
Upgrade to Java 21 (Selenium/TestNG test framework)#14devin-ai-integration[bot] wants to merge 8 commits into
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
📝 Info: Pre-existing: driver.close() followed by driver.quit() can throw
The wrapUp() method calls driver.close() then driver.quit(). When there is only one browser window (the typical case here), close() closes the last window and may invalidate the session, causing quit() to throw a NoSuchSessionException. This is a pre-existing issue not introduced by this PR, but worth noting since the PR touches this class. The fix would be to just call driver.quit() (which closes all windows and ends the session).
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Agreed this is pre-existing (wrapUp() is unchanged by this PR) and, as you note, not a regression. Since this PR's scope is strictly the Java 21 / TestNG 7 / Selenium 4 upgrade and the teardown isn't causing failures in the current suite, I'm intentionally leaving it as-is to keep the upgrade diff minimal. Happy to file a follow-up to simplify it to a single driver.quit() if you'd like.
TestNG 7 rejects native parameter injection into @AfterSuite (ISuite/ITestContext), and the prior @AfterTest workaround ran per-<test> rather than once per suite. Move globalSetup/wrapAllUp into a SuiteSummaryListener (ISuiteListener) registered via @listeners, aggregating results across all <test> contexts so the summary runs exactly once per suite.
Suite-level listeners are more robustly registered in the testng.xml <listeners> block than via @listeners on a test class. Move SuiteSummaryListener there so its onStart/onFinish reliably fire once per suite.
| <maven.compiler.target>1.8</maven.compiler.target> | ||
| <maven.compiler.source>21</maven.compiler.source> | ||
| <maven.compiler.target>21</maven.compiler.target> | ||
| <p>x</p> |
There was a problem hiding this comment.
🚩 Pre-existing: spurious
x
property in pom.xmlLine 18 contains <p>x</p> inside the <properties> block. This defines a Maven property named p with value x. It's likely a leftover from debugging or testing. While it doesn't break the build, it's noise in the POM. This is pre-existing and unchanged by this PR.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Agreed it's harmless leftover noise (defines an unused Maven property p=x) and, as you note, pre-existing and unchanged by this PR. Keeping this PR's diff scoped to the Java 21 / TestNG 7 / Selenium 4 upgrade, so I'm leaving it as-is here. Happy to remove it in a small follow-up cleanup if you'd like it gone.
Summary
Upgrades this Selenium WebDriver + TestNG Maven test framework from Java 1.8 to Java 21. It is a plain Java test project (no Spring / no app server), so there is no framework "big-bang" phase — the work is the Java toolchain bump plus the test-framework bumps that Java 21 requires.
This is the integration PR for
migration/java-21-migration, assembled from three task PRs that each targeted the integration branch:1.8→21,maven-surefire-plugin2.19.1→3.5.2org.testng:testng6.14.3→7.10.2(+ required test-lifecycle change, below)implicitlyWait)Changes
pom.xml:BaseTest.java— Selenium 4 deprecated API:Suite-level lifecycle (required by the TestNG 7 bump) — new
SuiteSummaryListener.java,BaseTest.java,testng.xml. TestNG 7 no longer allows native parameter injection into@AfterSuitemethods (the oldwrapAllUp(ITestContext)fails at runtime withNative Injection is NOT supported for @AfterSuite;ISuiteinjection is rejected too). Rather than weaken semantics, the suite-level setup/summary is moved out of@BeforeSuite/@AfterSuiteconfig methods into anISuiteListener, registered intestng.xml(the conventional, robust place for suite listeners):// BaseTest.java — @BeforeSuite globalSetup + @AfterSuite wrapAllUp removed; @Listeners unchanged @Listeners({ ReportListener.class, LogListener.class }) public class BaseTest { ... }This runs exactly once per suite and aggregates across all
<test>contexts (behavior-preserving for the current single-<test>suite, and correct if more<test>tags are added later).Out of scope
EOL libraries (
log4j 1.2.17,com.relevantcodes:extentreports 2.41.2,simple-java-mail 5.1.1/javax.mail) compile and run fine on Java 21, so they were intentionally left untouched to avoid risky rewrites that the Java 21 upgrade does not require.Verification
Run under JDK 21 (
JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64):mvn -q clean test-compile→ BUILD SUCCESS.GoogleSearchTestsmoke (mvn -q test -Dsurefire.suiteXmlFiles=<GoogleSearchTest-only suite>) →Tests run: 1, Failures: 0, Errors: 0.mvn test(canonicaltestng.xml) → suite summaryonStart/onFinisheach fire exactly once withTotal number of testcases : 2(confirms theISuiteListenerregistration works and there's no@AfterSuiteinjection error).Notes:
.githubCI workflows, so verification was performed locally as above.mvn testends in BUILD FAILURE by design:FaceBookLoginTestis an intentionally-failing demo (Assert.assertTrue(false, ...)) and was not modified.GoogleSearchTestasserts the live Google page title contains the search term and is occasionally flaky in headless runs; it passes on a clean run. This flakiness is in the test's own logic and is unrelated to the version upgrade.Link to Devin session: https://partner-workshops.devinenterprise.com/sessions/de8df3da522046418cb1fc8638c70992
Requested by: @mbatchelor81