Selenium Grid Setup in Jenkins

2.8k views Asked by At

I am working on configuring Selenium Grid setup in Jenkins. I have installed Selenium Grid plugin. Jenkins server is treated as Hub by default. Then I created two nodes (VM's) with specific labeled 'grid'. In selenium grid configuration I created two new configurations to match label 'grid' in nodes matching configuration I could see two my nodes when I tried to start they were not getting started not sure what's the issue.

Then I manually logged in to VM's and stated the node by registering them to hub from command prompt. then nodes were stated and I could see me the Grid Console.

How do I need to create a job in Jenkins so that I can run my tests in the test suite in parallel?

Please do let me if am doing some mistake in configuring the same or if there is some document which explains how to configure that would be helpful.

1

There are 1 answers

0
towel On

You need to connect to the Selenium Grid via your tests. Since you haven't specified your environment, I'm going to use mine (Windows/C#/NUnit/Jenkins pipeline) to describe how to connect to the Grid:

  1. In your tests, wherever you create a new WebDriver create a RemoteWebDriver with the Grid's address (I find it the easiest to create an environment variable in Jenkins):

new RemoteWebDriver($"http://{Environment.GetEnvironmentVariable("SELENIUM_GRID_SERVER")}/wd/hub", capabilities)

  1. In your pipeline use only nodes labeled 'grid'.

Like so:

node('grid') {
  scm checkout <your_branch>
  def nunit = tool 'NUnit'
  withEnv(["SELENIUM_GRID_SERVER=<your_grid_server>"]) {
    bat "$nunit <your_test>"
  }
}