0

Actual - The behavior I see is that it runs all the tests in the class sequentially one session (FireFox browser) at a time on 1 node.

Expected - The class in this example "IntegrationTest" has 20 methods(@Test). I expect to see 5 tests in the class getting picked up, and run in parallel in 5 FireFox sessions on the 1 node.

Here's my testng suite file. Having thread-count as 1 makes sense as there's only 1 class I want to run.

<suite name="WebDriver Tests" parallel="classes" thread-count="1">
<test name="WebDriver Tests">
    <classes>
        <class name = "com.axiom.web.IntegrationTest" />
    </classes>
</test>

And here's the grid2 commands that I run on the hub and the node.

Hub command -

java -jar selenium-server-standalone-2.43.0.jar -role hub -browserTimeout 60

Node command -

java -jar selenium-server-standalone-2.43.0.jar -role node  -hub http://<host ip address>:4444/grid/register

Am I missing something here? What do I have to do to get maxSession work as it should? I believe maxSession takes precedence over maxInstances, but either way, specifying none, both or either in the node command didn't work for me. I am on Selenium version 2.43.1 and testng version 6.8.8.

Thanks and appreciate the help!

testphreak
  • 489
  • 5
  • 16

2 Answers2

0
  1. You need to configure the node with the number of FF sessions you want it to support.

See "Configuring the nodes" on this page - https://code.google.com/p/selenium/wiki/Grid2

  1. You need to increase the thread-count in the testng suite file and specify that you want parallel="methods".

parallel="classes" and thread-count=1 means you want one total thread and that you want all methods in each class to run on the same thread. parallel="methods" means you want each method to have it's own thread. However, a single thread won't accomplish what you want, so you need to add more total threads.

Documentation for thread-count and the parallel setting is here - http://testng.org/doc/documentation-main.html#parallel-running

Doug Simmons
  • 458
  • 3
  • 8
  • parallel="methods" isn't possible in my case, as I don't instantiate a new driver in each test method but do it in the BaseTest, which means the driver is instantiated on a per class basis instead. I have tried previously with parallel="classes" and thread-count=12 with 4 active nodes, but it still doesn't seem to run 5 sessions in parallel on each node (maxSession in grid by default is 5). Perhaps the maxSession value only works when you have your suite file run tests parallel by methods and not parallel by classes. – testphreak Sep 24 '14 at 17:09
  • It doesn't matter how many threads you throw at it. If you have one test class and are running parallel=classes, then only one thread will be used. – Doug Simmons Sep 24 '14 at 21:52
  • Thanks. So say I have 5 test classes and have parallel="classes" and thread-count 5, what is the behavior of maxSession in this case? My expectation is that it should start tests on 5 Firefox browsers in parallel on the node running the tests. – testphreak Sep 24 '14 at 22:28
  • As long as you are properly managing your WebDriver instances to allow for parallelism, that is what I would expect to see too. Keep in mind TestNG and Selenium are two separate products -- meaning configuration in one does not influence behavior in the other. It's up to you to make them cooperate per your needs. – Doug Simmons Sep 24 '14 at 22:39
0

I will recommend you that add @BeforeMethod and have multiple driver instances being initialized in @BeforeMethod if you want to run in 5 browsers you will have to open 5 browsers i.e create 5 driver instances yourself in @BeforeMethod. Let me know if you need further help.

Mrunal Gosar
  • 4,595
  • 13
  • 48
  • 71
  • Hey Mrunal, thanks. I'm looking at a couple of possible solutions. Does your solution involve using ThreadLocal? Something like this... List drivers = threadLocalDriver.get(); – testphreak Sep 30 '14 at 05:32
  • Try this : http://stackoverflow.com/questions/19067885/static-webdriver-instance-synchronization-in-java – Mrunal Gosar Sep 30 '14 at 16:37