running Test cases in TestNG framework

342 Views Asked by At

hello I am trying to run a test case in TestNG class where i can get reports and number test failed or passed test cases the below code works when ran in normal java class...

@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("[email protected]");
    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();

}

when the above code is ran as TestNG Test i am given following error

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

2

There are 2 best solutions below

0
On

The jar file having the class com.google.common.base.Function, which you most probably did not add to your classpath. Add Guava jar file to build path

Check to make sure all the required selenium ,testNg libraries are in your build path

1
On

Actually your code works fine with TestNG I've tried it , all you need to do is to include the TeseNG Jars in your Class path you can do this manually by downloading TestNG jars and adding it to your classpath or Simply add TestNG dependency in your pom.xml if you are using Maven

If you are using maven to run your tests

Add below dependency in your pom.xml

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