Is there a way to specify parameters for included methods in TestNG suite.xml?

倾然丶 夕夏残阳落幕 提交于 2019-12-20 04:14:26

问题


I'm writing a suite.xml for an own testframework based on TestNG. My xml file looks like:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite" parallel="methods">
  <test name="NewTest">
  <parameter name="BROWSER" value="Chrome"></parameter>
  <classes>
   <class name="hm.NewTest">
     <methods>
        <include name="test"></include>
        <include name="test2"></include>
        <include name="test3"></include>
        <include name="test4"></include>
     </methods>
   </class>
 </classes>
 </test>
 </suite>

The parameter "BROWSER" is now specified for the complete test. But i need an own parameter for each of the included methods. Does anyone knows a solution?


回答1:


For this rather than assigning parameters in test suite xml you can assign parameters for your tests individually . for that you don't have to add each parameter in suite.xml .

@Parameters({ "datasource", "jdbcDriver" })
@test
public void sampleTest(String ds, String driver) {
// your test method
}

Hope this will help you 1

http://testng.org/doc/documentation-main.html#parameters




回答2:


For some reason testng 6.4 and up no longer supports parameter inside the method.

But if you revert back to 6.3 i think, is the last version that supported that. I have same issue and recall that it used to work in our framework, so i started reverting back one version at a time. Why they took it out is beyond me.

With 6.3 you could do:

<methods>
        <include name="test">
          <parameter name="Firefox"/>
        </include>
        <include name="test2">
           <parameter name="Chrome"/>
        </include>
        <include name="test3">...</include>
        <include name="test4">...</include>
</methods>

and somewhere with listener call

iTestContext.getCurrentXmlTest().getParameters()

Hope it helps. If too late for you, maybe good info for someone else.

Edit: I LIED! You can still get it with latest testng ;)

iTestResult.getMethod().findMethodParameters(iTestContext.getCurrentXmlTest())


来源:https://stackoverflow.com/questions/8820238/is-there-a-way-to-specify-parameters-for-included-methods-in-testng-suite-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!