SUBSCRIBE HERE TO GET POST UPDATES VIA EMAIL :

Delivered by FeedBurner

Running Multiple Nodes Of Selenium Grid On Same Machine To Run WebDriver Test

Earlier we learnt, How to start single node on one machine as described in THIS POST. Now our next question is "can we run multiple selenium grid nodes on same machine?". Answer is yes. Selenium grid allows us to run multiple nodes on same machine. In general, It is not required to run multiple nodes on same machine as we can control number of browsers as described in THIS POST and number of browser sessions in THIS POST. So it is easy to configure one node on one machine and run test on it as per requirements. But still let's see an example of running multiple nodes on same machine.

As you know, Selenium grid node is using port to listen request from hub and send response back. Till now, We have used 5566 port to run node in all previous examples of selenium grid. So if one node is already running on 5566 port and you wants to start 2nd node on same machine then you need to use other post 5567 as we can run only one node per port number. Let's start one hub and 2 nodes on same machine and run tests on both of them.

Start selenium grid hub
Start selenium grid hub as described in THIS POST.

Register selenium grid node 1
Open command prompt and run bellow given command in it to start 1st node. It will configure node 1 to run 2 Firefox and 2 chrome browser instances but max 2 instances at a time.
java -jar selenium-server-standalone-2.52.0.jar -role node -Dwebdriver.ie.driver="D:/IEDriverServer.exe" -Dwebdriver.chrome.driver="D:/chromedriver.exe" -hub http://localhost:4444/grid/register -port 5566 -browser browserName=firefox,maxInstances=2 -browser browserName=chrome,maxInstances=2 -maxSession 2

Register selenium grid node 2
Open another command prompt and run bellow given command in it to start 2nd node. It will configure node 2 to run 2 Firefox and 2 chrome browser instances but max 2 instances at a time.
java -jar selenium-server-standalone-2.52.0.jar -role node -Dwebdriver.ie.driver="D:/IEDriverServer.exe" -Dwebdriver.chrome.driver="D:/chromedriver.exe" -hub http://localhost:4444/grid/register -port 5567 -browser browserName=firefox,maxInstances=2 -browser browserName=chrome,maxInstances=2 -maxSession 2

Check both nodes running properly or not
Now if you access URL : http://localhost:4444/grid/console , It will show you both nodes running on different ports as shown in bellow given image. That means your nodes are registered with hub and ready to use.


Create and run tests on both nodes of grid
We can use test cases of "timeout" test in this example.
  • Create test cases(fillingForm.java and Calc.java) and testng.xml files as described in PREVIOUS POST.
  • un-comment driver.quit(); from both test cases.
Now run tests from testng.xml file. It will launch 4 browsers instances(2 instances on each node) and start executing tests on it.

If you refresh grid console page during test execution, it will show you that 2 sessions are running on node 1 and 2 sessions are running on node 2 as shown in bellow image.


This way we can run multiple nodes on same machine to execute selenium webdriver tests.

Note : I don't know if this is incorrect way but i know it is possible and it runs your tests on both nodes. I tried it and works for me so i have shared this info with you. Let me know if anyone of you face any issue in this combination.

1 comment:

  1. Hi,
    This is working fine, but when two user logged in on the same machine with below setup....its not working...Could you please check this...

     Hub – On User A
     Node – On User A & B both.

    So when we try to run test its not able to start the browser.

    Error: Unable to create new remote session. desired capabilities = Capabilities [{browserName=internet explorer, version=, platform=WINDOWS}], required capabilities = Capabilities [{}] Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700' System info: host: 'SANDBOX0654', ip: '10.194.10.111', os.name: 'Windows Server 2012 R2', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_74' Driver info: driver.version: InternetExplorerDriver (33)

    ReplyDelete