Updating testng xml at runtime or Option to run OS/Browser combination given in test method!

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

Updating testng xml at runtime or Option to run OS/Browser combination given in test method!

Sasi kumar-3
scenario : 

i) Iam create testng.xml at runtime before test starts ,that is before testng is started .
ii) Will have what all os,browsers has to be tested for an test method ,inside my test method .Say (linux,firefox) , (mac,safari).

What iam trying is,

Using listener  @Before method iam getting browser, os parameter from xml and initiate the driver. Now from test method i want to update the testng.xml with parameters given by user.

Or is there any other way to do it?

Note : i can't pre create with all OS/Browser combination as some test may not have all combinations.

Sample :

 @BeforeMethod
    public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
        if (method.isTestMethod()) {
            
            
            browserName = method.getTestMethod().getXmlTest().getLocalParameters().get("browserName");
            
            driver = LocalDriverFactory.createInstance(browserName);
LocalDriverManager.setWebDriver(driver);
       
        }
    }
 

XML :


<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="4" name="Default Suite" parallel="tests">
  <listeners>
    <listener class-name="com.WebDriverListener"/>
  </listeners>
  <test name="test">
    <parameter name="browserName" value="*firefox"/>
    <classes>
      <class name="com.testcases_name"/>
    </classes>
  </test> 
</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 http://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: Updating testng xml at runtime or Option to run OS/Browser combination given in test method!

Sasi kumar-3
Is it not possible to update testng.xml once we run the cases?

On Friday, 14 August 2015 11:27:35 UTC+5:30, Sasi kumar wrote:
scenario : 

i) Iam create testng.xml at runtime before test starts ,that is before testng is started .
ii) Will have what all os,browsers has to be tested for an test method ,inside my test method .Say (linux,firefox) , (mac,safari).

What iam trying is,

Using listener  @Before method iam getting browser, os parameter from xml and initiate the driver. Now from test method i want to update the testng.xml with parameters given by user.

Or is there any other way to do it?

Note : i can't pre create with all OS/Browser combination as some test may not have all combinations.

Sample :

 @BeforeMethod
    public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
        if (method.isTestMethod()) {
            
            
            browserName = method.getTestMethod().getXmlTest().getLocalParameters().get("browserName");
            
            driver = LocalDriverFactory.createInstance(browserName);
LocalDriverManager.setWebDriver(driver);
       
        }
    }
 

XML :


<!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\46sa\75D\46sntz\0751\46usg\75AFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\46sa\75D\46sntz\0751\46usg\75AFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;">http://testng.org/testng-1.0.dtd">
<suite thread-count="4" name="Default Suite" parallel="tests">
  <listeners>
    <listener class-name="com.WebDriverListener"/>
  </listeners>
  <test name="test">
    <parameter name="browserName" value="*firefox"/>
    <classes>
      <class name="com.testcases_name"/>
    </classes>
  </test> 
</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 http://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: Updating testng xml at runtime or Option to run OS/Browser combination given in test method!

Krishnan Mahadevan
Sasi Kumar,
Interesting use case there!

Since you are getting your parameters at the <test> level, you would perhaps want to explore the Listener way of doing things.

Here's what you can try [ In theory this should work! ]

  1. Create a Listener by implementing org.testng.ITestListener and wire it up to your suite.
  2. Within org.testng.ITestListener#onStart, you would have access to org.testng.ITestContext
  3. Now you can invoke ctx.getCurrentXmlTest().getLocalParameters(); to get access to all defined parameters. Since the implementation basically exposes out the original Map, you should be able to update the Map with the user provided values because its the same collection object thats being provided to you by TestNG.
Hope that helps!


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/

On Tue, Aug 18, 2015 at 11:16 AM, Sasi kumar <[hidden email]> wrote:
Is it not possible to update testng.xml once we run the cases?


On Friday, 14 August 2015 11:27:35 UTC+5:30, Sasi kumar wrote:
scenario : 

i) Iam create testng.xml at runtime before test starts ,that is before testng is started .
ii) Will have what all os,browsers has to be tested for an test method ,inside my test method .Say (linux,firefox) , (mac,safari).

