简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM