0

您好我正在尝试在 TestNG 类中运行一个测试用例,我可以在其中获得报告和编号测试失败或通过测试用例以下代码在普通 java 类中运行时有效...

@Test
public void make() throws InterruptedException{
    System.setProperty("webdriver.chrome.driver","C:\\Users\\sasy\\Desktop\\Akhil\\Selenium\\chromedriver.exe");
    WebDriver driver=new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    System.setProperty("org.apache.commons.logging.Log","org.apache.commons.logging.impl.Jdk14Logger");
    driver.get("http://198.57.218.124/CRFGLSPL/Private/login.aspx?ReturnUrl=%2fCRFGLSPL%2fPrivate%2fPatientOrganDamageIntermediateVisit.aspx%3fPatientID%3d2&PatientID=2");

    driver.findElement(By.xpath("//*[@id='ctl00_ContentPlaceHolder1_txtEmail']")).sendKeys("nikhil@gmail.com");
    driver.findElement(By.xpath("//*[@id='ctl00_ContentPlaceHolder1_txtPassword']")).sendKeys("maryme");
    driver.findElement(By.xpath("//*[@id='ctl00_ContentPlaceHolder1_btnLogin']")).click();
    driver.findElement(By.xpath("//*[@id='ctl00_ContentPlaceHolder1_btnSubmit']")).click();
    driver.findElement(By.xpath("//*[@id='ctl00_ContentPlaceHolder1_btnSubmit']")).click();
    //WebElement ID418=driver.findElement(By.xpath("//*[@id='edit41']"));
    //WebElement ID830=driver.findElement(By.xpath("//*[@id='edit40']"));
    WebElement ID969=driver.findElement(By.xpath("//*[@id='edit37']"));
    //WebElement ID472=driver.findElement(By.xpath("//*[@id='edit39']"));
    Thread.sleep(3000);
    ID969.click();
    driver.quit();

}

当上面的代码作为 TestNG Test 运行时,我得到以下错误

FAILED: make java.lang.NoClassDefFoundError: com/google/common/base/Function at first.heha.make(heha.java:16)

4

2 回答 2

0

具有 class 的 jar 文件com.google.common.base.Function,您很可能没有将其添加到您的类路径中。添加 Guava jar 文件以构建路径

检查以确保所有必需的 selenium 、testNg 库都在您的构建路径中

于 2017-05-10T06:32:04.650 回答
0

实际上,您的代码在 TestNG 上运行良好我已经尝试过了,您需要做的就是在您的类路径中包含 TeseNG 罐子,您可以通过下载 TestNG 罐子并将其添加到您的类路径中手动执行此操作,或者只需在您的类路径中添加 TestNG 依赖项pom.xml 如果您使用的是 Maven

如果您使用 maven 运行测试

在您的 pom.xml 中添加以下依赖项

<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.10</version>
</dependency>
于 2017-05-10T08:02:46.347 回答