Setting up a Selenium Grid

Watch this video to learn how to setup a Selenium Grid and use it from LEAPWORK.

In this video

  • Overview of Selenium Grid and LEAPWORK
  • Download Selenium files
  • Create startup scripts for Selenium Grid
  • Run Hub and Nodes
  • Run test cases from LEAPWORK on Selenium Grid

Go to next lesson.

Overview

Watch this video to learn how to setup a Selenium Grid and use it from LEAPWORK.

In this video

  • Overview of Selenium Grid and LEAPWORK
  • Download Selenium files
  • Create startup scripts for Selenium Grid
  • Run Hub and Nodes
  • Run test cases from LEAPWORK on Selenium Grid

Go to next lesson.

Watch this video to learn how to download, configure and run a Selenium Grid.

Downloads:

Find the necessary Selenium files from this location: http://www.seleniumhq.org/download/. The selenium grid (selenium server) is located in the “Selenium Standalone Server” section and the individual selenium drivers for the browsers is located in the “Third Party Drivers, Bindings, and Plugins” section.

This video does not show how to install Java on the machines where the Selenium Grid is installed. You can find a short video instruction of how to install Java here https://www.youtube.com/watch?v=wwsn1jEvsHY

Download the slides used in the video: slides (powerpoint)

Download the bat files used to start the Selenium Grid: Selenium-grid-startup-files (zip)

Download the test case used in the demonstration: find-leaptest-logo (zip)

Hi

In this video I will show you how to setup a local Selenium Grid and run web cases from Leaptest on the grid.

Selenium grid is part of the Selenium project and is a way to have a number of machines – in Selenium terms called Nodes – executing test cases. This will give the possibility of running the same web cases on different OS’s, in different browsers etc. It will also lower the total amount of time used to execute a set of test cases as the load can be distributed across multiple machines, aka the grid.

Selenium grid

This figure shows the elements from Leaptest Studio, over the Leaptest controller and into the Selenium Grid. The Selenium Grid itself contains a Hub and one or more nodes.

A node is a process running, that receives commands from the Hub and turn them into actions in a browser. So it’s a node that will start a browser and make sure to click, navigate, type text etc. in the browser.

Hub and turn them into actions

You can install nodes on different machines and you can have more than one node on a single machine.

one node on a single machine

You can also choose to install for instance 4 different nodes on the same machine as the Hub, but it could bring the machine under pressure.

4 different nodes on the same machine as the Hub

When the Selenium Grid starts up, all nodes will register themselves with the Hub, and at the same time tell the Hub about it’s capabilities. A nodes capabilities could be the browsers installed and the total amount of simultaneous browsers that can run on the node. This will obviously depend on the hardware and configuration of the machine the node is running on. In the figure I have added 3 nodes that has different browser capabilities.

When one or more nodes have registered them self to the Hub, then the Hub has a total list of all capabilities in the Grid and it will now control what web cases are executed at what node.

web cases

Leaptest will only communicate with the Hub and not directly with the nodes. In Leaptest you will define one or more Environments that points to the Hub – and at the same time matches the capabilities registered in the Hub. More about this later.

Leaptest will only communicate

To keep things simple, I’m gonna install the Hub and 2 nodes on my local machine in this video. This is not ideal for a production setup, but it should illustrate how to setup the grid. I will have one node for running test cases in Chrome and one for running in Firefox.

illustrate how to setup the grid

This figure shows what components needs to installed in order for the Hub and the Node to work. The Hub is pretty straight forward. We just need the jar file to run the Hub. I have downloaded this from http://www.seleniumhq.org and have placed in a local folder. In this case a ‘Selenium’ folder at the root of the C-drive. You can find all relevant links in the description of this video.

For the node, I will have to use the same jar file, but just run it in “node-mode”. We will come back to this. I have already installed Chrome and Firefox on my local machine, so I just need the browser drivers for Chrome and Firefox. I have downloaded these from http://www.seleniumhq.org as well and also added them to local selenium folder. They are named chromedriver.exe and geckodriver.exe for chrome and firefox respectively.

So now we have all 3 files needed to start up the hub and the 2 nodes.

I have created a bat file to start up the hub. If we edit this file, we can see that it’s relatively simple.

java -jar “C:\Selenium\selenium-server-standalone-3.3.1.jar” -role hub

Just run the java application with a parameter telling the app that this instance should be the hub. Let’s try to run the bat file. A console is opening and the hub states that it is up and running.

