Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Selenium Java tests with TestNG programmatically?

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?

like image 443
Ripon Al Wasim Avatar asked Mar 28 '11 10:03

Ripon Al Wasim


2 Answers

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

like image 169
Ripon Al Wasim Avatar answered Sep 22 '22 19:09

Ripon Al Wasim


TheStijn gives a few good directions, although TestMethodWorker() is internal so you shouldn't use it.

Based on the question, I'm not even sure the original poster is trying to launch TestNG in a separate process, so the API documentation might be what you're looking for:

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

like image 34
Cedric Beust Avatar answered Sep 22 '22 19:09

Cedric Beust