Passing external values to testng.run method

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

Passing external values to testng.run method

Jayakrishnan Nair
Hi 
     I am running testng programmatically and I want to pass some values in testng.run() method so that can be used by test. Below is the code for the same.

public class MeetingMasterExecutor implements Runnable {

@Override
public void run() {
TestNG tng = new TestNG();
    List<XmlSuite> suiteslist = new ArrayList<XmlSuite>();        
       List<XmlTest> testlist  = new ArrayList<XmlTest>();
       List<XmlClass> classeslist = new ArrayList<XmlClass>();
           
       XmlSuite suite = new XmlSuite();
       suite.setName("MeetinMaster");
 
       XmlTest test = new XmlTest(suite);
       test.setName("MeetinMaster");
      
 
       XmlClass clss1 = new XmlClass(MeetingMaster.class.getName());
       clss1.setName("MeetingMasterClass");
       classeslist.add(clss1);
       test.setXmlClasses(classeslist);
       testlist.add(test);
       suite.setTests(testlist);
       suiteslist.add(suite);
       tng.setXmlSuites(suiteslist);
       tng.run();
   }

public static void main(String args[]) throws InterruptedException{
/* Paramater 
* 1st Parameter - Test Class Name
* 2nd Parameter - ThreadPool Size
* 3rd Parameter - SuiteName
* 4th Parameter - Time to Run
* */
// String ClassName  =  args[0];
 String Threadpoolsize =  args[0];
 String SuiteName =  args[1];
 String TimeToRun = args[2];
 System.out.println(Threadpoolsize+"   "+SuiteName+"   "+TimeToRun+"   ");
// ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(Integer.parseInt(Threadpoolsize));

long startTime = System.currentTimeMillis();
long TimeDuration1 =  Integer.parseInt(TimeToRun)*60*1000;
int j =0;
int iterations = Integer.parseInt(TimeToRun);
int size = Integer.parseInt(Threadpoolsize);
ThreadFactory threadFactory = Executors.defaultThreadFactory();
       //creating the ThreadPoolExecutor
Map<String,String> Configdata =  ConfigurationData.getInstance().getconfigData();  // ( I want to pass this Map to testng.run())

       ThreadPoolExecutor executorPool = new ThreadPoolExecutor((size), (size), 180, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(size), threadFactory);
while(j<=iterations){
if(executorPool.getActiveCount()<=(size)){
 
  executorPool.execute(new MeetingMasterExecutor());
  j++;
}
}
executorPool.shutdown();
}

--
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: Passing external values to testng.run method

Krishnan Mahadevan
What exactly is your question ? Can you please help clarify ?

Oh btw, when TestNG by itself is a manager of threadpools etc., why would you want TestNG to be by itself included within another thread ?

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 Wed, Jun 21, 2017 at 9:27 AM, Jayakrishnan Nair <[hidden email]> wrote:
Hi 
     I am running testng programmatically and I want to pass some values in testng.run() method so that can be used by test. Below is the code for the same.

public class MeetingMasterExecutor implements Runnable {

@Override
public void run() {
TestNG tng = new TestNG();
    List<XmlSuite> suiteslist = new ArrayList<XmlSuite>();        
       List<XmlTest> testlist  = new ArrayList<XmlTest>();
       List<XmlClass> classeslist = new ArrayList<XmlClass>();
           
       XmlSuite suite = new XmlSuite();
       suite.setName("MeetinMaster");
 
       XmlTest test = new XmlTest(suite);
       test.setName("MeetinMaster");
      
 
       XmlClass clss1 = new XmlClass(MeetingMaster.class.getName());
       clss1.setName("MeetingMasterClass");
       classeslist.add(clss1);
       test.setXmlClasses(classeslist);
       testlist.add(test);
       suite.setTests(testlist);
       suiteslist.add(suite);
       tng.setXmlSuites(suiteslist);
       tng.run();
   }

public static void main(String args[]) throws InterruptedException{
/* Paramater 
* 1st Parameter - Test Class Name
* 2nd Parameter - ThreadPool Size
* 3rd Parameter - SuiteName
* 4th Parameter - Time to Run
* */
// String ClassName  =  args[0];
 String Threadpoolsize =  args[0];
 String SuiteName =  args[1];
 String TimeToRun = args[2];
 System.out.println(Threadpoolsize+"   "+SuiteName+"   "+TimeToRun+"   ");
// ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(Integer.parseInt(Threadpoolsize));

long startTime = System.currentTimeMillis();
long TimeDuration1 =  Integer.parseInt(TimeToRun)*60*1000;
int j =0;
int iterations = Integer.parseInt(TimeToRun);
int size = Integer.parseInt(Threadpoolsize);
ThreadFactory threadFactory = Executors.defaultThreadFactory();
       //creating the ThreadPoolExecutor
Map<String,String> Configdata =  ConfigurationData.getInstance().getconfigData();  // ( I want to pass this Map to testng.run())

       ThreadPoolExecutor executorPool = new ThreadPoolExecutor((size), (size), 180, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(size), threadFactory);
while(j<=iterations){
if(executorPool.getActiveCount()<=(size)){
 
  executorPool.execute(new MeetingMasterExecutor());
  j++;
}
}
executorPool.shutdown();
}

--
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Passing external values to testng.run method

Jayakrishnan Nair
Hi Krishnan,
                     I am trying read a CSV file and collect data into a map. This map, I will pass into the dataprovider of entire test suite I want to run.  I am running a single Test Suite using testng.run and I want to run the same Suite in parallel. For this purpose I am using java threadpool. Want I understand from the TestNG documentation that there is no support for providing single dataset for the entire suite. I may be wrong about it, if it is possible I would like to learn more about that. 

Hope this clarifies my need to pass data to testng.run() method.

Thanks
Jayakrishnan Nair
 

On Wednesday, June 21, 2017 at 10:19:51 AM UTC+5:30, Krishnan wrote:
What exactly is your question ? Can you please help clarify ?

Oh btw, when TestNG by itself is a manager of threadpools etc., why would you want TestNG to be by itself included within another thread ?

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\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_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\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

On Wed, Jun 21, 2017 at 9:27 AM, Jayakrishnan Nair <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="Pc53VMDEAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jai12...@...> wrote:
Hi 
     I am running testng programmatically and I want to pass some values in testng.run() method so that can be used by test. Below is the code for the same.

public class MeetingMasterExecutor implements Runnable {

@Override
public void run() {
TestNG tng = new TestNG();
    List<XmlSuite> suiteslist = new ArrayList<XmlSuite>();        
       List<XmlTest> testlist  = new ArrayList<XmlTest>();
       List<XmlClass> classeslist = new ArrayList<XmlClass>();
           
       XmlSuite suite = new XmlSuite();
       suite.setName("MeetinMaster");
 
       XmlTest test = new XmlTest(suite);
       test.setName("MeetinMaster");
      
 
       XmlClass clss1 = new XmlClass(MeetingMaster.class.getName());
       clss1.setName("MeetingMasterClass");
       classeslist.add(clss1);
       test.setXmlClasses(classeslist);
       testlist.add(test);
       suite.setTests(testlist);
       suiteslist.add(suite);
       tng.setXmlSuites(suiteslist);
       tng.run();
   }

public static void main(String args[]) throws InterruptedException{
/* Paramater 
* 1st Parameter - Test Class Name
* 2nd Parameter - ThreadPool Size
* 3rd Parameter - SuiteName
* 4th Parameter - Time to Run
* */
// String ClassName  =  args[0];
 String Threadpoolsize =  args[0];
 String SuiteName =  args[1];
 String TimeToRun = args[2];
 System.out.println(Threadpoolsize+"   "+SuiteName+"   "+TimeToRun+"   ");
// ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(Integer.parseInt(Threadpoolsize));

long startTime = System.currentTimeMillis();
long TimeDuration1 =  Integer.parseInt(TimeToRun)*60*1000;
int j =0;
int iterations = Integer.parseInt(TimeToRun);
int size = Integer.parseInt(Threadpoolsize);
ThreadFactory threadFactory = Executors.defaultThreadFactory();
       //creating the ThreadPoolExecutor
Map<String,String> Configdata =  ConfigurationData.getInstance().getconfigData();  // ( I want to pass this Map to testng.run())

       ThreadPoolExecutor executorPool = new ThreadPoolExecutor((size), (size), 180, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(size), threadFactory);
while(j<=iterations){
if(executorPool.getActiveCount()<=(size)){
 
  executorPool.execute(new MeetingMasterExecutor());
  j++;
}
}
executorPool.shutdown();
}

--
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="Pc53VMDEAwAJ" 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="Pc53VMDEAwAJ" 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="https://groups.google.com/group/testng-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://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 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: Passing external values to testng.run method

Krishnan Mahadevan

Jayakrishnan,

 

The data provider that’s tied to a test method and which is part of a suite will already do this no?

I still didn’t understand what you meant by “There is no support for providing single data set for the entire suite”. Are you trying to do the following ?

 

My data provider has 5 rows. I have 5 suites. I want TestNG to pick one row of data from my data provider, pass it to the first suite, and repeat the same thing to all the suites and I also want TestNG to run all the suites in parallel at the same time.

 

Is this a fair understanding of your problem statement ?

If yes, then here’s how you can do this programmatically.

 

Every suite can basically have attributes which can be set via org.testng.xml.XmlSuite#setParameters (since you are already having a reference to the XmlSuite). But you may still have a problem here, because the XmlSuite has more than 1 XmlTest and each XmlTest would have one or more XmlClass and every XmlClass has one or more @Test annotated test methods.

 

So what is the value that each of the @Test method would basically take and read ?

 

On a side note, since the setParameters takes a key/value pair, and since your value is actually a map, you may have to transform your map into a JSON or something which you can set to the key.

 

 

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 Jayakrishnan Nair <[hidden email]>
Reply-To: <[hidden email]>
Date: Thursday, June 22, 2017 at 1:41 AM
To: testng-users <[hidden email]>
Subject: Re: [testng-users] Passing external values to testng.run method

 

Hi Krishnan,

                     I am trying read a CSV file and collect data into a map. This map, I will pass into the dataprovider of entire test suite I want to run.  I am running a single Test Suite using testng.run and I want to run the same Suite in parallel. For this purpose I am using java threadpool. Want I understand from the TestNG documentation that there is no support for providing single dataset for the entire suite. I may be wrong about it, if it is possible I would like to learn more about that. 

 

Hope this clarifies my need to pass data to testng.run() method.

 

Thanks

Jayakrishnan Nair

 


On Wednesday, June 21, 2017 at 10:19:51 AM UTC+5:30, Krishnan wrote:

What exactly is your question ? Can you please help clarify ?

 

Oh btw, when TestNG by itself is a manager of threadpools etc., why would you want TestNG to be by itself included within another thread ?


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 Wed, Jun 21, 2017 at 9:27 AM, Jayakrishnan Nair <<a href="javascript:" target="_blank">jai12...@...> wrote:

Hi 

     I am running testng programmatically and I want to pass some values in testng.run() method so that can be used by test. Below is the code for the same.

 

public class MeetingMasterExecutor implements Runnable {

 

@Override

public void run() {

TestNG tng = new TestNG();

    List<XmlSuite> suiteslist = new ArrayList<XmlSuite>();        

       List<XmlTest> testlist  = new ArrayList<XmlTest>();

       List<XmlClass> classeslist = new ArrayList<XmlClass>();

           

       XmlSuite suite = new XmlSuite();

       suite.setName("MeetinMaster");

 

       XmlTest test = new XmlTest(suite);

       test.setName("MeetinMaster");

      

 

       XmlClass clss1 = new XmlClass(MeetingMaster.class.getName());

       clss1.setName("MeetingMasterClass");

       classeslist.add(clss1);

       test.setXmlClasses(classeslist);

       testlist.add(test);

       suite.setTests(testlist);

       suiteslist.add(suite);

       tng.setXmlSuites(suiteslist);

       tng.run();

   }

 

public static void main(String args[]) throws InterruptedException{

/* Paramater 

* 1st Parameter - Test Class Name

* 2nd Parameter - ThreadPool Size

* 3rd Parameter - SuiteName

* 4th Parameter - Time to Run

* */

// String ClassName  =  args[0];

 String Threadpoolsize =  args[0];

 String SuiteName =  args[1];

 String TimeToRun = args[2];

 System.out.println(Threadpoolsize+"   "+SuiteName+"   "+TimeToRun+"   ");

// ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(Integer.parseInt(Threadpoolsize));

 

long startTime = System.currentTimeMillis();

long TimeDuration1 =  Integer.parseInt(TimeToRun)*60*1000;

int j =0;

int iterations = Integer.parseInt(TimeToRun);

int size = Integer.parseInt(Threadpoolsize);

ThreadFactory threadFactory = Executors.defaultThreadFactory();

       //creating the ThreadPoolExecutor

Map<String,String> Configdata =  ConfigurationData.getInstance().getconfigData();  // ( I want to pass this Map to testng.run())

 

       ThreadPoolExecutor executorPool = new ThreadPoolExecutor((size), (size), 180, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(size), threadFactory);

while(j<=iterations){

if(executorPool.getActiveCount()<=(size)){

 

  executorPool.execute(new MeetingMasterExecutor());

  j++;

}

}

executorPool.shutdown();

}

 

--
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">testng-users...@....
To post to this group, send email to <a href="javascript:" target="_blank">testng...@....
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.

--
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: Passing external values to testng.run method

Jayakrishnan Nair
Hi Krishnan,
                  Sorry for the late reply, as you had mentioned "My data provider has 5 rows. I have 5 suites. I want TestNG to pick one row of data from my data provider, pass it to the first suite, and repeat the same thing to all the suites and I also want TestNG to run all the suites in parallel at the same time."

My case is similar but I have 5 rows and 1 single suite. I want to run the single suite with 5 different rows in parallel.

I am able to use threadpool and run same suite with 5 different rows, but I am unable to save HAR object to mongo database.
Another issue is starting browsermobproxy on remote machine programmatically.


Thanks

Jayakrishnan Nair



On Thursday, June 22, 2017 at 9:16:39 AM UTC+5:30, Krishnan wrote:

Jayakrishnan,

 

The data provider that’s tied to a test method and which is part of a suite will already do this no?

I still didn’t understand what you meant by “There is no support for providing single data set for the entire suite”. Are you trying to do the following ?

 

My data provider has 5 rows. I have 5 suites. I want TestNG to pick one row of data from my data provider, pass it to the first suite, and repeat the same thing to all the suites and I also want TestNG to run all the suites in parallel at the same time.

 

Is this a fair understanding of your problem statement ?

If yes, then here’s how you can do this programmatically.

 

Every suite can basically have attributes which can be set via org.testng.xml.XmlSuite#setParameters (since you are already having a reference to the XmlSuite). But you may still have a problem here, because the XmlSuite has more than 1 XmlTest and each XmlTest would have one or more XmlClass and every XmlClass has one or more @Test annotated test methods.

 

So what is the value that each of the @Test method would basically take and read ?

 

On a side note, since the setParameters takes a key/value pair, and since your value is actually a map, you may have to transform your map into a JSON or something which you can set to the key.

 

 

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\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_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\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

 

From: <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="pS_FEuIPBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@...> on behalf of Jayakrishnan Nair <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="pS_FEuIPBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jai12...@...>
Reply-To: <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="pS_FEuIPBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@...>
Date: Thursday, June 22, 2017 at 1:41 AM
To: testng-users <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="pS_FEuIPBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@...>
Subject: Re: [testng-users] Passing external values to testng.run method

 

Hi Krishnan,

                     I am trying read a CSV file and collect data into a map. This map, I will pass into the dataprovider of entire test suite I want to run.  I am running a single Test Suite using testng.run and I want to run the same Suite in parallel. For this purpose I am using java threadpool. Want I understand from the TestNG documentation that there is no support for providing single dataset for the entire suite. I may be wrong about it, if it is possible I would like to learn more about that. 

 

Hope this clarifies my need to pass data to testng.run() method.

 

Thanks

Jayakrishnan Nair

 


On Wednesday, June 21, 2017 at 10:19:51 AM UTC+5:30, Krishnan wrote:

What exactly is your question ? Can you please help clarify ?

 

Oh btw, when TestNG by itself is a manager of threadpools etc., why would you want TestNG to be by itself included within another thread ?


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\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_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\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

 

On Wed, Jun 21, 2017 at 9:27 AM, Jayakrishnan Nair <[hidden email]> wrote:

Hi 

     I am running testng programmatically and I want to pass some values in testng.run() method so that can be used by test. Below is the code for the same.

 

public class MeetingMasterExecutor implements Runnable {

 

@Override

public void run() {

TestNG tng = new TestNG();

    List<XmlSuite> suiteslist = new ArrayList<XmlSuite>();        

       List<XmlTest> testlist  = new ArrayList<XmlTest>();

       List<XmlClass> classeslist = new ArrayList<XmlClass>();

           

       XmlSuite suite = new XmlSuite();

       suite.setName("MeetinMaster");

 

       XmlTest test = new XmlTest(suite);

       test.setName("MeetinMaster");

      

 

       XmlClass clss1 = new XmlClass(MeetingMaster.class.getName());

       clss1.setName("MeetingMasterClass");

       classeslist.add(clss1);

       test.setXmlClasses(classeslist);

       testlist.add(test);

       suite.setTests(testlist);

       suiteslist.add(suite);

       tng.setXmlSuites(suiteslist);

       tng.run();

   }

 

public static void main(String args[]) throws InterruptedException{

/* Paramater 

* 1st Parameter - Test Class Name

* 2nd Parameter - ThreadPool Size

* 3rd Parameter - SuiteName

* 4th Parameter - Time to Run

* */

// String ClassName  =  args[0];

 String Threadpoolsize =  args[0];

 String SuiteName =  args[1];

 String TimeToRun = args[2];

 System.out.println(Threadpoolsize+"   "+SuiteName+"   "+TimeToRun+"   ");

// ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(Integer.parseInt(Threadpoolsize));

 

long startTime = System.currentTimeMillis();

long TimeDuration1 =  Integer.parseInt(TimeToRun)*60*1000;

int j =0;

int iterations = Integer.parseInt(TimeToRun);

int size = Integer.parseInt(Threadpoolsize);

ThreadFactory threadFactory = Executors.defaultThreadFactory();

       //creating the ThreadPoolExecutor

Map<String,String> Configdata =  ConfigurationData.getInstance().getconfigData();  // ( I want to pass this Map to testng.run())

 

       ThreadPoolExecutor executorPool = new ThreadPoolExecutor((size), (size), 180, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(size), threadFactory);

while(j<=iterations){

if(executorPool.getActiveCount()<=(size)){

 

  executorPool.execute(new MeetingMasterExecutor());

  j++;

}

}

executorPool.shutdown();

}

 

--
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="https://groups.google.com/group/testng-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="pS_FEuIPBAAJ" 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="pS_FEuIPBAAJ" 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="https://groups.google.com/group/testng-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://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 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: Passing external values to testng.run method

Krishnan Mahadevan

That would essentially equate you to doing the following:

 

