   (let [nlocal (t/to-time-zone (t/now) (t/time-zone-for-offset -0))]
     (f/unparse (f/formatter-local "yyyy-MM-dd_hh:mm")
                nlocal)))
+
+(defn screenshot
+  ([name]
+   (let [nm (if name (str "-" name) "")
+         s-file (str *output-dir* "/" (date) "_" (.getName *crison-file*) "-screenshot" nm ".png")]
+      (wc/get-screenshot driver :file s-file)))
+  ([] (screenshot nil)))
 
 (defn title [] (wc/title driver))
 


(System/setProperty "phantomjs.binary.path" (env :phantom-path))

(def ^:dynamic *input-dir*)
(def ^:dynamic *output-dir*)



(defmulti decode (fn[x] (ffirst x)))

(defmethod decode :url! [x] (go (:url! x)) (screenshot (:screenshot x)))

(defmethod decode :click! [x]
  (let [e (:click! x)]
    (if (string? e)
      (-> driver (wc/find-element {:id e}) wc/click)
      (-> driver (wc/find-element e) wc/click))
    (Thread/sleep 2000)
    (screenshot (:screenshot x))))

(defmethod decode :submit! [{:keys [submit!] :as x}]
  (let [input (first submit!)
        v (:text! input)
        srch (dissoc input :text!)]
        (-> driver (wc/find-element srch) (wc/input-text v))
        (-> driver (wc/find-element (last submit!)) wc/click)
        (screenshot (:screenshot x))))

(defmethod decode :search! [x]
  (wf/quick-fill-submit driver (:search! x)) (Thread/sleep 2000) (screenshot (:screenshot x)))

(defmethod decode :title [x] (title? (:title x)))

(defmethod decode :default [x] (? x))

(deftest tests
  (wc/resize driver {:width 1024 :height 800})
  (let [fs (do/filter-exts (file-seq (file *input-dir*)) ["csn"])]
    (doseq [f fs]
      (binding [*crison-file* f]
        (doseq [t (read-string (slurp f))] (decode t))
        (screenshot)))))

(defn drive [input-d output-d]
  (binding [*input-dir* input-d
