automating the building of the parameters used in xml file?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

automating the building of the parameters used in xml file?

MWebster
Hello, 
Can the xml file, which has the (data drived) parameters be built in an automated method?

For example, rather than manually edit the testng.xml file to add the parameters, can they be generated at run time? In the example (xml below): companyName, deviceName, deviceUdid, deviceVersion and platform are data values used to run the test. rather than manually enter them can the xml be autogenerated?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="SmokeSuite" allow-return-values="true" verbose="1" parallel="tests" thread-count="1">
  <test name="Smoke Moto" thread-count="1">
    <parameter name="CompanyName" value="Brand X" />
  <parameter name="deviceName" value="Moto" />
<parameter name="deviceUdid" value="ZY223LJ2W4" />
<parameter name="deviceVersion" value="7.0" />
<parameter name="platform" value="android" />
    <classes>
      <class name="tests.smoke.SmokeTest"/>
    </classes>
  </test> <!-- Test -->
  <test name="Smoke Note4" thread-count="1">
    <parameter name="CompanyName" value="Brand Y" />
  <parameter name="deviceName" value="Note4" />
<parameter name="deviceUdid" value="2b80c4f8" />
<parameter name="deviceVersion" value="6.0.1" />
<parameter name="platform" value="android" />
    <classes>
      <class name="tests.smoke.SmokeTest"/>
    </classes>
  </test> <!-- Test -->
  <test name="Smoke OnePlus" thread-count="1">
    <parameter name="CompanyName" value="Brand Z" />
<parameter name="deviceName" value="OnePlus" />
<parameter name="deviceUdid" value="6efdf4e6" />
<parameter name="deviceVersion" value="6.0.1" />
<parameter name="platform" value="android" />
    <classes>
      <class name="tests.smoke.SmokeTest"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: automating the building of the parameters used in xml file?

Krishnan Mahadevan

Yes it can be done.

Here’s how you do it.

 

  • You upgrade to using the latest released version of TestNG (6.11)
  • You build an implementation of the TestNG listener IAlterSuiteListener wherein you include the logic of altering your suite xml based on your needs.
  • Add a reference to above created listener into your suite xml file using the <listener> tag

 

So your suite xml can look like below (Here ConsoleReporter would be an implementation of IAlterSuiteListener)

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="1297_Suite" verbose="2" parallel="tests" thread-count="10">

    <listeners>

        <listener class-name="com.rationaleemotions.github.issue1297.ConsoleReporter"/>

    </listeners>

</suite>

 

 

That should basically solve your use-case.

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

 

From: <[hidden email]> on behalf of MWebster <[hidden email]>
Reply-To: <[hidden email]>
Date: Saturday, June 3, 2017 at 4:37 AM
To: testng-users <[hidden email]>
Subject: [testng-users] automating the building of the parameters used in xml file?

 

Hello, 

Can the xml file, which has the (data drived) parameters be built in an automated method?

 

For example, rather than manually edit the testng.xml file to add the parameters, can they be generated at run time? In the example (xml below): companyName, deviceName, deviceUdid, deviceVersion and platform are data values used to run the test. rather than manually enter them can the xml be autogenerated?

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="SmokeSuite" allow-return-values="true" verbose="1" parallel="tests" thread-count="1">

  <test name="Smoke Moto" thread-count="1">

            <parameter name="CompanyName" value="Brand X" />

            <parameter name="deviceName" value="Moto" />

            <parameter name="deviceUdid" value="ZY223LJ2W4" />

            <parameter name="deviceVersion" value="7.0" />

            <parameter name="platform" value="android" />

    <classes>

      <class name="tests.smoke.SmokeTest"/>

    </classes>

  </test> <!-- Test -->

  <test name="Smoke Note4" thread-count="1">

            <parameter name="CompanyName" value="Brand Y" />

            <parameter name="deviceName" value="Note4" />

            <parameter name="deviceUdid" value="2b80c4f8" />

            <parameter name="deviceVersion" value="6.0.1" />

            <parameter name="platform" value="android" />

    <classes>

      <class name="tests.smoke.SmokeTest"/>

    </classes>

  </test> <!-- Test -->

  <test name="Smoke OnePlus" thread-count="1">

            <parameter name="CompanyName" value="Brand Z" />

            <parameter name="deviceName" value="OnePlus" />

            <parameter name="deviceUdid" value="6efdf4e6" />

            <parameter name="deviceVersion" value="6.0.1" />

            <parameter name="platform" value="android" />

    <classes>

      <class name="tests.smoke.SmokeTest"/>

    </classes>

  </test> <!-- Test -->

</suite> <!-- Suite -->

 

 

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Loading...