How to programmatically run Selenium Java tests with TestNG?

I am using Selenium RC with Java, using TestNG as a test platform. I am using Eclipse as an IDE. I want to call TestNG from my own program very easily. How can i do this?

+8
java eclipse testng selenium-rc automated-tests
source share
3 answers

TheStijn provides some good directions, although TestMethodWorker () is internal, so you should not use it.

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

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

+6
source share

My following java code works fine:

@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(); } 

A detailed explanation can be obtained by visiting the following URL:

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

+8
source share

Take a look at org.testng.remote.RemoteTestNG, however you will need to write an xml set for your tests, for example:

 <suite name="Default suite"> <test verbose="2" name="Default test"> <classes> <class name="com...service.UserServiceImplTest"/> </classes> </test> </suite> 

Another entry point could be the new org.testng.internal.TestMethodWorker (...). run (), but you will have to look at the code to determine the constructor arguments that need to be set.

Perhaps other, more convenient entry points are available depending on your needs; I suggest starting some test in debug mode, putting a breakpoint in your test and going down the stack.

0
source share

All Articles