Search code examples
c#azureselenium-rcselenium-gridazure-devtest-labs

How to deploy Selenium Grid in Azure DevTestLabs


I'm trying to execute remote selenium tests via Azure.

To do this, I used https://github.com/Azure/azure-devtestlab/tree/master/samples/DevTestLabs/QuickStartTemplates/201-dtl-create-lab-with-seleniumgrid

I create a custom template with the selenium server standalone jar file and installed the Chocolatey Packages, which contains the node and hub artifacts.

I started the virtual machines (the hub and the node). And downloaded the java standalone jar file manually in each vm, and at the command prompt I started each one with the proper commands:

Hub:

java -jar selenium-server-standalone-3.11.0.jar -role hub

And the hub gave me an IP for the node to connect. (For this example I'll use: 10.0.0.2)

Node

java -Dwebdriver.chrome.driver="C:\tryGrid\chromedriver.exe" -jar selenium-server-standalone-3.11.0.jar -role node -hub http://10.0.0.2:4444/grid/register/

But the node couldn't connect to the hub.

So I search in azure forums to solve this problem. I found that I had to add the artifacts. So, in Azure, I went to the DevTest Lab resource I've created, look for every vm and inspect the artifacts. In this case: Manage Artifacts section. Here I found that Selenium-grid hub and Selenium-grid node had an error showed in the Implementation Message. enter image description here

Hub:

The resource operation completed with terminal provisioning state 'Failed'. VM has reported a failure when processing extension 'customScriptArtifact-183362431'. Error message: "Finished executing command".

Extension Message:

Executing script GridDeployer.ps1

Parameters ---------- Role: hub ConfigFile: testhub SeleniumGridJarFile: https://seleniumserverstandalonejardow

SeleniumGridJarFileName: s4o9Vx Successfully downloaded the SeleniumGrid jar file from https://seleniumserverstandalonejardownload. Invoke-WebRequest : The remote name could not be resolved: 'testhub' At C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.9\Downloads\2\ PublicRepo\master\b8dcb684950157e2f6c44e9774ad70f0b27443d3\Artifacts\windows-se leniumgrid-hub\scripts\GridDeployer.ps1:58 char:5 + Invoke-WebRequest -Uri $configFile -OutFile "$PWD\$configFileName" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:Htt pWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShe
ll.Commands.InvokeWebRequestCommand

So I don't now what I should do. Help!

PS. I've work with these node and hub configuration in local machines and It works awesome, but the problem is when I want to execute it with azure VMs


Solution

  • Well I were able to find the answer to this question. The problem wasn't in the portal azure side but in my virtual machine.

    I read a lot of forums and issues on github and another questions here. And finally I found one about a firewall issue.

    What did I just do? On my virtual machine I:

    1. Went to Windows Firewall with Advanced Security
    2. Clicked on Windows Firewall Properties
    3. On Private and Public Profile I changed the state of the firewall to Off.
    4. Click on Apply and OK

    Then, for the Hub configuration you can write a json file and save it in the same path as the selenium server. The file should contains something like this:

    {
      "host": "85.168.37.178",
      "port": 4444,
      "newSessionWaitTimeout": -1,
      "servlets" : [],
      "prioritizer": null,
      "capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
      "throwOnCapabilityNotPresent": true,
      "nodePolling": 5000,
    
      "cleanUpCycle": 5000,
      "timeout": 300000,
      "maxSession": 5
    }
    

    I saved the file as hub.json. And on the console you write  

    java -jar selenium-server-standalone-2.6.0.jar -role hub -hubConfig hub.json
    

    For the Node you can also write a configuration file like this:

    {
      "capabilities":
          [
            {
              "browserName": "firefox",
              "maxInstances": 5
            },
            {
              "browserName": "chrome",
              "maxInstances": 5,
              "seleniumProtocol": "WebDriver"
            },
            {
              "browserName": "internet explorer",
              "maxInstances": 1
            }
          ],
        "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
        "maxSession": 5,
        "port": 5555,
        "register": true,
        "registerCycle": 5000,
        "hub": "http://85.168.37.178:4444/",
        "nodeStatusCheckTimeout": 5000,
        "nodePolling": 5000,
        "role": "node",
        "unregisterIfStillDownAfter": 60000,
        "downPollingLimit": 2,
        "debug": false,
        "servlets" : [],
        "withoutServlets": [],
        "custom": {}
    }
    

    And finally, in your program you can write the IP or the DNS, I took the DNS because is public.

    ChromeOptions options = new ChromeOptions();
    options.AddArgument("--start-maximized");
    RemoteWebDriver(new Uri("http://myvirtualmachinename.server.cloudapp.azure.com:4444/wd/hub"), options.ToCapabilities());
    

    I hope this works for you too!