0

Given below is the code that I coded using selenium in eclipse.

import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
class GoogleSearchTest {

    @Test
    public static void main(String[] args) throws InterruptedException {
        System.setProperty("webdriver.gecko.driver","C:\\Users\\acer\\Downloads\\selenium\\geckodriver.exe");
        WebDriver driver =new FirefoxDriver();
        driver.get("https://www.google.com/");
        WebElement we1 = driver.findElement(By.name("q"));
        we1.sendKeys("GMAIL");
        we1.sendKeys(Keys.ENTER); 
        WebDriverWait wait1 = new WebDriverWait(driver, 5);
        wait1.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h3[text()='E-mail - Sign in - Google Accounts']"))).click();
        Thread.sleep(10000); 
        driver.findElement(By.id("identifierId")).sendKeys("2017cs102@stu.ucsc.cmb.ac.lk");
        driver.findElement(By.xpath("//*[@id='identifierNext']/div/span/span")).click();
        Thread.sleep(10000);
        driver.findElement(By.name("password")).sendKeys("mmalsha425@gmail.com");
        driver.findElement(By.xpath("//*[@id='passwordNext']/div/span/span")).click();

    }

}

It gives the following error.

[TestNG] No tests found. Nothing was run
Usage: <main class> [options] The XML suite files to run

I have already installed TestNG plugin.What can I do to fix this problem??

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Malsha Madushani
  • 27
  • 1
  • 3
  • 11

4 Answers4

0

Change the main function name. You should not use it while using TestNG

@Test
public void test() throws InterruptedException {
    System.setProperty("webdriver.gecko.driver","C:\\Users\\acer\\Downloads\\selenium\\geckodriver.exe");
    WebDriver driver =new FirefoxDriver();
Sriram S
  • 169
  • 14
0

You don't need to write main() method, TestNg do that by itself.

class GoogleSearchTest {
    @Test
    public void test() throws InterruptedException{
        //your code here
        .....
    }
}

If you want to call from main(), simply:

import org.testng.TestNG;

public class Master {
    public static void main(String[] args) {
        TestNG testng = new TestNG();
        testng.setTestClasses(new Class[] { GoogleSearchTest.class });
        testng.run();
    }
}

But note, in GoogleSearchTest class don't put public static void main for @Test

frianH
  • 7,295
  • 6
  • 20
  • 45
0

This error message...

[TestNG] No tests found. Nothing was run
Usage: <main class> [options] The XML suite files to run

...implies that the TestNG found no tests hence nothing was executed.


TestNG

TestNG is an annotation-based test framework which needs a marker annotation type to indicate that a method is a test method, and should be run by the testing tool. Hence, while using as you use annotations and you don't have to call the main() method explicitly.


Solution

The simple solution would be to replace the main() method with a test method name e.g. test() and keep the @Test annotation as follows:

// your imports

class GoogleSearchTest {

    @Test
    public void test() throws InterruptedException {
        System.setProperty("webdriver.gecko.driver","C:\\Users\\acer\\Downloads\\selenium\\geckodriver.exe");
        // other lines of code
    }
}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Try reframing the method

public static void main(String[] args) throws InterruptedException {

like this:

public void search()
{
    // -----your code----
}
Alberto
  • 1,569
  • 1
  • 22
  • 41