2
votes

I have set up selenium grid on local machine and a node is set up on remote machine.

The node is running

java -jar selenium-server-standalone-3.8.1.jar -role node  -hub http://<hub_machine>:4444/grid/register

Now I have written robot tests to run the script on the remote machine as follows:

Open Browser   google.com   chrome  None  http://<hub_machine>:4444/wd/hub  desired_capabilities=browserName:chrome,platform:WINDOWS

I also tried using the remote Webdriver as follows:

${executor}=    Evaluate    str('http://<hub_machine>:4444/wd/hub')
    ${desired capabilities}=    Evaluate    { "browserName": "chrome", "version": "", "platform": "VISTA", "javascriptEnabled": True}
    Create Webdriver    Remote    desired_capabilities=${desired capabilities}    command_executor=${executor} 

But it the code throws an error as follows:

2018-02-20 13:33:41.655:WARN:osjs.HttpChannel:qtp662736689-13: /wd/hub/session java.io.IOException: org.openqa.grid.common.exception.GridException: Cannot extract a capabilities from the request: {"capabilities": {"alwaysMatch": {"version": "", "platform": "VISTA", "browserName": "chrome", "javascriptEnabled": true}, "firstMatch": []}, "desiredCapabilities": {"version": "", "platform": "VISTA", "browserName": "chrome", "javascriptEnabled": true}}

Please suggest how to resolve this issue.

2

2 Answers

2
votes

The error says it all :

/wd/hub/session java.io.IOException: org.openqa.grid.common.exception.GridException: Cannot extract a capabilities from the request: {"capabilities": {"alwaysMatch": {"version": "", "platform": "VISTA", "browserName": "chrome", "javascriptEnabled": true}, "firstMatch": []}, "desiredCapabilities": {"version": "", "platform": "VISTA", "browserName": "chrome", "javascriptEnabled": true}}

To start the Selenium Grid Node you should provide the WebDriver variant as an argument as follows :

  • Mozilla Firefox :

    java -Dwebdriver.gecko.driver=geckodriver.exe -jar selenium-server-standalone-3.8.1.jar -role node -hub http://<hub_machine>:4444/grid/register
    
  • Chrome :

    java -Dwebdriver.chrome.driver=chromedriver.exe -jar selenium-server-standalone-3.8.1.jar -role node -hub http://<hub_machine>:4444/grid/register
    
  • Internet Explorer :

    java -Dwebdriver.ie.driver=IEDriverServer.exe -jar selenium-server-standalone-3.8.1.jar -role node -hub http://<hub_machine>:4444/grid/register
    

Update

As you are still seeing the same error you need to :

  • Provide the complete url including the protocol as https://www.google.com (instead of only google.com)
  • Clean the Project from your IDE
  • Use CCleaner tool to wipe off all the OS chores.
  • Execute your Test
0
votes

Note if you need to run Robot tests across many systems then Grid is the way. But if you only need one remote machine you can use the selenium server in stand alone mode.

I just solved this problem. Here is how I did it for Grid:

Start the Hub and Node Selenium server

Note I run in python's virtual env to control versions. So virPath below is the full path to the bin dir where I put the selenium server jar file

#! /bin/bash
virPath="$(echo $PATH | cut -f 1 -d':')"

java -jar ${virPath}/selenium-server.jar \
     -role hub \
     >/tmp/selenium_server_hub.log 2>&1 &

sleep 3

java -jar ${virPath}/selenium-server.jar \
     -role node \
     -hub http://localhost:4444/grid/register \
     -maxSession 10 \
     -browser browserName=chrome,maxInstances=10 \ 
     >/tmp/selenium_server_node.log 2>&1 &

Running Robot tests

When I want to run Robot tests using the remote server I pass in flags to pybot:

--variable Use Selenium Server:True
--variable Selenium Server URL:http://localhost:4444/wd/hub

I have a number of keywords to open the brower based on my env but eventually it gets down to these:

