user1724416
user1724416

Reputation: 954

Running selenium tests using TestNG from the command line

I am currently running my selenium test from the command line using TestNG

java -cp \lib\testng.jar;
         \lib\selenium-server-standalone-2.42.2.jar;
         \lib\log4j-1.2.17.jar;
         \bin\. 
         org.testng.TestNG runTest.xml

However I would ideally like to use as a command line argument what webdriver to use. Currently in my setUp() it just loads the firefox driver, and changing drivers means commenting and uncommenting out code

So as an end goal I could use.

-chrome -firefox

To run tests on firefox and chrome.

What method do you suggest is best to achieve this?

Upvotes: 1

Views: 851

Answers (1)

satworld
satworld

Reputation: 117

You can create a custom parameter -Dbrowser=chrome or -Dbrowser=firefox. Based on the value in the Dbrowser you need to initialize appropriate driver in the setup() method.

-Dbrowser can be read using the System.getProperty("browser") code.

Upvotes: 1

Related Questions