Permalink
Browse files

Initial working POC

  • Loading branch information...
krukow committed Aug 26, 2012
1 parent 442b074 commit 5963c621e9a03fd9d004e6552945dc07152ff64f
@@ -0,0 +1,17 @@
+import calabash_jvm.API;
+import java.util.List;
+import java.util.Map;
+
+class Example
+{
+
+ public static void main(String[] args)
+ {
+ List l = (List) API.queryq("[:UITableView]",null);
+ System.err.println("-----");
+ for (Object m : l)
+ {
+ System.err.println(m);
+ }
+ }
+}
View
@@ -1,5 +1,6 @@
(defproject calabash-jvm "0.0.1"
:description "JVM client for calabash-ios-server for automated iOS functional testing"
+ :url "https://github.com/calabash/calabash-ios"
:repositories {"sonatype"
{:url "http://oss.sonatype.org/content/repositories/releases"
:snapshots false
@@ -8,9 +9,11 @@
{:url "http://oss.sonatype.org/content/repositories/snapshots"
:snapshots true
:releases {:checksum :fail :update :always}}}
+
:dependencies [[org.clojure/clojure "1.4.0"]
[org.clojure/data.json "0.1.3"]
[clj-http "0.5.3"]
+ [slingshot "0.10.3"]
[org.slf4j/slf4j-log4j12 "1.6.4"]
[log4j "1.2.16" :exclusions [javax.mail/mail
javax.jms/jms
@@ -21,6 +24,8 @@
[clj-logging-config/clj-logging-config "1.9.8"]
[org.clojure/tools.nrepl "0.2.0-beta9"]]
+ :aot [calabash-jvm]
+
:plugins [[lein-swank "1.4.4"]]
:resources-path "resources"
@@ -0,0 +1,7 @@
+#!/bin/bash
+lein clean
+lein uberjar
+
+javac -cp target/calabash-jvm-0.0.1-standalone.jar:target/classes example/Example.java -d target/classes
+
+java -cp target/calabash-jvm-0.0.1-standalone.jar:target/classes Example
@@ -1,45 +1,54 @@
(ns calabash-jvm
- (:require [clojure.tools.logging :as lg]
+ (:require [clojure.tools.logging :as log]
[clj-logging-config.log4j :as l4j]
[calabash-jvm
+ [core :as core]
+ [keyboard :as keyboard]
+ [utils :as utils]
[env :as env]
[http :as http]
- [events :as events]]))
+ [events :as events]])
+ (:use [calabash-jvm.utils :only [logging]]))
+(l4j/set-loggers!
-;; Public API ;;
+ ["org.apache.http"]
+ {:level :info}
-(def playback events/playback)
-(def interpolate events/interpolate)
-(def record-begin! events/record-begin!)
-(def record-end! events/record-end!)
+ ["calabash-jvm"]
+ {:level :debug
+ :pattern "%p %m (query=%X{query}, action=%X{action}, :extras=%X{extras}) %n"})
+;; Public API ;;
(defn query*
"query views and optionally apply selectors to the results
Tries hard to filter out non-visible views"
[q & selectors]
- (apply http/map-views q :query selectors))
+ (apply core/query* q selectors))
(defn query-all*
"query views (optionally applying selectors to results)
Does not filter out non-visible views"
[q & selectors]
- (apply http/map-views q :query_all selectors))
-
+ (apply core/query-all* q selectors))
(defn touch*
"touch the center of the view that results from performing query q.
Options include offset..."
([q] (touch* q {}))
([q options]
- (playback "touch"
- (if q
- (assoc options :query q)
- options))))
+ (logging
+ {:query q
+ :extras options
+ :action "touch*"}
+ (events/playback "touch"
+ (if q
+ (assoc options :query q)
+ options)))))
(defn touch-point
"Touch the point x,y in the screen coordinate system"
@@ -51,19 +60,83 @@
(query* [:UIView {:marked mark}]))
(defn scroll
+ "Scrolls a scroll view in direction dir (:up, :down, :left, :right)
+ May specify a query (q) determining what to scroll. Default is [:UIScrollView]"
([dir] (scroll [:UIScrollView] dir))
([q dir]
- (http/map-views q :scroll dir)))
+ (core/scroll q dir)))
(defn scroll-to-row
- "Scrolls UITableView corresponding to query q to number"
+ "Scrolls UITableView corresponding to query q to number num. Default is [:UITableView]"
([num] (scroll-to-row [:UITableView] num))
([q num]
- (http/map-views q :scrollToRow num)))
+ (core/scroll-to-row q num)))
+
+
+(defn pinch
+ "Pinch :in or :out (in-out). May specify query."
+ ([in-out] (events/playback (str "pinch_" (name in-out))))
+ ([q in-out]
+ (core/pinch q in-out)))
+
+
+(defn enter-char
+ "Enters a single character (char) using the iOS keyboard.
+ The character must be visible. char must be a string of length one or one of
+ 'Dictation'
+ 'Shift'
+ 'Delete'
+ 'International'
+ 'More'
+ 'Return'"
+ [char]
+ (keyboard/enter-char char))
+
+(defn enter-text
+ "Enters several characters (text) using the iOS keyboard.
+ Tries to find the chars in the keyplanes of the keyboard."
+ [text]
+ (keyboard/enter-text text))
+
+(defn done
+ "Touches return/done/search on keyboard"
+ [] (enter-char "Return"))
+
+(defn search "Touches return/done/search on keyboard" [] (done))
+
+
+(defn record-begin!
+ "Begins recording touch events"
+ []
+ (events/record-begin!))
+
+(defn record-end!
+ "Finishes recording touch events. The recorded events as saved using name param as name."
+ [name]
+ (events/record-end! name))
+
+(defn playback
+ "Plays back a pre-recorded sequence of events with options."
+ ([recname] (events/playback recname))
+ ([recname options]
+ (events/playback recname options)))
+(defn interpolate
+ "TBD"
+ ([recname] (events/interpolate recname))
+ ([recname options]
+ (events/interpolate recname options)))
+
+
+(defn set-http-log-level!
+ [level] (l4j/set-logger-level! "org.apache.http" level))
+
+(defn set-calabash-log-level!
+ [level] (l4j/set-logger-level! "calabash-jvm" level))
+
;;;; PUBLIC DSL ;;;;
(defn- dsl-op
@@ -85,3 +158,36 @@
"construct an xpath query for web views"
[xpath]
(dsl-op :xpath xpath))
+
+
+
+;; interop
+
+(gen-class
+ :name calabash_jvm.API
+ :main true
+ :methods [^:static [query [java.util.List java.util.List] java.util.List]
+ ^:static [queryq [String java.util.List] java.util.List]
+ ^:static [q [String] java.util.List]])
+
+(defn- -query [x & args] (apply query* x args))
+
+
+(defn- -q [s] (eval (read-string s)))
+
+
+(defn- -queryq [x ss]
+ (let [ds (-q x)]
+ (apply query* ds ss)))
+
+(defn -main [& args]
+ (when (< (count args) 1)
+ (println "Usage java -cp target/calabash-jvm-[VERSION]-standalone.jar calabash_jvm.API calabash_jvm.API [query] (selectors)")
+ (System/exit 1))
+ (let [ds (read-string (first args))
+ args (rest args)]
+ (if (vector? ds)
+ (do
+ (prn "Running Query: " ds "(" (class ds) ")")
+ (prn (apply query* (eval ds) args)))
+ (eval ds))))
Oops, something went wrong.

0 comments on commit 5963c62

Please sign in to comment.