How to run Selenium Java tests with TestNG programmatically?

Ripon Al Wasim picture Ripon Al Wasim · Mar 28, 2011 · Viewed 14.9k times · Source

I am using Selenium RC with Java using TestNG as Test Framework. I'm using Eclipse as IDE. I want to invoke TestNG from my own program very easily. How can I do that?

Answer

Ripon Al Wasim picture Ripon Al Wasim · Aug 30, 2012

My following code in java works nicely:

@Test
public void testTestNGProgramatically(){
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] {LoginAuthentication.class, GmailSigninSignout.class});
testng.addListener(tla);
testng.run(); 
}

You can get the details explanation by visiting the following URL:

http://testng.org/doc/documentation-main.html#running-testng-programmatically