当前位置: 首页 > 知识库问答 >
问题:

使用TestNG在selenium automation中出现“未找到测试。未运行”错误

柴琦
2023-03-14
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

共有1个答案

陈飞语
2023-03-14

此错误消息...

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

...意味着TestNG没有发现任何测试,因此没有执行任何测试。

TestNG是一个基于注释的测试框架,它需要一个标记注释类型来表示一个方法是一个测试方法,并且应该由测试工具运行。因此,在使用注释时使用testng,并且不必显式调用main()方法。

// 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
    }
}
 类似资料:
  • 我试图通过testng运行简单的Cucumber/Java测试。xml。 所以,我有testng。xml: 我用的是runner。类,在其中我将路径/选项/etc设置为功能文件、步骤和报告: 但是当我运行testng时。xml作为TestNG套件,它: 1) 通过我自己的设想, 但是 我做错了什么?

  • 当我试图从Spring Boot应用程序中调用JUnit测试用例时,我遇到了以下错误: 我在测试类中使用了这个注释。 @RunWith(SpringRunner.class) 在我从项目依赖项添加JUnit库后,它给出了以下错误: 我的Spring启动版本是2.0.4。编辑器是SpringToolSuite。有人能帮我解决这个问题吗? 谢谢

  • 这是一个关于PHP单元测试的问题,给出了一个类NotFound错误。 背景资料 我正在使用Zend Studio 10.5开发Zend Framework 2应用程序。我加载了一些模块,包括和 FedcoUser是具有使用BJYAAuthorize的保护规则的控制器保护的模块: 使用Zend Studio 10.5本机菜单,我为上面的控制器创建了一个测试用例。当我运行它时,我得到以下错误: 我的假

  • 目前,我正在使用头盔和地形在GCP上部署我的詹金斯。这是我的地形代码: 但当我尝试在管道上运行docker命令时,我得到了以下错误: [vision_front_new_master-pth4udtqvsas7vicpco2ufhiem6b37lqylejt5bmat36ayx77ka]运行shell脚本 docker拉节点:碳 /home/jenkins/workspace/vision\u f

  • 我试图用maven和tesng运行一个API测试,在执行过程中,一些错误出现在consol上,我使用intellij,java 8,testng和maven任何想法如何解决这个问题 错误: 测试:这是我使用testng执行的一个示例测试 POM:这是我的POM xml文件和所有使用的依赖项的示例

  • 问题内容: 在Eclipse中运行JUnit测试时出现此错误: 尽管我正在使用maven,但我尝试在类路径中添加库,而JUnit库位于POM依赖项中。 我已经尝试清理项目,并使用Eclipse的JUnit插件创建了一个新的JUnit测试用例,但仍然遇到相同的错误。 问题答案: 出现这种情况的原因是,使用时只有源代码正在编译(我使用的是maven 3.1.0,所以我不确定它是否始终如此)。 如果运行