Well you find quite a lot of documentation about it:

[https://sites.google.com/a/chromium.org/chromedriver/getting-started](https://sites.google.com/a/chromium.org/chromedriver/getting-started)

Basically you download the Google Chrome webdriver:

[https://sites.google.com/a/chromium.org/chromedriver/downloads](https://sites.google.com/a/chromium.org/chromedriver/downloads)

then run it... and use something like this to "control" it:
    
    
    # nim c --hints:off --verbosity:0
    
    import httpclient
    import json
    import os
    import strutils
    
    const endpoint = "http://127.0.0.1:9515";
    
    var headers = ""
    headers &= "Content-Type: application/json; charset=utf-8\c\L"
    
    let statusResponse = get(endpoint / "status", headers)
    echo $statusResponse.status
    let jsonStatus = parseJSON(statusResponse.body)
    
    if jsonStatus == nil:
      echo "could not query status"
      quit 5
    
    # play with the answer
    #echo $json_status
    if jsonStatus["status"].getNum != 0:
      echo "status returned unexpected " & $jsonStatus["status"]
      quit 5
    
    try:
      let values = json_status["value"]
      echo values["build"]["version"]
      echo values["os"]["name"]
      echo values["os"]["arch"]
      echo values["os"]["version"]
    except:
      echo "Missing information from Status request"
    
    # now we create a session
    var data = %* {
      "desiredCapabilities": {"takesScreenshot": true}
      }
    
    let sessionResponse = post(endpoint / "session", headers, $data)
    echo sessionResponse.status
    let jsonSession = parseJSON(sessionResponse.body)
    
    let tmp = jsonSession.getOrDefault("sessionId")
    if tmp == nil:
      echo "we did not get a session id. check you webdriver is running on " & 
endpoint
      quit 5
    
    #echo $jsonSession
    let sessionId = tmp.str
    echo "we have a session id (" & sessionId & ")"
    
    # so lets open nim-lang.org in the browser
    data = %* {
      "url": "http://nim-lang.org/";
    }
    
    var response = post(endpoint / "session" / sessionId / "url", headers, 
$data)
    echo $response.status
    echo $parseJSON(response.body)
    
    # and so on...
    

Reply via email to