Update of /project/cl-selenium/cvsroot/cl-selenium In directory clnet:/tmp/cvs-serv19783
Modified Files: ChangeLog iedoc.lisp selenium.lisp Log Message: Apply patch from Chaitanya Gupta to improve handling of return types.
--- /project/cl-selenium/cvsroot/cl-selenium/ChangeLog 2008/01/24 15:40:40 1.2 +++ /project/cl-selenium/cvsroot/cl-selenium/ChangeLog 2008/05/19 06:37:05 1.3 @@ -1,3 +1,8 @@ +2008-05-19 Matthew Kennedy + + * iedoc.lisp, selenium.lisp: Apply patch from Chaitanya Gupta to + improve handling of return types. + 2008-01-24 Matthew Kennedy
* packages.lisp: Add documentation strings. --- /project/cl-selenium/cvsroot/cl-selenium/iedoc.lisp 2008/01/24 15:40:40 1.2 +++ /project/cl-selenium/cvsroot/cl-selenium/iedoc.lisp 2008/05/19 06:37:05 1.3 @@ -6,7 +6,9 @@ (parameters :initarg :parameters :accessor iedoc-function-parameters) (comment :initarg :comment - :accessor iedoc-function-comment))) + :accessor iedoc-function-comment) + (return-type :initarg :return-type + :accessor iedoc-return-type)))
(defmethod print-object ((iedoc-function iedoc-function) stream) (print-unreadable-object (iedoc-function stream :identity t :type t) @@ -30,7 +32,10 @@ :name name :parameters (loop for p across (dom:get-elements-by-tag-name e "param") collect (make-iedoc-parameter p)) - :comment (make-iedoc-comment (elt (dom:get-elements-by-tag-name e "comment") 0))))) + :comment (make-iedoc-comment (elt (dom:get-elements-by-tag-name e "comment") 0)) + :return-type (let ((return-elements (dom:get-elements-by-tag-name e "return"))) + (when (plusp (length return-elements)) + (make-iedoc-return-type (elt return-elements 0)))))))
(defun make-iedoc-parameter (e) (let ((name (dom:get-attribute e "name"))) @@ -48,6 +53,15 @@ (with-output-to-string (stream) (make-iedoc-comment-r e stream)))))
+(defun make-iedoc-return-type (e) + (let ((type (dom:get-attribute e "type"))) + (cond + ((string-equal type "string") 'string) + ((string-equal type "boolean") 'boolean) + ((string-equal type "number") 'number) + ((string-equal type "string[]") 'list)))) + + (defun normalize-comment (comment) (cl-ppcre:regex-replace-all " {3,}" (cl-ppcre:regex-replace-all "[\t\n]" comment " ") " "))
@@ -104,11 +118,37 @@ (or (null mismatch) (>= mismatch (length prefix)))))
-(defun convert-result (s) - (cond - ((string= s "true") t) - ((string= s "false") nil) - (t s))) +(defun convert-result (s return-type) + (ecase return-type + ((number string) s) + (boolean (cond + ((string= s "true") t) + ((string= s "false") nil))) + (list (convert-string-array s)) + ((nil) nil))) + +;;; Shamelessly copied from selenium.rb in selenium-ruby-client-driver +(defun convert-string-array (s) + (flet ((new-string () + (make-array 0 :element-type 'character :fill-pointer 0 :adjustable t))) + (let ((result nil) + (escape-p nil) + (token (new-string))) + (loop + for char across s + do (cond + (escape-p + (vector-push-extend char token) + (setf escape-p nil)) + ((eql char #\) + (setf escape-p t)) + ((eql char #,) + (push token result) + (setf token (new-string))) + (t + (vector-push-extend char token))) + finally (push token result)) + (nreverse result))))
(define-condition base-error (error) ()) @@ -130,18 +170,18 @@ (format s "Selenium execution error: ~A" (description c)))))
-(defun execute (url) +(defun execute (url &optional return-type) (multiple-value-bind (reply status-code headers reply-from stream some-bool reason) (drakma:http-request url :method :get) (declare (ignore headers reply-from stream some-bool)) (when (/= 200 status-code) (error 'http-error :status-code status-code :reason reason)) - (let ((results (split-sequence:split-sequence #, reply))) - (cond - ((starts-with (first results) "OK") (convert-result (second results))) - ((starts-with (first results) "ERROR:") - (let ((err (second (split-sequence:split-sequence #: (first results))))) - (error 'execution-error :description err))))))) + (cond + ((starts-with reply "OK") + (convert-result (subseq reply (min 3 (length reply))) return-type)) + ((starts-with reply "ERROR:") + (let ((err (second (split-sequence:split-sequence #: reply)))) + (error 'execution-error :description err))))))
(defun convert-function (iedoc-function) (let ((function-name (convert-function-name (iedoc-function-name iedoc-function))) @@ -153,7 +193,8 @@ (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*)))))) + *selenium-driver-url*) + ',(iedoc-return-type iedoc-function))))))
#+nil (mapcar #'convert-function (parse-iedoc #p"/selenium-core-0.8.2/core/iedoc.xml"))
--- /project/cl-selenium/cvsroot/cl-selenium/selenium.lisp 2008/01/24 15:40:40 1.2 +++ /project/cl-selenium/cvsroot/cl-selenium/selenium.lisp 2008/05/19 06:37:05 1.3 @@ -15,8 +15,9 @@
(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 (puri:merge-uris (make-instance 'puri:uri :query (marshall-request "getNewBrowserSession" browser url)) + *selenium-driver-url*) + 'string))
(defun do-test-complete (&optional (session *selenium-session*)) (let ((query (concatenate 'string
cl-selenium-cvs@common-lisp.net