Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Clean up requires in ns, provide example of how to use IWire in comme…
Browse files Browse the repository at this point in the history
…nt at bottom
  • Loading branch information
semperos committed Feb 3, 2012
1 parent 9717a6d commit 9096ee3
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/clj_webdriver/wire.clj
@@ -1,8 +1,9 @@
;; JsonWireProtocol work
(ns clj-webdriver.wire
(:use [cheshire.core :only [parse-string]])
(:require [clj-http.client :as client])
(:import [clj_webdriver.remote_server.RemoteServer]))
(:require [clj-http.client :as client]
[clj-webdriver.remote-server :as rs])
(:import clj_webdriver.remote_server.RemoteServer))

(def default-wd-url "http://localhost:3001/wd/")

Expand All @@ -12,25 +13,30 @@
(parse-string (:body resp)))

(defprotocol IWire
"JsonWireProtocol implemented in Clojure"
"JsonWireProtocol support"
(execute [server commands])
(status [server]))

;; this should probably be initially defined in remote.clj
;; with a protocol for functions relating to starting/stopping,
;; in addition to IWire protocol here.
(extend-type RemoteServer

IWire
(execute [server commands]
(let [commands (if-not (vector? commands)
(vector commands)
commands)
resp (client/get (str (:address server)
resp (client/get (str (rs/address server)
(apply str (interpose "/" commands))))
body (parse-body resp)]
(assoc resp :body body)))

(status [server]
(execute server ["status"])))

(comment
;; The following would execute /session/:sessionId/url to get the
;; current URL of the driver. The response is a JSON object
;; that conforms to the JsonWireProtocol spec detailed here:
;; http://code.google.com/p/selenium/wiki/JsonWireProtocol
(let [[server driver] (rs/new-remote-session)
session-id (clj-webdriver.remote-driver/session-id driver)]
(execute server ["session" session-id "url"])))

0 comments on commit 9096ee3

Please sign in to comment.