Selenium Grid Nodes to the Rescue for Automated Testing

In the never-ending game of application vs. automation, applications always seem to try to have functionalities that can’t be automated. The challenge that led me to create this solution – and write this blog post – arose out of one such instance.

Let the story begin with this case study:

Suppose you have a scenario that asks a tester to verify certain content which depends on the tester’s current geographical location. What if you have to test any such test case as written below:

Verify that the dropdown under the text “I want my complementary fitness session in ____” shows user’s nearest health club based on his/her geographical location.

One way (the easiest one) to overcome the problem in testing such a scenario is to mark this as “Manual,” but this will give opponents of manual testing a lead. Let’s not give them an easy breakthrough. So, we opted for the slightly tricky automated test in Chrome (though it is not so flexible, anyways its flexibility is not the scope of this blog).

  • Create a new Chrome profile.
  • Add the location mocking plug in to it, like, I used manual Geolocation.
  • Save this profile and use this profile for your automation.

Solution:

Even if we are concerned about this solution not being flexible, there was another challenge of implementing this solution on a distributed automation infrastructure like Selenium Grid. The solution will only work if each node has that particular Chrome profile. Sure, we can have this – but after each execution the profile gets bulkier (obviously, because of adding cache/cookies and other browser history elements). In order to overcome this problem, there has to be a mechanism that flushes the current set of profile copy and creates a clean one for each execution.

Adding SOA to this solution:

Services are unassociated, loosely coupled units of functionality that are self-contained. Each service implements at least one action (like in the above case, creating a fresh copy of the browser profile). The reason for having this architecture is not to load your Selenium framework with such custom logic.

hub

Ingredients and their roles:

Node and client machines: In the current implementation, the nodes have the services deployed on them, where the client sends the request to the service deployed on the node and performs the action.

Hub: This is the normal Selenium hub which interacts with its nodes to run Selenium commands.

Server and Services:In this implementation, the server will be running on all the nodes and certain services will be running on it. These are normal services that are made to do some specific operations. These services will be called and the response will be taken outside the conventional Selenium grid-hub interaction and this implementation will wrap that.

Service building framework: This will create the stub and skeleton around all the methods and help you to create a service around your method. I used Apache CXF. You can follow this link for more details on Apache CXF.

Considering all those above elements, the architecture will look like:

hub

Client Server flow: This flow occurs between Client and Server deployed on the node. Client sends all the commands to the server and the service does the proceedings through the server node flow.

Server node flow: This is a local flow which does all the operation to set up the node.

In our current implementation, the client and hub may be the same machine. So in the above diagram, the client and hub can be merged together to form a single block. As you can see, there is a parallel communication path created between client and node (via server) and hub to node. Now, before starting the Selenium automation cases, you can set up your node to make the prerequisites. The best trait of this approach is that it is a complete SOA and your existing Selenium framework will have minimal LOC changes if you want to set up this implementation. All you have to do is make a call to the service and do your need.

Making a call to service:

For a general CS based architecture, it is one of the simplest things to do. Then, why have I added this segment, Well… there is a small hurdle here – getting the IP of registered nodes. Yes, there is no direct mechanism that Selenium APIs have to get you the list of all registered nodes. So, right now, we are fetching it from grid console (from UI) and we are trying to create a better solution for this.

What else can we achieve using this implementation?

This solution can be scaled up to have numerous benefits:

  • Start or restart and register Selenium node to the hub just by creating and calling a service
  • Doing CRUD operation on a file you want
  • Install or remove a package before your tests
  • The solution is platform independent, so you can use it on any cross-platform combination (Mac/Windows), which is an extremely important trait from the Selenium Grid perspective.

All you have to do is create and deploy your services and call those. Make sure you start the Tomcat (or any other server if you want) at system startup.

Limitations:

Like any other implementation, this also has certain limitations as of now:

  • Like explained above, right now we do not have any mechanism to fetch the IPs of registered nodes so, UI fetching has to be included right now,
  • Hub and Client are two separate entities. So the flow is independent of each other.
Rajeev Mehta

Rajeev Mehta

Module Lead Quality Assurance

Rajeev Mehta is working as a Module Lead Quality Assurance with 3Pillar Global. Rajeev has been deeply involved in designing automation solutions for various industries such Oil and Gas, Insurance, Banking, and also for consumer-based desktop applications for more than 4 years now.

6 Responses to “Selenium Grid Nodes to the Rescue for Automated Testing”
  1. Heera Singh on

    Hi Rajeev,

    This is a great work published. its really helpful when you work in hub nodes Infrastructure.

    Reply
  2. Madhu on

    Hi Rajeev,

    Am trying to Launch Internet Explorer in Selenium Grid in two different nodes and succeeded once launched we need to pass the credentials to Login into the site. When executed the code for the first time the username is not passed into the first node else it getting passed in the second twice…Pls give a appropriate solution.

    Reply
  3. harish on

    hi, i have to read your blog. Your blogs is more Informative. If anyone interested to learn mobile application training in Chennai, please refer this website. ios training in chennai

    Reply
  4. Rohith on

    I am running selenium hub in one machine, let it be hub_machine and I am registering nodes to that hub from machines(m1, m2, m3). I am able to do this part without any problem. Now using the remote web driver I am passing commands from m1, m2, m3 to the hub_machine to invoke the browser on these machines using the below code.

    WebDriver selenium = new RemoteWebDriver(new URL(“http://localhost:4444/wd/hub”), DesiredCapabilities.chrome());

    But when I do this, as three nodes are registered to the hub, hub is creating new session on the first node in the list of available nodes. How do I specify the hub to create a session on particular node?
    Thanks.

    Reply
    • Rajeev Mehta on

      Hi Rohith,
      You can not configure hub to create session on particular node. However, you can set your node to have maxSession as 1, if you do that, sessions will be distributed uniformly.

      Reply
Leave a Reply

Related Posts

Designing the Future & the Future of Work – The I... Martin Wezowski, Chief Designer and Futurist at SAP, shares his thoughts on designing the future and the future of work on this episode of The Innovat...
The 4 Characteristics of a Healthy Digital Product Team Several weeks ago, I found myself engaged in two separate, yet eerily similar, conversations with CEOs struggling to gain the confidence they needed t...
Recapping Fortune Brainstorm Tech – The Innovation Eng... On this episode of The Innovation Engine, David DeWolf and Jonathan Rivers join us to share an overview of all the news that was fit to print at this ...
4 Reasons Everyone is Wrong About Blockchain: Your Guide to ... You know a technology has officially jumped the shark when iced tea companies decide they want in on the action. In case you missed that one, Long Isl...
The Connection Between Innovation & Story On this episode of The Innovation Engine, we'll be looking at the connection between story and innovation. Among the topics we'll cover are why story ...