TestNG - Indicate environment andbrowser as parameter, set up value in Xml file.

    xiaoxiao2022-07-03  123

    Set up parameter in TestNG class 

    There is a class named Config which focuses on set up environment and browser, here just use it

    @BeforeClass @Parameters({"environment"}) public void setupEnvironment(@Optional final String environment) throws Exception { this.log.info(" @BeforeTest "); this.log.info("Setup Environment: " + environment); loadTestData(); Config.setupEnvironment(environment); } @BeforeClass @Parameters({"browser", "url"}) public void setupDriver(@Optional final String browser, @Optional final String url) throws Exception { this.log.info("@BeforeClass"); try { Config.setupWebDriver(browser, url); } catch(Exception e) { e.printStackTrace(); } this.log.info("Setup web Driver: " + browser); }

    Xml file to indicate value for parameter:

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="Suite" parallel="classes" thread-count ="9"> <parameter name="url" value="http://hub's IP:4444"/> <parameter name="browser" value="chrome" /> <parameter name="environment" value="dev" /> <listeners> <listener class-name="test.template.utils.SendEmailReporter"></listener> </listeners> <test name="XXX"> <classes> <class name="com.xxx.xxx.cases.xxx.xxxxxx"></class> </classes> </test> </suite>

     

    最新回复(0)