Is Selenium, Appium code preventing TestNG from running the test methods?

TestNG is like a blackbox. BUILD SUCCESS But no Tests were picked up to run. All the TestNG annotations were ignored. Sounds like TestNG problem, right ??
Probably not !
When I removed the Selenium, Appium code and leave just the empty methods and TestNG annotations, the tests are picked up just as we expected and run just fine!!
This is strange ! And makes me think that

> Selenium, Appium code preventing TestNG from running the test methods
Obviously, this could not be real.
Please help with your suggestions.

Here are the details…
I made sure and checked that

  1. My test class has no main method
  2. My test method has public qualifier
  3. My test method has no return parameter.
  4. Test annotation is from TestNG framework, not JUnit.
  5. test tag in xml config file has enabled=“true”
  6. Using TestNG version 7.11.0
  7. Whenever I try to give a wrong Java file path, TestNG complains that it is
    not able to find it, meaning currently, it is having classpath correctly specified.

My software components are:

Operating system: Mac Sequoia 15.3.1

Appium server version: 2.15.0

Appium driver(s) and their version(s): [email protected]

Appium plugin(s) and their version(s): No plugins activated

Node.js version: v20.16.0

npm version: 10.8.1

Platform and version under test: iOS 18.3.1

Real device: Apple iPhone 11

JDK: 11.0.26

appium-java-client: 9.4.0

selenium-java client: 4.28.0

TestNG: 7.11.0

Here is the skeletal outline of my script.

package com.zq.mobile.browser.agent;
import org.testng.annotations.Test;
public class StockQuoteCreation extends Util {
@Parameters({"platform","browser","device","udid"})
@BeforeClass //>>-->TestNG annotation
public void setUp( String platform,String browser,String device,String udid) {
super.setUp(platform, browser, device, udid);
}
* @Test //>>-->TestNG annotation
public void quoteCreationAndApprovalValidations() {
createStockQuoteInfoStep();// <----
addCustomer();// <----
}
* private void createStockQuoteInfoStep(){// <----
// Create Quote menu....
}
* private void addCustomer() {// <----
// 'Add Customers'...
}
* @AfterClass //>>-->TestNG annotation
public void tearDown(){
//.....
}
}

Here is the outline of my suite configuration xml file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="zCommerce_Test_Suite" preserve-order="true" parallel="none" thread-count="1">
   
 <test name="StockQuoteCreation_RealLocalDeviceAndroidTesting" enabled="true">
  <classes>
  <class name="com.zq.mobile.browser.agent.StockQuoteCreation">
           <parameter name="platform" value="Android"/>
           <parameter name="browser" value="Chrome"/>
           <parameter name="device" value="Galaxy S21 FE 5G"/>
           <parameter name="udid" value="R5CW71PYTHE"/>
           <parameter name="platformVersion" value="14"/>
   </class> 
   </classes> 
 </test>
</suite>

Here is my run time console output
e[1m--- e[0;32msurefire:3.5.2:teste[m e[1m(default-test)e[m @ e[36mZklmn-zCommerceQAe[0;1m ---e[m [INFO] Using auto detected provider org.apache.maven.surefire.testng.TestNGProvider [INFO] [INFO] ------------------------------------------------------- [INFO] T E S T S [INFO] ------------------------------------------------------- [INFO] Running e[1mTestSuitee[m [INFO] e[1mTests run: e[0;1m0e[m, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.472 s -- in e[1mTestSuitee[m [INFO] [INFO] Results: [INFO] [INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] e[1m------------------------------------------------------------------------e[m [INFO] e[1;32mBUILD SUCCESSe[m [INFO] e[1m------------------------------------------------------------------------e[m [INFO] Total time: 1.805 s [INFO] Finished at: 2025-03-01T20:40:26-06:00 [INFO] e[1m------------------------------------------------------------------------e[m

1 try add (alwaysRun = true)

@Parameters({"platform","browser","device","udid"})
@BeforeClass(alwaysRun = true)
public void setUp( String platform,String browser,String device,String udid) {
  super.setUp(platform, browser, device, udid);
}

2 add logs right after all your beforeX and afterX so you can see if they actually started

@Parameters({"platform","browser","device","udid"})
@BeforeClass(alwaysRun = true)
public void setUp( String platform,String browser,String device,String udid) {
  Systme.out.println("BeforeClass: setUp")
  super.setUp(platform, browser, device, udid);
}

Thanks @Aleksei for your kind response.
After inserting System.out.println("<Some console msg...>") and (alwaysRun = true) next to @BeforeClass and @AfterClass annotations, running the script class as Maven Verify or test, I got none of the console output messages but just the usual output like…

I tried debugging by inserting the breakpoints, but none were hit and program simply flowed with out hitting them.

Bottom line, no System.out.println(“msg”) or breakpoints were effective ! Meaning TestNG is silently exiting the code ???

How you run the project or xml file? Try with command line also…

What is the name of the test class? Depending on how you run your tests, the class name may be tripping you up.

https://chatgpt.com/c/67c63580-8fd8-8011-acf3-ca65b7ab0e37

@Aleksei
I ran the test class with testSuite xml file(supplying the TestNG parameters) from the command prompt and attached is the output on the terminal. Essentially the same status.

maven_command_run_console_output.txt (7.6 KB)

If I believe mismatch in terms of selenium dependencies is causing this issue, I matched Selenium-java client v.4.28 with Appium-java client v9.4.0 as mentioned in the compatibility matrix.

Maybe you can share your project? Just remove any sensitive part so everyone can see a bit more and suggest solution…

@Aleksei and @sbabcoc
Following the suggestion that Selenium dependency is no more required because Appium java client already has it added as a transitive dependency and it will always be compatible.

After removing the dependency to selenium-java v.4.28, the program flow is recognizing the TestNG annotations and running OK.

Wow ! What a roller coaster ride on. this issue … for one week.
Thanks all for your kind help !

2 Likes

W.o.w i.n.d.e.e.d. - need to try also!

Checked mine selenium-java v.4.28 →

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.9.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <!-- need java-client increase
            https://github.com/appium/java-client?tab=readme-ov-file#compatibility-matrix
            -->
            <version>4.28.0</version>
        </dependency>

        <!-- https://github.com/appium/java-client/issues/2247#issuecomment-2523527428  -->
        <dependency>
            <groupId>net.bytebuddy</groupId>
            <artifactId>byte-buddy</artifactId>
            <version>1.16.1</version>
        </dependency>

        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>9.4.0</version>
        </dependency>

zero issues…