What iam trying is,

Using listener  @Before method iam getting browser, os parameter from xml and initiate the driver. Now from test method i want to update the testng.xml with parameters given by user.

Or is there any other way to do it?

Note : i can't pre create with all OS/Browser combination as some test may not have all combinations.

Sample :

 @BeforeMethod
    public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
        if (method.isTestMethod()) {
            
            
            browserName = method.getTestMethod().getXmlTest().getLocalParameters().get("browserName");
            
            driver = LocalDriverFactory.createInstance(browserName);
LocalDriverManager.setWebDriver(driver);
       
        }
    }
 

XML :


<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="4" name="Default Suite" parallel="tests">
  <listeners>
    <listener class-name="com.WebDriverListener"/>
  </listeners>
  <test name="test">
    <parameter name="browserName" value="*firefox"/>
    <classes>
      <class name="com.testcases_name"/>
    </classes>
  </test> 
</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 http://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 http://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: Updating testng xml at runtime or Option to run OS/Browser combination given in test method!

walter.kelt
In reply to this post by Sasi kumar-3

I may not fully understand what you are trying to do, but you could have your xml look as follows:

<parameter name="browserName" value="*firefox,chrome"/>

When the @test method looks at the parameters you can have it do a simple split on the string 

String [] browser = browserName.split(",")

Iterate over the browser array to create your webdriver and run the test. You'll probably want to
use soft asserts to make sure all browsers are exercised before the test completes.



On Friday, August 14, 2015 at 1:57:35 AM UTC-4, Sasi kumar wrote:
scenario : 

i) Iam create testng.xml at runtime before test starts ,that is before testng is started .
ii) Will have what all os,browsers has to be tested for an test method ,inside my test method .Say (linux,firefox) , (mac,safari).

What iam trying is,

Using listener  @Before method iam getting browser, os parameter from xml and initiate the driver. Now from test method i want to update the testng.xml with parameters given by user.

Or is there any other way to do it?

Note : i can't pre create with all OS/Browser combination as some test may not have all combinations.

Sample :

 @BeforeMethod
    public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
        if (method.isTestMethod()) {
            
            
            browserName = method.getTestMethod().getXmlTest().getLocalParameters().get("browserName");
            
            driver = LocalDriverFactory.createInstance(browserName);
LocalDriverManager.setWebDriver(driver);
       
        }
    }
 

XML :


<!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\46sa\75D\46sntz\0751\46usg\75AFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\46sa\75D\46sntz\0751\46usg\75AFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;">http://testng.org/testng-1.0.dtd">
<suite thread-count="4" name="Default Suite" parallel="tests">
  <listeners>
    <listener class-name="com.WebDriverListener"/>
  </listeners>
  <test name="test">
    <parameter name="browserName" value="*firefox"/>
    <classes>
      <class name="com.testcases_name"/>
    </classes>
  </test> 
</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 http://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: Updating testng xml at runtime or Option to run OS/Browser combination given in test method!

Sasi kumar-3
In reply to this post by Krishnan Mahadevan
@krishnan - Thanks for the reply. You saw my above sample code ? 

When i tried it & update xml ,testng seems to read the xml first time it starts and it ignores the changes made in between.

Correct me if you are proposing anything different from my above code!


On Wednesday, 19 August 2015 13:32:21 UTC+5:30, Krishnan wrote:
Sasi Kumar,
Interesting use case there!

Since you are getting your parameters at the <test> level, you would perhaps want to explore the Listener way of doing things.

Here's what you can try [ In theory this should work! ]

  1. Create a Listener by implementing org.testng.ITestListener and wire it up to your suite.
  2. Within org.testng.ITestListener#onStart, you would have access to org.testng.ITestContext
  3. Now you can invoke ctx.getCurrentXmlTest().getLocalParameters(); to get access to all defined parameters. Since the implementation basically exposes out the original Map, you should be able to update the Map with the user provided values because its the same collection object thats being provided to you by TestNG.
Hope that helps!


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fwakened-cognition.blogspot.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fwakened-cognition.blogspot.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/
My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Frationaleemotions.wordpress.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Frationaleemotions.wordpress.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

On Tue, Aug 18, 2015 at 11:16 AM, Sasi kumar <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="6OSBdXZJBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">sasi...@...> wrote:
Is it not possible to update testng.xml once we run the cases?


On Friday, 14 August 2015 11:27:35 UTC+5:30, Sasi kumar wrote:
scenario : 

i) Iam create testng.xml at runtime before test starts ,that is before testng is started .
ii) Will have what all os,browsers has to be tested for an test method ,inside my test method .Say (linux,firefox) , (mac,safari).

What iam trying is,

Using listener  @Before method iam getting browser, os parameter from xml and initiate the driver. Now from test method i want to update the testng.xml with parameters given by user.

Or is there any other way to do it?

Note : i can't pre create with all OS/Browser combination as some test may not have all combinations.

Sample :

 @BeforeMethod
    public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
        if (method.isTestMethod()) {
            
            
            browserName = method.getTestMethod().getXmlTest().getLocalParameters().get("browserName");
            
            driver = LocalDriverFactory.createInstance(browserName);
LocalDriverManager.setWebDriver(driver);
       
        }
    }
 

XML :


<!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\46sa\75D\46sntz\0751\46usg\75AFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\46sa\75D\46sntz\0751\46usg\75AFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;">http://testng.org/testng-1.0.dtd">
<suite thread-count="4" name="Default Suite" parallel="tests">
  <listeners>
    <listener class-name="com.WebDriverListener"/>
  </listeners>
  <test name="test">
    <parameter name="browserName" value="*firefox"/>
    <classes>
      <class name="com.testcases_name"/>
    </classes>
  </test> 
</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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="6OSBdXZJBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="6OSBdXZJBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@....
Visit this group at <a href="http://groups.google.com/group/testng-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;http://groups.google.com/group/testng-users&#39;;return true;">http://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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 http://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: Updating testng xml at runtime or Option to run OS/Browser combination given in test method!

Sasi kumar-3
In reply to this post by walter.kelt
@walter kelt - Thanks for your reply.

My use case is, i want to get the value from user in runtime ,from test method and then update testng xml in runtime.


On Wednesday, 19 August 2015 21:31:59 UTC+5:30, walter kelt wrote:

I may not fully understand what you are trying to do, but you could have your xml look as follows:

<parameter name="browserName" value="*firefox,chrome"/>

When the @test method looks at the parameters you can have it do a simple split on the string 

String [] browser = browserName.split(",")

Iterate over the browser array to create your webdriver and run the test. You'll probably want to
use soft asserts to make sure all browsers are exercised before the test completes.



On Friday, August 14, 2015 at 1:57:35 AM UTC-4, Sasi kumar wrote:
scenario : 

i) Iam create testng.xml at runtime before test starts ,that is before testng is started .
ii) Will have what all os,browsers has to be tested for an test method ,inside my test method .Say (linux,firefox) , (mac,safari).

What iam trying is,

Using listener  @Before method iam getting browser, os parameter from xml and initiate the driver. Now from test method i want to update the testng.xml with parameters given by user.

Or is there any other way to do it?

Note : i can't pre create with all OS/Browser combination as some test may not have all combinations.

Sample :

 @BeforeMethod
    public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
        if (method.isTestMethod()) {
            
            
            browserName = method.getTestMethod().getXmlTest().getLocalParameters().get("browserName");
            
            driver = LocalDriverFactory.createInstance(browserName);
LocalDriverManager.setWebDriver(driver);
       
        }
    }
 

XML :


<!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\46sa\75D\46sntz\0751\46usg\75AFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\46sa\75D\46sntz\0751\46usg\75AFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;">http://testng.org/testng-1.0.dtd">
<suite thread-count="4" name="Default Suite" parallel="tests">
  <listeners>
    <listener class-name="com.WebDriverListener"/>
  </listeners>
  <test name="test">
    <parameter name="browserName" value="*firefox"/>
    <classes>
      <class name="com.testcases_name"/>
    </classes>
  </test> 
</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 http://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: Updating testng xml at runtime or Option to run OS/Browser combination given in test method!

Sasi kumar-3
In reply to this post by Sasi kumar-3
@krishnan - oh you are suggesting to use different Listener. Will try that too.

On Thursday, 20 August 2015 12:03:58 UTC+5:30, Sasi kumar wrote:
@krishnan - Thanks for the reply. You saw my above sample code ? 

When i tried it & update xml ,testng seems to read the xml first time it starts and it ignores the changes made in between.

Correct me if you are proposing anything different from my above code!


On Wednesday, 19 August 2015 13:32:21 UTC+5:30, Krishnan wrote:
Sasi Kumar,
Interesting use case there!

Since you are getting your parameters at the <test> level, you would perhaps want to explore the Listener way of doing things.

Here's what you can try [ In theory this should work! ]

  1. Create a Listener by implementing org.testng.ITestListener and wire it up to your suite.
  2. Within org.testng.ITestListener#onStart, you would have access to org.testng.ITestContext
  3. Now you can invoke ctx.getCurrentXmlTest().getLocalParameters(); to get access to all defined parameters. Since the implementation basically exposes out the original Map, you should be able to update the Map with the user provided values because its the same collection object thats being provided to you by TestNG.
Hope that helps!


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fwakened-cognition.blogspot.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fwakened-cognition.blogspot.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/
My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Frationaleemotions.wordpress.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Frationaleemotions.wordpress.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

On Tue, Aug 18, 2015 at 11:16 AM, Sasi kumar <[hidden email]> wrote:
Is it not possible to update testng.xml once we run the cases?


On Friday, 14 August 2015 11:27:35 UTC+5:30, Sasi kumar wrote:
scenario : 

i) Iam create testng.xml at runtime before test starts ,that is before testng is started .
ii) Will have what all os,browsers has to be tested for an test method ,inside my test method .Say (linux,firefox) , (mac,safari).

What iam trying is,

Using listener  @Before method iam getting browser, os parameter from xml and initiate the driver. Now from test method i want to update the testng.xml with parameters given by user.

Or is there any other way to do it?

Note : i can't pre create with all OS/Browser combination as some test may not have all combinations.

Sample :

 @BeforeMethod
    public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
        if (method.isTestMethod()) {
            
            
            browserName = method.getTestMethod().getXmlTest().getLocalParameters().get("browserName");
            
            driver = LocalDriverFactory.createInstance(browserName);
LocalDriverManager.setWebDriver(driver);
       
        }
    }
 

XML :


<!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\46sa\75D\46sntz\0751\46usg\75AFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\46sa\75D\46sntz\0751\46usg\75AFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;">http://testng.org/testng-1.0.dtd">
<suite thread-count="4" name="Default Suite" parallel="tests">
  <listeners>
    <listener class-name="com.WebDriverListener"/>
  </listeners>
  <test name="test">
    <parameter name="browserName" value="*firefox"/>
    <classes>
      <class name="com.testcases_name"/>
    </classes>
  </test> 
</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 testng-users...@googlegroups.com.
To post to this group, send email to [hidden email].
Visit this group at <a href="http://groups.google.com/group/testng-users" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;http://groups.google.com/group/testng-users&#39;;return true;">http://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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 http://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: Updating testng xml at runtime or Option to run OS/Browser combination given in test method!

Sasi kumar-3
@krishnan - I tried with ITestListener . When i get defined parameters and update the xml ,testng is not reading it .It takes the xml defined when test run started and it ignores xml updated in between.


sample : 

import java.util.ArrayList;
import java.util.List;

import org.openqa.selenium.WebDriver;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;
import org.testng.xml.XmlClass;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;

public class WebdriverITestListener implements ITestListener {

boolean ischecked=true;
public static XmlSuite suite ;
@Override
public void onFinish(ITestContext arg0) {
// TODO Auto-generated method stub

}

@Override
public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) {
// TODO Auto-generated method stub

}

@Override
public void onTestFailure(ITestResult test) {
// TODO Auto-generated method stub

}

@Override
public void onTestSkipped(ITestResult arg0) {
// TODO Auto-generated method stub

}

@Override
public void onTestStart(ITestResult test) {
// TODO Auto-generated method stub
String browserName=test.getMethod().getXmlTest().getParameter("browserName");
if(ischecked)
{
List<XmlTest> tests = new ArrayList<XmlTest>();
XmlTest testsuite = new XmlTest(test.getMethod().getXmlTest().getSuite());
testsuite.setName("defalut");

List<XmlClass> xmlclasses = new ArrayList<XmlClass>();
xmlclasses.add(new XmlClass("TESTCASE NAME"));

testsuite.addParameter("browserName","firefox");
testsuite.setXmlClasses(xmlclasses);
tests.add(testsuite);
suite.setTests(tests);
test.getMethod().getXmlTest().setXmlSuite(suite);
ischecked=false;
}
System.out.println(test.getMethod().getXmlTest().getSuite()+"  ------------------   ");
WebDriver driver;
try {
driver = LocalDriverFactory.createInstance(browserName);
LocalDriverManager.setWebDriver(driver);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

@Override
public void onTestSuccess(ITestResult arg0) {
// TODO Auto-generated method stub

}

@Override
public void onStart(ITestContext test) {



}

}





On Thursday, 20 August 2015 12:38:42 UTC+5:30, Sasi kumar wrote:
@krishnan - oh you are suggesting to use different Listener. Will try that too.

On Thursday, 20 August 2015 12:03:58 UTC+5:30, Sasi kumar wrote:
@krishnan - Thanks for the reply. You saw my above sample code ? 

When i tried it & update xml ,testng seems to read the xml first time it starts and it ignores the changes made in between.

Correct me if you are proposing anything different from my above code!


On Wednesday, 19 August 2015 13:32:21 UTC+5:30, Krishnan wrote:
Sasi Kumar,
Interesting use case there!

Since you are getting your parameters at the <test> level, you would perhaps want to explore the Listener way of doing things.

Here's what you can try [ In theory this should work! ]

  1. Create a Listener by implementing org.testng.ITestListener and wire it up to your suite.
  2. Within org.testng.ITestListener#onStart, you would have access to org.testng.ITestContext
  3. Now you can invoke ctx.getCurrentXmlTest().getLocalParameters(); to get access to all defined parameters. Since the implementation basically exposes out the original Map, you should be able to update the Map with the user provided values because its the same collection object thats being provided to you by TestNG.
Hope that helps!


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fwakened-cognition.blogspot.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fwakened-cognition.blogspot.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/
My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Frationaleemotions.wordpress.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Frationaleemotions.wordpress.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

On Tue, Aug 18, 2015 at 11:16 AM, Sasi kumar <[hidden email]> wrote:
Is it not possible to update testng.xml once we run the cases?


On Friday, 14 August 2015 11:27:35 UTC+5:30, Sasi kumar wrote:
scenario : 

i) Iam create testng.xml at runtime before test starts ,that is before testng is started .
ii) Will have what all os,browsers has to be tested for an test method ,inside my test method .Say (linux,firefox) , (mac,safari).

What iam trying is,

Using listener  @Before method iam getting browser, os parameter from xml and initiate the driver. Now from test method i want to update the testng.xml with parameters given by user.

Or is there any other way to do it?

Note : i can't pre create with all OS/Browser combination as some test may not have all combinations.

Sample :

 @BeforeMethod
    public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
        if (method.isTestMethod()) {
            
            
            browserName = method.getTestMethod().getXmlTest().getLocalParameters().get("browserName");
            
            driver = LocalDriverFactory.createInstance(browserName);
LocalDriverManager.setWebDriver(driver);
       
        }
    }
 

XML :


<!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\46sa\75D\46sntz\0751\46usg\75AFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\46sa\75D\46sntz\0751\46usg\75AFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;">http://testng.org/testng-1.0.dtd">
<suite thread-count="4" name="Default Suite" parallel="tests">
  <listeners>
    <listener class-name="com.WebDriverListener"/>
  </listeners>
  <test name="test">
    <parameter name="browserName" value="*firefox"/>
    <classes>
      <class name="com.testcases_name"/>
    </classes>
  </test> 
</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 testng-users...@googlegroups.com.
To post to this group, send email to [hidden email].
Visit this group at <a href="http://groups.google.com/group/testng-users" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;http://groups.google.com/group/testng-users&#39;;return true;">http://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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 http://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: Updating testng xml at runtime or Option to run OS/Browser combination given in test method!

Shylu Arji
In reply to this post by Sasi kumar-3
@Sasi Kumar,

Where u abel to solve this problem?
I am facing similar issue.

Below is the snippet of testng xml file
<parameter name="TestPlan" value="sampleTestPlan" />
<parameter name="testCase" value="sampleTestCase" />

<test name="ShopCaSeRegression">
<classes>
<class name=""> // sampleTestPlan should be here
<methods>
<include name=""></include> //sampleTestCase should be here
</methods>
</class>
</classes>
</test>

i am trying to pass testPlanname and test case name that i get as jenkins parameters inside the class and includes when test starts.

I tried using both suiteListener and testListener .

code snippet
public void onStart(ISuite suite) {
Map<String, String> parameters = suite.getXmlSuite().getParameters();
for (Map.Entry<String, String> parameter : parameters.entrySet()) {
String env = System.getenv(parameter.getKey());
if (env != null && ! env.trim().isEmpty()) {
parameter.setValue(env);
}
}

String testPlan = null;
String testCase = null;
Map<String, String> suitParameters = suite.getXmlSuite().getParameters();
for (Map.Entry<String, String> parameter : suitParameters.entrySet()) {
if(parameter.getKey().equalsIgnoreCase("TestPlan"))
testPlan = parameter.getValue();
if(parameter.getKey().equalsIgnoreCase("TestCase"))
testCase = parameter.getValue();
}

List<XmlTest> allTests = suite.getXmlSuite().getTests();
XmlTest oneTest = new XmlTest();
XmlClass oneTestClass = new XmlClass();
XmlInclude includedMethod = new XmlInclude();
List<XmlInclude> allIncludedMethods = oneTestClass.getIncludedMethods();
oneTestClass.setName(testPlan);
includedMethod.addParameter(testCase,"");
allIncludedMethods.add(includedMethod);
oneTestClass.setIncludedMethods(allIncludedMethods);
oneTest.getClasses().add(oneTestClass);
allTests.add(oneTest);
suite.getXmlSuite().setTests(allTests);

}

In debug mode i see that this method is executed, but my suite is not updated and the expected test is not run.
Any help appreciated.

Thanks!

On Thursday, August 13, 2015 at 10:57:35 PM UTC-7, Sasi kumar wrote:
scenario : 

i) Iam create testng.xml at runtime before test starts ,that is before testng is started .
ii) Will have what all os,browsers has to be tested for an test method ,inside my test method .Say (linux,firefox) , (mac,safari).

What iam trying is,

Using listener  @Before method iam getting browser, os parameter from xml and initiate the driver. Now from test method i want to update the testng.xml with parameters given by user.

Or is there any other way to do it?

Note : i can't pre create with all OS/Browser combination as some test may not have all combinations.

Sample :

 @BeforeMethod
    public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
        if (method.isTestMethod()) {
            
            
            browserName = method.getTestMethod().getXmlTest().getLocalParameters().get("browserName");
            
            driver = LocalDriverFactory.createInstance(browserName);
LocalDriverManager.setWebDriver(driver);
       
        }
    }
 

XML :


<!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;">http://testng.org/testng-1.0.dtd">
<suite thread-count="4" name="Default Suite" parallel="tests">
  <listeners>
    <listener class-name="com.WebDriverListener"/>
  </listeners>
  <test name="test">
    <parameter name="browserName" value="*firefox"/>
    <classes>
      <class name="com.testcases_name"/>
    </classes>
  </test> 
</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: Updating testng xml at runtime or Option to run OS/Browser combination given in test method!

Krishnan Mahadevan

