使用TestNG的selenium automation中出现java“未找到任何测试。未运行任何内容”错误
下面是我在eclipse中使用selenium编写的代码
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();
}
}
它给出了以下错误
[TestNG] No tests found. Nothing was run
Usage: <main class> [options] The XML suite files to run
我已经安装了TestNG插件。我能做些什么来解决这个问题
# 1 楼答案
您不需要编写
main()
方法,TestNg可以自己完成如果您想从
main()
呼叫,只需:但是请注意,在
GoogleSearchTest
类中,不要把public static void main
放在@Test
# 2 楼答案
更改主函数名。您不应该在使用TestNG时使用它
# 3 楼答案
此错误消息
。。。这意味着TestNG没有发现任何测试,因此没有执行任何测试
TestNG
TestNG是一个基于注释的测试框架,它需要一个标记注释类型来指示一个方法是一个测试方法,并且应该由测试工具运行。因此,当使用testng时,就像使用annotations一样,您不必显式地调用
main()
方法解决方案
简单的解决方案是用测试方法名替换
main()
方法,例如test()
,并保留@Test
注释如下: