Wednesday, 14 November 2012

Executing TestNG Selenium tests via Command Line

My Java's a little rusty.
I'm new to Selenium.
This will be a guide for me: the 'above novice programmer' and 'below dev'.

Starting Assumptions

Java jre is installed.
Class path for Java has been set up.
You know how to add/edit class paths (for most (all?) Windows machines this is: Start > right click My Computer > Properties > Advanced tab > Environment Variables)

There is a Selenium project kicking around, already set up with TestNG. 
We're on a Windows computer.

I'm going to assume that you've been able to run these from your IDE - in my case, Eclipse. For help on this, or getting TestNG set up originally, refer to my older post on Implementing TestNG

What two things we need to set up

Two classpaths are required. Please be aware that a computer reboot is required in order for a class path / environment variable to be set.

Class path to Selenium jar

So I have a file on my computer: C:\Selenium\selenium-server-standalone-2.25.0.jar
So I add in to my class path
c:\Selenium\*
From memory I think this didn't work without the \* - I can't really be bothered analysing why, or double checking this. 

Class path to my project

And I have a project at C:\dev\Workspace\MyProject\
So I will add the bin to my class path
C:\dev\Workspace\MyProject\bin;
This seemed to throw a wobbly when I added \* ..again, I am a bit perplexed but can't really justify analysing why, or double checking this. 

Command to Run

Refer to the official documentation for examples on creating a driving xml file.
C:\Selenium\DrivingXml>java org.testng.TestNG myDrivingXmlFile.xml

Work log (and issues encountered)

Could not find or load main class org.testng.TestNG

Check your class paths. I had this because I failed to include my class path to my selenium jar. Or had an error in one of my class paths.

Exception in thread "main" java.lang.NoClassDefFoundError: org/testng/TestNG

Computer probably doesn't hvae TestNG jar file. Will test this on Monday though as today is POETS day. 

No comments:

Post a Comment

Robot Framework, Basic Setup

Plug: Robot Framework is quick to setup, easy to write tests for, and super fast to triage failures in. The last point really sets it apart...