【问题标题】:running Test cases in TestNG framework在 TestNG 框架中运行测试用例
【发布时间】:2017-05-10 06:08:10
【问题描述】:

你好,我正在尝试在 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 运行时,我得到以下错误

失败:制作 java.lang.NoClassDefFoundError: com/google/common/base/Function 起初.heha.make(heha.java:16)

【问题讨论】:

标签: java selenium-webdriver automated-tests testng test-reporting


【解决方案1】:

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

如果你使用 maven 来运行你的测试

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

<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.10</version>
</dependency>

【讨论】:

  • 不客气,请您选择这个作为正确答案
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-29
    • 2017-05-01
    • 1970-01-01
    • 2018-02-15
    • 1970-01-01
    • 1970-01-01
    • 2017-11-14
    • 2015-08-14
    相关资源
    最近更新 更多