  • Upgrade to the latest released version of TestNG
  • Build an implementation of org.testng.IAlterSuiteListener wherein for the current <suite> you create “n” number of <test> tags (every <test> tag represents a <test> that has parameters obtained from one set of data from your data provider)
  • Your actual suite would never contain any <test> entries but just a reference to the above created listener.

 

That way, you fall back to TestNG for managing everything and you don’t have to fiddle around with managing thread pools etc.,

 

>>> Unable to save HAR object to Mongo DB

This would be a separate issue that is outside of the scope of TestNG.

 

>>> Cannot start BMP on a remote machine programmatically.

AFAIK, you can never do this! Programatically starting a server (be it BMP or the selenium grid or anything else) is all confined to local machines only. When it comes to a remote machine, you are talking about a different JVM. Java cannot start a new JVM in a remote machine without you using “java –jar” command and then interacting with the remote machine using “ssh”.

On a side note, you don’t need this at all, because BMP lets you create and destroy proxy instances via its rest calls. So the server would always be running on one remote machine, but your tests could request for a proxy instance by invoking the RestCall, working with that proxy instance, and once its purpose is done, you destroy the instance via the rest calls.

 

 

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 Jayakrishnan Nair <[hidden email]>
Reply-To: <[hidden email]>
Date: Wednesday, June 28, 2017 at 4:35 PM
To: testng-users <[hidden email]>
Subject: Re: [testng-users] Passing external values to testng.run method

 

Hi Krishnan,
                  Sorry for the late reply, as you had mentioned "My data provider has 5 rows. I have 5 suites. I want TestNG to pick one row of data from my data provider, pass it to the first suite, and repeat the same thing to all the suites and I also want TestNG to run all the suites in parallel at the same time."

My case is similar but I have 5 rows and 1 single suite. I want to run the single suite with 5 different rows in parallel.

I am able to use threadpool and run same suite with 5 different rows, but I am unable to save HAR object to mongo database.
Another issue is starting browsermobproxy on remote machine programmatically.


Thanks
Jayakrishnan Nair


On Thursday, June 22, 2017 at 9:16:39 AM UTC+5:30, Krishnan wrote:

Jayakrishnan,

 

The data provider that’s tied to a test method and which is part of a suite will already do this no?

I still didn’t understand what you meant by “There is no support for providing single data set for the entire suite”. Are you trying to do the following ?

 

My data provider has 5 rows. I have 5 suites. I want TestNG to pick one row of data from my data provider, pass it to the first suite, and repeat the same thing to all the suites and I also want TestNG to run all the suites in parallel at the same time.

 

Is this a fair understanding of your problem statement ?

If yes, then here’s how you can do this programmatically.

 

Every suite can basically have attributes which can be set via org.testng.xml.XmlSuite#setParameters (since you are already having a reference to the XmlSuite). But you may still have a problem here, because the XmlSuite has more than 1 XmlTest and each XmlTest would have one or more XmlClass and every XmlClass has one or more @Test annotated test methods.

 

So what is the value that each of the @Test method would basically take and read ?

 

On a side note, since the setParameters takes a key/value pair, and since your value is actually a map, you may have to transform your map into a JSON or something which you can set to the key.

 

 

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: <<a href="javascript:" target="_blank">testng...@...> on behalf of Jayakrishnan Nair <<a href="javascript:" target="_blank">jai12...@...>
Reply-To: <<a href="javascript:" target="_blank">testng...@...>
Date: Thursday, June 22, 2017 at 1:41 AM
To: testng-users <<a href="javascript:" target="_blank">testng...@...>
Subject: Re: [testng-users] Passing external values to testng.run method

 

Hi Krishnan,