Please upgrade to TestNG 6.11 and try plugging in your implementation into the implementation of org.testng.IAlterSuiteListener inside of

 

void alter(List<XmlSuite> suites) {

   // Your code goes here

}

 

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 Shylu Arji <[hidden email]>
Reply-To: <[hidden email]>
Date: Saturday, June 10, 2017 at 4:31 AM
To: testng-users <[hidden email]>
Subject: [testng-users] Re: Updating testng xml at runtime or Option to run OS/Browser combination given in test method!

 

@Sasi Kumar,

 

Where u abel to solve this problem?

I am facing similar issue.

 

Below is the snippet of testng xml file

<parameter name="TestPlan" value="sampleTestPlan" />

<parameter name="testCase" value="sampleTestCase" />

 

            <test name="ShopCaSeRegression">

                        <classes>

                                    <class name=""> // sampleTestPlan should be here

                                    <methods>

                                                <include name=""></include> //sampleTestCase should be here

                                    </methods>

                                    </class>

                        </classes>

            </test>

 

i am trying to pass testPlanname and test case name that i get as jenkins parameters inside the class and includes when test starts.

 

I tried using both suiteListener and testListener .

 

code snippet

public void onStart(ISuite suite) {
    Map<String, String> parameters = suite.getXmlSuite().getParameters();
   
for (Map.Entry<String, String> parameter : parameters.entrySet()) {
        String env = System.getenv(parameter.getKey());
       
if (env != null && ! env.trim().isEmpty()) {
            parameter.setValue(env);
        }
    }

    String testPlan =
null;
    String testCase =
null;
    Map<String, String> suitParameters = suite.getXmlSuite().getParameters();
   
for (Map.Entry<String, String> parameter : suitParameters.entrySet()) {
       
if(parameter.getKey().equalsIgnoreCase("TestPlan"))
            testPlan =  parameter.getValue();
       
if(parameter.getKey().equalsIgnoreCase("TestCase"))
            testCase = parameter.getValue();
    }

    List<XmlTest> allTests = suite.getXmlSuite().getTests();
    XmlTest oneTest =
new XmlTest();
    XmlClass oneTestClass =
new XmlClass();
    XmlInclude includedMethod =
new XmlInclude();
    List<XmlInclude> allIncludedMethods = oneTestClass.getIncludedMethods();
    oneTestClass.setName(testPlan);
    includedMethod.addParameter(testCase,
"");
    allIncludedMethods.add(includedMethod);
    oneTestClass.setIncludedMethods(allIncludedMethods);
    oneTest.getClasses().add(oneTestClass);
    allTests.add(oneTest);
    suite.getXmlSuite().setTests(allTests);
   
}
 
In debug mode i see that this method is executed, but my suite is not updated and the expected test is not run.
Any help appreciated.
 
Thanks!


On Thursday, August 13, 2015 at 10:57:35 PM UTC-7, Sasi kumar wrote:

scenario : 

 

i) Iam create testng.xml at runtime before test starts ,that is before testng is started .

ii) Will have what all os,browsers has to be tested for an test method ,inside my test method .Say (linux,firefox) , (mac,safari).

 

What iam trying is,

 

Using listener  @Before method iam getting browser, os parameter from xml and initiate the driver. Now from test method i want to update the testng.xml with parameters given by user.

 

Or is there any other way to do it?

 

Note : i can't pre create with all OS/Browser combination as some test may not have all combinations.

 

Sample :

 

 @BeforeMethod

    public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {

        if (method.isTestMethod()) {

            

            

                    browserName = method.getTestMethod().getXmlTest().getLocalParameters().get("browserName");

            

            driver = LocalDriverFactory.createInstance(browserName);

                                LocalDriverManager.setWebDriver(driver);

       

        }

    }

 

 

XML :

 

 

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

<suite thread-count="4" name="Default Suite" parallel="tests">

  <listeners>

    <listener class-name="com.WebDriverListener"/>

  </listeners>

  <test name="test">

    <parameter name="browserName" value="*firefox"/>

    <classes>

      <class name="com.testcases_name"/>

    </classes>

  </test> 

</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...