0

Im very new to selenium and tried creating a test script in eclipse. When the class is executed using TestNG a testngexception is thrown. can some one please check whether there is a issue with the script I have written?

package first_package;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class Test_Class_Automation {

    @Test
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        WebDriver driver = new FirefoxDriver();
        driver.manage().window().maximize();
        driver.get("https://www.google.lk");
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        driver.close();
    }
}
0

1 Answer 1

1

If you are using testng annotation then you don't need to write main method there. You can just write it in this way: package first_package;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class Test_Class_Automation {

    @Test
    public void testCase {
        // TODO Auto-generated method stub
        WebDriver driver = new FirefoxDriver();
        driver.manage().window().maximize();
        driver.get("https://www.google.lk");
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        driver.close();
    }
  }
Sign up to request clarification or add additional context in comments.

3 Comments

thanks but now it doesn't identify it as a class. noclassfoundexception is given.
I would suggest start from scratch, in ur package right click and create a new testng class which would ask to select annotations and then write the above method and execute it as testng class.
Run this class and as TestNg class not as java

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.