Saturday, April 2, 2016

I have researched lot, how to execute the TestNG xml from a Java class because I wanted to make my whole project in to a Runnable JAR file and execute it anywhere outside eclipse. This was already in the TestNG docs, but I couldn't understand this first time.

Advantages of this method:


  • You can execute your tests outside eclipse, any machine provided JRE is installed on the machine. You don't need to place the libraries too, The JAR will have all these.
  • Without a Selenium grid, this enables you to  run the tests on any previous versions of browsers running on another machine.
  • This can be executed by anyone without any knowledge of Eclipse, scripting etc.


How to do this:

Assuming you are running your test cases by executing testNG.xml as TestNG.

Steps:

Create a Java class with main method with below code.


public class MainTest {
    public static void main(String[] args){
    List<String> file = new ArrayList<String>();
    file.add("D:/Selenium_workspace/Framework/src/Framework.xml");
    TestNG testNG = new TestNG();
    testNG.setTestSuites(file);
    testNG.run();}
}



Now Export your whole project to runnable JAR. Double click the JAR, will execute the xml as testNG. You may create a user interface to select XML so that it adds flexibility to select which test you need to run.


2 comments:

  1. When i tried above code, displays "The System cannot find the filepath specified". Kindly advise on this.

    ReplyDelete
    Replies
    1. Did you place the testng xml file in the given path?

      Delete

>

Selenium useful links

Powered by Blogger.

Featured Post

Benefits of having a user Interface for a Selenium Automation Suite/Regression Suite

Once you are able to work independently on Selenium scripting, another important task is how to ease your automation test execution. There a...

Video

Popular Posts

Our Facebook Page