                     I am trying read a CSV file and collect data into a map. This map, I will pass into the dataprovider of entire test suite I want to run.  I am running a single Test Suite using testng.run and I want to run the same Suite in parallel. For this purpose I am using java threadpool. Want I understand from the TestNG documentation that there is no support for providing single dataset for the entire suite. I may be wrong about it, if it is possible I would like to learn more about that. 

 

Hope this clarifies my need to pass data to testng.run() method.

 

Thanks

Jayakrishnan Nair

 


On Wednesday, June 21, 2017 at 10:19:51 AM UTC+5:30, Krishnan wrote:

What exactly is your question ? Can you please help clarify ?

 

Oh btw, when TestNG by itself is a manager of threadpools etc., why would you want TestNG to be by itself included within another thread ?


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 Wed, Jun 21, 2017 at 9:27 AM, Jayakrishnan Nair <[hidden email]> wrote:

Hi 

     I am running testng programmatically and I want to pass some values in testng.run() method so that can be used by test. Below is the code for the same.

 

public class MeetingMasterExecutor implements Runnable {

 

@Override

public void run() {

TestNG tng = new TestNG();

    List<XmlSuite> suiteslist = new ArrayList<XmlSuite>();        

       List<XmlTest> testlist  = new ArrayList<XmlTest>();

       List<XmlClass> classeslist = new ArrayList<XmlClass>();

           

       XmlSuite suite = new XmlSuite();

       suite.setName("MeetinMaster");

 

       XmlTest test = new XmlTest(suite);

       test.setName("MeetinMaster");

      

 

       XmlClass clss1 = new XmlClass(MeetingMaster.class.getName());

       clss1.setName("MeetingMasterClass");

       classeslist.add(clss1);

       test.setXmlClasses(classeslist);

       testlist.add(test);

       suite.setTests(testlist);

       suiteslist.add(suite);

       tng.setXmlSuites(suiteslist);

       tng.run();

   }

 

public static void main(String args[]) throws InterruptedException{

/* Paramater 

* 1st Parameter - Test Class Name

* 2nd Parameter - ThreadPool Size

* 3rd Parameter - SuiteName

* 4th Parameter - Time to Run

* */

// String ClassName  =  args[0];

 String Threadpoolsize =  args[0];

 String SuiteName =  args[1];

 String TimeToRun = args[2];

 System.out.println(Threadpoolsize+"   "+SuiteName+"   "+TimeToRun+"   ");

// ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(Integer.parseInt(Threadpoolsize));

 

long startTime = System.currentTimeMillis();

long TimeDuration1 =  Integer.parseInt(TimeToRun)*60*1000;

int j =0;

int iterations = Integer.parseInt(TimeToRun);

int size = Integer.parseInt(Threadpoolsize);

ThreadFactory threadFactory = Executors.defaultThreadFactory();

       //creating the ThreadPoolExecutor

Map<String,String> Configdata =  ConfigurationData.getInstance().getconfigData();  // ( I want to pass this Map to testng.run())

 

       ThreadPoolExecutor executorPool = new ThreadPoolExecutor((size), (size), 180, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(size), threadFactory);

while(j<=iterations){

if(executorPool.getActiveCount()<=(size)){

 

  executorPool.execute(new MeetingMasterExecutor());

  j++;

}

}

executorPool.shutdown();

}

 

--
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 <a href="javascript:" target="_blank">testng-users...@....
To post to this group, send email to <a href="javascript:" target="_blank">testng...@....
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.

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