When I was running a test ng method using the '@Test' annotation, we got an exception and the test was not running.
TestNG class
package testNGtest;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
public class loginlogout {
public WebDriver driver;
String driverPath = "D:\\chromedriver.exe";
public String BaseURL = "https://xxxx.com/login";
@Test
public String loginPage() {
System.out.println(BaseURL);
System.setProperty("webdriver.chrome.driver", driverPath);
driver= new ChromeDriver();
driver.get(BaseURL);
String currentUrl=driver.getCurrentUrl();
Assert.assertTrue(currentUrl.contains("/login"));
return "URL is found";
}
}
when i am running this test as testNG Test, it shows [TestNG] No tests found. Nothing was run. But when i am just run only with
System.out.println(BaseURL);
it displaying the BaseURL, but when adding the rest of the code, shows no tests found. I am using chrome browser version 91.0.4472.124 and chrome driver version i have downloaded from https://chromedriver.storage.googleapis.com/index.html?path=91.0.4472.101/ and saved it to my D drive. And i have added two jar files 'client-combined-3.141.59.jar and client-combined-3.141.59-sources.jar' as Referenced libraries in my Project. As a test result, i can see the following
This console error message
[TestNG] No tests found. Nothing was run
Usage: <main class> [options] The XML suite files to run
Options:
-alwaysrunlisteners
Should MethodInvocation Listeners be run even for skipped methods
Default: true
-configfailurepolicy
Configuration failure policy (skip or continue)
-d
Output directory
-dataproviderthreadcount
Number of threads to use when running data providers
-dependencyinjectorfactory
The dependency injector factory implementation that TestNG should use.
-excludegroups
Comma-separated list of group names to exclude
-failwheneverythingskipped
Should TestNG fail execution if all tests were skipped and nothing was
run.
Default: false
-groups
Comma-separated list of group names to be run
-junit
JUnit mode
Default: false
-listener
List of .class files or list of class names implementing ITestListener
or ISuiteListener
-methods
Comma separated of test methods
Default: []
-methodselectors
List of .class files or list of class names implementing IMethodSelector
-mixed
Mixed mode - autodetect the type of current test and run it with
appropriate runner
Default: false
-objectfactory
List of .class files or list of class names implementing
ITestRunnerFactory
-parallel
Parallel mode (methods, tests or classes)
Possible Values: [tests, methods, classes, instances, none, true, false]
-port
The port
-reporter
Extended configuration for custom report listener
-spilistenerstoskip
Comma separated fully qualified class names of listeners that should be
skipped from being wired in via Service Loaders.
Default: <empty string>
-suitename
Default name of test suite, if not specified in suite definition file or
source code
-suitethreadpoolsize
Size of the thread pool to use to run suites
Default: 1
-testclass
The list of test classes
-testjar
A jar file containing the tests
-testname
Default name of test, if not specified in suitedefinition file or source
code
-testnames
The list of test names to run
-testrunfactory, -testRunFactory
The factory used to create tests
-threadcount
Number of threads to use when running tests in parallel
-threadpoolfactoryclass
The threadpool executor factory implementation that TestNG should use.
-usedefaultlisteners
Whether to use the default listeners
Default: true
-log, -verbose
Level of verbosity
-xmlpathinjar
The full path to the xml file inside the jar file (only valid if
-testjar was specified)
Default: testng.xml
I want to run my test which is using testNg without any error or exception for above code.
We have ways to solve the above bug.
If your test ng method has a non-void return type[Not void]. If we remove the non-void return type for the test method.
Instead of removing the non-void return type we can add a line to the testng.xml file that accepts any return type for testNg methods. Line