首页 > 解决方案 > 无法运行 testng 程序

问题描述

我无法运行testng程序,因为它给出了classpath错误。我已经添加了testng库:

org.testng.TestNGException:在类路径中找不到类:testngBasic

package mobileAutomation;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
    public class testngBasic {
    WebDriver driver;
    @BeforeMethod
    public void setUP() {
        System.setProperty("webdriver.chrome.driver", "C:\\drivers\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.manage().deleteAllCookies();
        driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("https://www.google.com");
    }
    @Test
    public void getTitle() {
        String googleTitle = driver.getTitle();
        System.out.println(googleTitle);
    }
    @AfterMethod
    public void closeBrowser() {
        driver.quit();  
    }
}

标签: javaseleniumautomationtestng

解决方案


只需执行Eclipse > Project > Clean,然后再次运行测试用例。它应该工作。


推荐阅读