From mkennedy at common-lisp.net Tue Jul 1 06:53:31 2008 From: mkennedy at common-lisp.net (mkennedy) Date: Tue, 1 Jul 2008 02:53:31 -0400 (EDT) Subject: [cl-selenium-cvs] CVS cl-selenium Message-ID: <20080701065331.5D1DC50B1@common-lisp.net> 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 (, at parameters &optional (session *selenium-session*)) ,(iedoc-function-comment iedoc-function) - (let ((query (concatenate 'string - (marshall-request ,(iedoc-function-name iedoc-function) , at 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) , at 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 From mkennedy at common-lisp.net Wed Jul 2 03:33:12 2008 From: mkennedy at common-lisp.net (mkennedy) Date: Tue, 1 Jul 2008 23:33:12 -0400 (EDT) Subject: [cl-selenium-cvs] CVS cl-selenium Message-ID: <20080702033312.6946E33054@common-lisp.net> Update of /project/cl-selenium/cvsroot/cl-selenium In directory clnet:/tmp/cvs-serv11275 Modified Files: selenium.lisp selenium.asd packages.lisp iedoc.lisp ChangeLog Log Message: Add convenience method with-selenium-session. Update driver URL to be Selenium RC default. --- /project/cl-selenium/cvsroot/cl-selenium/selenium.lisp 2008/07/01 06:53:30 1.4 +++ /project/cl-selenium/cvsroot/cl-selenium/selenium.lisp 2008/07/02 03:33:12 1.5 @@ -25,3 +25,13 @@ (cons `("sessionId" . ,session) (marshall-request "testComplete")))) +(defmacro with-selenium-session ((var browser url) &body body) + "Evaluate BODY within a Selenium RC session specified by VAR. +Once the body is evaluated, the test complete command is sent which +closes the session and browser." + `(let ((,var (do-get-new-browser-session ,browser ,url))) + (unwind-protect + (progn + , at body) + (when ,var + (do-test-complete ,var))))) --- /project/cl-selenium/cvsroot/cl-selenium/selenium.asd 2008/01/20 20:01:43 1.1.1.1 +++ /project/cl-selenium/cvsroot/cl-selenium/selenium.asd 2008/07/02 03:33:12 1.2 @@ -1,3 +1,4 @@ + (defpackage #:selenium-system (:use #:common-lisp #:asdf)) (in-package #:selenium-system) --- /project/cl-selenium/cvsroot/cl-selenium/packages.lisp 2008/01/24 15:40:40 1.2 +++ /project/cl-selenium/cvsroot/cl-selenium/packages.lisp 2008/07/02 03:33:12 1.3 @@ -1,3 +1,4 @@ + (defpackage #:selenium (:use #:common-lisp) (:documentation "An interface to Selenium Remote Control.") @@ -8,4 +9,5 @@ #:do-test-complete #:base-error #:http-error - #:execution-error)) + #:execution-error + #:with-selenium-session)) --- /project/cl-selenium/cvsroot/cl-selenium/iedoc.lisp 2008/07/01 06:53:30 1.4 +++ /project/cl-selenium/cvsroot/cl-selenium/iedoc.lisp 2008/07/02 03:33:12 1.5 @@ -1,3 +1,4 @@ + (in-package #:selenium) (defclass iedoc-function () @@ -175,7 +176,7 @@ #+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/") +(defvar *selenium-driver-url* (puri:parse-uri "http://localhost:4444/selenium-server/driver") "The URL of the Selenium Remote Control server.") (defvar *selenium-session* nil --- /project/cl-selenium/cvsroot/cl-selenium/ChangeLog 2008/07/01 06:53:30 1.4 +++ /project/cl-selenium/cvsroot/cl-selenium/ChangeLog 2008/07/02 03:33:12 1.5 @@ -1,5 +1,10 @@ 2008-07-01 Matthew Kennedy + * selenium.lisp (with-selenium-session): New convenience method. + * iedoc.lisp (*selenium-driver-url*): Change value to Selenium RC default. + +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