Wednesday, October 25, 2017

Troubleshooting Chrome WebDriver in Robot Framework


I had a nightmare recently. I had my Selenium script finished in Robot Framework and I was able to run pybot every time with no problem. However, it threw an ugly exception error when I added the test suite to our Jenkins pipeline:

| FAIL |
WebDriverException: Message: chrome not reachable
  (Driver info: chromedriver=2.24.417424 (c5c5ea873213ee72e3d0929b47482681555340c3),platform=Linux 3.10.0-229.20.1.el7.x86_64 x86_64)

I made sure that both chromedriver and google-chrome-stable are updated and available in path, but still couldn't figure why Jenkins was unable to run the same command in same box.

My best friend, google, said that's possibly because the user (Jenkins) can not reach Chrome's debugging ports and I could fix it easily by adding browser "options" in the code. I sounds easy now, but there is no single page in google to tell me how to set those options in ROBOT not Python, Java, etc.

At the end, here was my solution:


  • Don't use keyword:  Open Browser 
  • Instead, make and use a keyword this way:
Open Chrome With Options ${url}
   Log     Creating WebDriver   WARN
   Start Virtual Display    1920   1920
   ${options}=  Evaluate  sys.modules['selenium.webdriver'].ChromeOptions()  sys
    Call Method   ${options}   add_argument   --no-sandbox
    Call Method   ${options}   add_argument   --disable-setuid-sandbox
    Create WebDriver   Chrome   chrome_options=${options}
    Go To   ${url}