Skip to content

Upgrade to Java 21 (Selenium/TestNG test framework)#14

Open
devin-ai-integration[bot] wants to merge 8 commits into
mainfrom
migration/java-21-migration
Open

Upgrade to Java 21 (Selenium/TestNG test framework)#14
devin-ai-integration[bot] wants to merge 8 commits into
mainfrom
migration/java-21-migration

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jun 17, 2026

Copy link
Copy Markdown

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:

Changes

pom.xml:

- <maven.compiler.source>1.8</maven.compiler.source>
- <maven.compiler.target>1.8</maven.compiler.target>
+ <maven.compiler.source>21</maven.compiler.source>
+ <maven.compiler.target>21</maven.compiler.target>
- org.testng:testng        6.14.3 -> 7.10.2
- maven-surefire-plugin    2.19.1 -> 3.5.2   (old surefire predates proper JDK 21 + TestNG 7 support)

BaseTest.java — Selenium 4 deprecated API:

- driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);   // deprecated in Selenium 4
+ driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

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 @AfterSuite methods (the old wrapAllUp(ITestContext) fails at runtime with Native Injection is NOT supported for @AfterSuite; ISuite injection is rejected too). Rather than weaken semantics, the suite-level setup/summary is moved out of @BeforeSuite/@AfterSuite config methods into an ISuiteListener, registered in testng.xml (the conventional, robust place for suite listeners):

public class SuiteSummaryListener implements ISuiteListener {
    @Override public void onStart(ISuite suite) { /* log + TestProperties.loadAllPropertie() */ }
    @Override public void onFinish(ISuite suite) {
        // aggregate counts over suite.getResults() -> all <test> contexts, then MailUtil.sendMail(...)
    }
}
  // testng.xml
- <listeners></listeners>
+ <listeners>
+     <listener class-name="example.example.listeners.SuiteSummaryListener" />
+ </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.
  • GoogleSearchTest smoke (mvn -q test -Dsurefire.suiteXmlFiles=<GoogleSearchTest-only suite>) → Tests run: 1, Failures: 0, Errors: 0.
  • Full mvn test (canonical testng.xml) → suite summary onStart/onFinish each fire exactly once with Total number of testcases : 2 (confirms the ISuiteListener registration works and there's no @AfterSuite injection error).

Notes:

  • The repo has no .github CI workflows, so verification was performed locally as above.
  • A full mvn test ends in BUILD FAILURE by design: FaceBookLoginTest is an intentionally-failing demo (Assert.assertTrue(false, ...)) and was not modified.
  • GoogleSearchTest asserts 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


Open in Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Devin Review found 3 potential issues.

Open in Devin Review

@devin-ai-integration devin-ai-integration Bot Jun 17, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

📝 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).

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

Comment thread src/test/java/example/example/tests/BaseTest.java Outdated
Comment thread src/test/java/example/example/tests/BaseTest.java Outdated
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.
devin-ai-integration[bot]

This comment was marked as resolved.

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.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

Open in Devin Review

Comment thread pom.xml
<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>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🚩 Pre-existing: spurious

x

property in pom.xml

Line 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.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

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.

1 participant