The Hub is running on port 4444, and we can use a browser to check if it’s running correctly (http://localhost:4444). This is the opening page for the Hub running on my local computer. If we click into the console, we can see how the hub is configured, and when we start registering the nodes with the hub, we will get an overview of the nodes in this console.

Let’s start up the first node – the chrome node. Similar to the bat file for the hub, I have created a bat file for the chrome node. When I edit this, we can see that it’s a bit more complicated than the hub.

java -Dwebdriver.chrome.driver=”C:\Selenium\chromedriver.exe” -jar “C:\Selenium\selenium-server-standalone-3.3.1.jar” -role webdriver -hub “http://localhost:4444/grid/register” -browser browserName=”chrome”,version=ANY,platform=WINDOWS,maxInstances=20

I’ll just run through the most important parameters, but in most cases, you can just copy this into you own bat file and correct file paths and URLs to get started.

The first parameter, that needs to be added before the jar command is the Dwebdriver. In this case for the chrome browser. The value of this parameter is the path to the webdriver for chrome that I added to the local selenium folder.

The next parameter is just a pointer to the application file and the role is now set to node, instead of the hub.

The hub parameter tells the node where to register it self with the hub, so this should point to the URL where the Hub is installed. In this case localhost port 4444 which is my local machine.

The last parameter is the information about the capabilities of the node.
It states what browser is available for the node in what version and on what operating system.
Further it tells how many concurrent instances of the browser that can run on this node.

When I run the bat-file we see a console opening stating that the node is registered and ready to use. If I refresh the selenium console we now see a node registered with 20 instances of chrome available. This means that if the Hub received a request to execute a test case in Chrome, it could choose this node
and send the testing instructions to the node.

I also want to register a Firefox node, and I have a bat file very similar to the chrome bat file.

java -Dwebdriver.gecko.driver=”C:\Program Files\Selenium Server\geckodriver.exe” -jar “C:\Program Files\Selenium Server\selenium-server-standalone-3.3.1.jar” -role webdriver -hub “http://localhost:4444/grid/register” -browser “browserName=firefox, maxInstances=10, platform=ANY, seleniumProtocol=WebDriver” -port 5556

The only new parameter is the port, which I have changed from the default 5555 to 5556. I can’t have 2 nodes running with the same port number on the same machine.

When I run the Firefox bat we can see the console opening just like the chrome console, and in the selenium console we now have 2 nodes registered.

That’s it – we now have a Selenium Grid running with 1 hub, 2 nodes and support for running web cases in Chrome and Firefox.

The next things is to use the Selenium Grid from Leaptest.

A schedule in Leaptest has 2 main purposes: One is to combine a number of test cases with one or more environments to execute the test case on. The other is to be able to run this combination either via a time based schedule or manually.

Slide8

In this demo I will use a simple test case I have created in advance, and show you how to create the 2 environments and the schedule.

The test case is simple. It just opens a browser and navigate to Leaptest.com. When the page is loaded it verifies that the logo is present. We can see that the browser setting in the Start Web Browser block is set to Chrome but we will override this in the environments later on.

To create an environment I click on Environments in the left menu and click new. I name this environment “Local grid Chrome” and set the type to ‘Selenium Grid’. Then I insert the URL to the Hub, in this case Localhost and specify 4444 as the port number. I then select Chrome as the browser and can specify a specific version if needed. In this case I just use the version that is currently installed. I then set the resolution to match my screen size and click Save.

To create an environment for Firefox, I right-click the newly created Chrome environment and select ‘Duplicate’. I then change the name and change the browser to Firefox, and click Save.

We are now ready to create the Schedule.

I will name it “Local Grid” and use the “AdHoc” type. This allows us to trigger it manually. I then select the Project and check the test case. I then select the 2 environments we just created. I select “Run all cases” which means that the selected test case will be run on both environments. In other words, by defining environments with different browsers, we can use a schedule to very easily create cross browser testing. Just create a number of web cases and pair it with the a number of environments.

We are now ready to run the schedule. I right-click and select “Run now”. We can see the schedule change to status running and a number of browsers are now running in the task bar. If we look at the node consoles, we can see both of them working with the test case.

The schedule is now done, and we can look into the reporting section to inspect the results. I have report showing the result of all executed test cases and we can see that the “Find Leaptest Logo” has been run twice a moment ago. This is the result of the schedule. We can see that the environment is different for the 2 results. One is from the Chrome environment and the other from the Firefox environment.

If I double-click one of the entries we can see the activity log and details about the case run.

In this video we have looked into the architecture when Leaptest is setup to use a Selenium Grid to execute web cases. I demonstrated how to setup a Selenium Grid on my local computer with 2 nodes, and we saw how to configure Leaptest to use the Selenium Grid. Finally a schedule was executed and we saw both nodes in action and the results returned to Leaptest.

Thank you.