Update of /project/cl-selenium/cvsroot/cl-selenium In directory clnet:/tmp/cvs-serv14903
Modified Files: selenium.lisp iedoc.lisp ChangeLog Log Message: Don't do our own URL encoding.
--- /project/cl-selenium/cvsroot/cl-selenium/selenium.lisp 2008/05/19 06:37:05 1.3 +++ /project/cl-selenium/cvsroot/cl-selenium/selenium.lisp 2008/07/01 06:53:30 1.4 @@ -15,14 +15,13 @@
(defun do-get-new-browser-session (browser url) "Create a session by using the the given browser and initial URL." - (execute (puri:merge-uris (make-instance 'puri:uri :query (marshall-request "getNewBrowserSession" browser url)) - *selenium-driver-url*) + (execute *selenium-driver-url* + (marshall-request "getNewBrowserSession" browser url) 'string))
(defun do-test-complete (&optional (session *selenium-session*)) - (let ((query (concatenate 'string - "cmd=testComplete&sessionId=" - (format nil "~A" session)))) - (execute (puri:merge-uris (make-instance 'puri:uri :query query) - *selenium-driver-url*)))) + "Destroy session, closing the browser." + (execute *selenium-driver-url* + (cons `("sessionId" . ,session) + (marshall-request "testComplete"))))
--- /project/cl-selenium/cvsroot/cl-selenium/iedoc.lisp 2008/05/19 06:37:05 1.3 +++ /project/cl-selenium/cvsroot/cl-selenium/iedoc.lisp 2008/07/01 06:53:30 1.4 @@ -81,35 +81,13 @@ (convert-parameter-name (iedoc-parameter-name parameter))) iedoc-function-parameters))
-(defun replace-all (string part replacement &key (test #'char=)) - "Returns a new string in which all the occurences of the part - is replaced with replacement." - (with-output-to-string (out) - (loop with part-length = (length part) - for old-pos = 0 then (+ pos part-length) - for pos = (search part string - :start2 old-pos - :test test) - do (write-string string out - :start old-pos - :end (or pos (length string))) - when pos do (write-string replacement out) - while pos))) - -(defun encode (s) - ;;; Must replace % first! - (loop for disallowed-char in '("%" " " "<" ">" "#" "{" "}" "|" "\" "^" - "~" "[" "]" "`" ";" "/" "?" ":" "@" "=" "&" - "$") - do - (setf s (replace-all s disallowed-char (format nil "%~x" (char-code (elt disallowed-char 0)))))) - s) - (defun marshall-request (command &rest parameters) - (with-output-to-string (stream) - (format stream "cmd=~A" command #+nil(html-encode:encode-for-http "asdf% asdf")) - (dotimes (i (length parameters)) - (format stream "&~D=~A" (1+ i) (encode (elt parameters i)))))) + (cons `("cmd" . ,command) + (let ((argument-count 0)) + (mapcar #'(lambda (parameter) + (cons (format nil "~D" (incf argument-count)) + (format nil "~A" parameter))) + parameters))))
(defun starts-with (s prefix) "Returns t if s starts with prefix" @@ -170,9 +148,9 @@ (format s "Selenium execution error: ~A" (description c)))))
-(defun execute (url &optional return-type) +(defun execute (url parameters &optional return-type) (multiple-value-bind (reply status-code headers reply-from stream some-bool reason) - (drakma:http-request url :method :get) + (drakma:http-request url :method :get :parameters parameters) (declare (ignore headers reply-from stream some-bool)) (when (/= 200 status-code) (error 'http-error :status-code status-code :reason reason)) @@ -189,14 +167,13 @@ `(defun ,function-name (,@parameters &optional (session *selenium-session*)) ,(iedoc-function-comment iedoc-function) - (let ((query (concatenate 'string - (marshall-request ,(iedoc-function-name iedoc-function) ,@parameters) - (format nil "&sessionId=~d" session)))) - (execute (puri:merge-uris (make-instance 'puri:uri :query query) - *selenium-driver-url*) + (let ((parameters (cons `("sessionId" . ,session) + (marshall-request ,(iedoc-function-name iedoc-function) ,@parameters)))) + (execute *selenium-driver-url* + parameters ',(iedoc-return-type iedoc-function))))))
-#+nil (mapcar #'convert-function (parse-iedoc #p"/selenium-core-0.8.2/core/iedoc.xml")) +#+nil (mapcar #'convert-function (parse-iedoc #p"/home/mkennedy/src/cl-selenium/iedoc-0.8.3-1879.xml"))
(defvar *selenium-driver-url* (puri:parse-uri "http://localhost:9999/selenium-server/driver/") "The URL of the Selenium Remote Control server.") --- /project/cl-selenium/cvsroot/cl-selenium/ChangeLog 2008/05/19 06:37:05 1.3 +++ /project/cl-selenium/cvsroot/cl-selenium/ChangeLog 2008/07/01 06:53:30 1.4 @@ -1,3 +1,10 @@ +2008-07-01 Matthew Kennedy + + * iedoc.lisp (marshall-request): Change the result to an + associative list of parameters which can be passed to Drakma's + http-request function. This way we don't have to do our own URL + encoding. Thanks to Robin Lee Powell for noting this problem. + 2008-05-19 Matthew Kennedy
* iedoc.lisp, selenium.lisp: Apply patch from Chaitanya Gupta to
cl-selenium-cvs@common-lisp.net