0

Consider following example code:

public class testcases()
{
 @Before method
 public void setup()
 {
  -----------
  some code
  -----------
 }

  @Test
  public void test1()
  {
   ---------- some code-----
  }

  @Test
  public void test2()
  {
   ---------- some code-----
  }

 @After method
 public void setup()
 {
  -----------
  some code
  -----------
 }
 }

Now i will a create hub and launch 2 firefox nodes. i want the method test1() to run in one firefox node and the method test2() in another firefox node. Please let me know how to configure this using testng.xml file

Vikas
  • 669
  • 3
  • 10
  • 21

1 Answers1

0

Basically you want to run your testcases in parallel. In the testng xml in your suite declaration you would need to add parallel="methods". Options for the parallel values include, classes, tests, instances,false.

<suite thread-count="10" verbose="1" parallel="methods" ......>

Make sure your thread-count value is set appropriately, i.e. how many threads should be spawned. The Grid would take care of distribution of the parallel tests. Thing that you need to watch out for is make sure your driver object is different for each thread for the commands to go to proper driver object.

niharika_neo
  • 8,441
  • 1
  • 19
  • 31
  • Hi, i have implemented the above line in my testng.xml code and it's working fine. Thanks for your help :) – Vikas Feb 18 '13 at 08:37
  • if i run the scripts using parallel="classes" or "methods".. scripts are running like charm and correctly..... But when i am using parallel="methods", operations are not performing as expected. i.e., some operations of different methods are performing on one browser it self and on other browsers some operations are not performing.... why there will be a difference when i am running with parallel=""methods"? while scripts are running fine with parallel="tests" or "classes".. please let me know any thing need to be added while initializing the driver. i am not using static variable – Vikas Feb 18 '13 at 14:31
  • Do u hv a static in all ur classes? – niharika_neo Feb 18 '13 at 15:49
  • ya i am using static for some generic wait methods and also for some generic user actions like click,type,dropdown etc... while using grid we shouldn't use static keyword in entire script?... Right now i am not using static till the initialization of driver. But for other methods in my script i am using static keyword. Please suggest – Vikas Feb 18 '13 at 17:37
  • Also i am getting this exception very frequently org.openqa.selenium.remote.SessionNotFoundException: Session ID is null while running using parallel="methods"..... this exception is not coming while running using parallel="tests" or "classes" – Vikas Feb 19 '13 at 05:13
  • http://stackoverflow.com/questions/14874494/testng-selenium-grid-2-not-running-tests-in-parallel/14941180#14941180 - Look at this thread. The issue is with static driver initialization, in which case there is only one instance on which all your cases run. You should have your driver object either inside your test or use ThreadLocal so that each thread has its own copy.. – niharika_neo Feb 19 '13 at 05:25
  • i have wrote a sample grid code in following google docs link: https://docs.google.com/document/d/19oUG-mrR92x-Sz6sXlC9kWw9b8Iw0wwIp9I1RuaIw0Y/edit Observe that while running the code without static also i am getting same exception i.e., org.openqa.selenium.remote.SessionNotFoundException: Session ID is null. i am getting this exception when two or three browsers at a time launch... i am creating a hub and i am adding three firefox nodes to run 3 @test methods as shown in google docs in 3 nodes. Can u please run it at your end and let me know if the code is running fine for u. Thanks – Vikas Feb 20 '13 at 04:57