简体   繁体   中英

Is there way to send different parameter values to different classes inside a test inside testng.xml

I need to pass a different parameter value for different classes inside a test. The following code gives me an error saying :

"The content of element type "classes" must match '(class*,parameter*)'.".

Is there any other way I can pass the parameter value to be accessible by a class?

  <suite name="Project">
  <test thread-count="5" name="Test">
      <classes>
      <parameter name="URL" value="https://testRunner1.com" />
      <class name="project.TestRunner1"/>
      <parameter name="URL" value="https://testRunner2.com" />
      <class name="project.TestRunner2"/>
    </classes>
  </test>
</suite>

There are two solutions. 1. Move the classes to different test as given below. Here you can have same name for the Parameters.

<suite name="Project">
  <test thread-count="5" name="Test">
      <classes>
      <parameter name="URL" value="https://testRunner1.com" />
      <class name="project.TestRunner1"/>          
    </classes>
  </test>
  <test thread-count="5" name="Test">
      <parameter name="URL" value="https://testRunner2.com" />
      <class name="project.TestRunner2"/>
   </test>
</suite>
  1. You need to change the parameter name in the class and change the xml as given below

I rewrote my code like below which worked.

  <suite name="Project">
  <test thread-count="5" name="Test">
      <classes>
         <class name="project.TestRunner1">
             <parameter name="URL" value="https://testRunner1.com" />
         </class>
         <class name="project.TestRunner2">
             <parameter name="URL" value="https://testRunner2.com" />
         </class>
    </classes>
  </test>
</suite>

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