Open Chrome Browser to Page
| | [Documentation]
| | ... | Opens Google Chrome to a given web page using Create Webdriver so
| | ... | arguments can be passed to webdriver in the form of capabilities.
| | ... | For more information on what capabilities that Google Chrome
| | ... | supports, see [http://chromedriver.chromium.org/capabilities] and
| | ... | [https://peter.sh/experiments/chromium-command-line-switches/]
| | ... |
| | ... | Webdriver can be run remotely using the selenium remote server.
| | ... | This can be done in 'Grid' mode with both a Hub server and
| | ... | Node servers where the tests are route to by the Hub to be run.
| | ... | See run_tests.sh for options to use this feature.
| | [Arguments] | ${url} |
| | ${ws}= | Set Variable | window-size=1080,1080 |
| | ${chrome_options}= | Evaluate | sys.modules['selenium.webdriver'].ChromeOptions() | sys |
| | Call Method | ${chrome_options} | add_argument | disable-infobars          |
| | Call Method | ${chrome_options} | add_argument | test-type                 |
| | Call Method | ${chrome_options} | add_argument | disable-extensions        |
| | Call Method | ${chrome_options} | add_argument | ignore-certificate-errors |
| | Call Method | ${chrome_options} | add_argument | allow-insecure-localhost  |
| | Call Method | ${chrome_options} | add_argument | disable-browser-side-navigation |
| | Call Method | ${chrome_options} | add_argument | ${ws} |
| | Run Keyword If | ${Use Chrome Headless} |
| | ... | Call Method | ${chrome_options} | add_argument | headless |
| | Run Keyword If | ${Use Selenium Server} |
| | ...        | Create Remote Chrome Webdriver | ${chrome_options} |
| | ... | ELSE | Create Local Chrome Webdriver  | ${chrome_options} |
| | Go To | ${url} |

Create Remote Chrome Webdriver
| | [Arguments] | ${chrome options} |
| | Comment | Convert webdriver options to capabilities for Selenium server |
| | ${options}= |  Call Method |  ${chrome_options} | to_capabilities |
| | ${status} | ${resp}= | Run Keyword And Ignore Error |
| | ... | Create Webdriver | Remote | command_executor=${Selenium Server URL} | desired_capabilities=${options}
| | Run Keyword If | '${status}'=='FAIL' | Fail | Could not connect to Selenium Server.  Is it up?\nError: ${resp} |

Create Local Chrome Webdriver
| | [Arguments] | ${chrome options} |
| | ${status} | ${resp}= | Run Keyword And Ignore Error |
| | ... | Create Webdriver | Chrome | chrome_options=${chrome_options} |
| | Run Keyword If | '${status}'=='FAIL' | Fail | Could not start browser.  Are tests being run locally?\nError: ${resp} |

Tool Versions

Robot env requires a lot of different packages so I have a bash script to list all that I use:

        Tool |      Version       | Path
-------------+--------------------+-------------------------------------
  Linux Dist | Ubuntu 16.04.4 LTS | NA
Linux Kernel | 4.4.0-116-generic  | NA
  Git commit | 9d7739b            | NA
  Virtualenv | 15.0.1             | /usr/bin/virtualenv
      Python | 2.7.12             | /home/bm/devel/work/rf/bin/python
          RF | 3.0.2              | /home/bm/devel/work/rf/bin/pybot
 RF Selenium | 3.1.0              | /home/bm/devel/work/rf/lib/python2.7/site-packages
    Selenium | 3.9.0              | /home/bm/devel/work/rf/lib/python2.7/site-packages
    Requests | 2.18.4             | /home/bm/devel/work/rf/lib/python2.7/site-packages
    Easysnmp | 0.2.5              | /home/bm/devel/work/rf/lib/python2.7/site-packages
      Poster | 0.8.1              | /home/bm/devel/work/rf/lib/python2.7/site-packages
      Chrome | 65.0.3325.181      | /usr/bin/google-chrome
chromedriver | 2.35.528139        | /home/bm/devel/work/rf/bin/chromedriver
     Firefox | 59.0.2             | /usr/bin/firefox
 Geckodriver | 0.19.1             | /home/bm/devel/work/rf/bin/geckodriver
------------------------------------------------------------------------