From dc2839e0861cd17ae5b40d28f08c27dc6f658c8c Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 26 May 2016 15:31:11 +0300 Subject: [PATCH] first attempt --- .gitignore | 4 +++ project.clj | 9 +++--- test/status_im/appium.clj | 53 ++++++++++++++++++++++++++++++++++++ test/status_im/console.clj | 44 ++++++++++++++++++++++++++++++ test/status_im/core_test.clj | 7 ----- 5 files changed, 106 insertions(+), 11 deletions(-) create mode 100644 test/status_im/appium.clj create mode 100644 test/status_im/console.clj delete mode 100644 test/status_im/core_test.clj diff --git a/.gitignore b/.gitignore index 14773fe52f..ea7f8f836b 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,7 @@ target/ # figwheel_server.log .nrepl-port + +# Lein +# +.lein-failures diff --git a/project.clj b/project.clj index 647d7ad498..d68172cc05 100644 --- a/project.clj +++ b/project.clj @@ -8,7 +8,7 @@ [reagent "0.5.1" :exclusions [cljsjs/react]] [re-frame "0.6.0"] [prismatic/schema "1.0.4"] - ^{:voom {:repo "https://github.com/status-im/status-lib.git" + ^{:voom {:repo "git@github.com:status-im/status-lib.git" :branch "master"}} [status-im/protocol "0.1.1-20160525_083359-g53ab2c2"] [natal-shell "0.1.6"] @@ -22,7 +22,9 @@ ["with-profile" "prod" "cljsbuild" "once" "android"]]} :figwheel {:nrepl-port 7888} :profiles {:dev {:dependencies [[figwheel-sidecar "0.5.0-2"] - [com.cemerick/piggieback "0.2.1"]] + [com.cemerick/piggieback "0.2.1"] + [io.appium/java-client "3.4.1"] + ] :source-paths ["src" "env/dev"] :cljsbuild {:builds {:ios {:source-paths ["src" "env/dev"] :figwheel true @@ -46,5 +48,4 @@ :compiler {:output-to "index.android.js" :main "env.android.main" :output-dir "target/android" - :optimizations :simple}}}} - }}) + :optimizations :simple}}}}}}) diff --git a/test/status_im/appium.clj b/test/status_im/appium.clj new file mode 100644 index 0000000000..a879a68ba2 --- /dev/null +++ b/test/status_im/appium.clj @@ -0,0 +1,53 @@ +(ns status-im.appium + (:require [clojure.java.io :as io] + [clojure.test :refer :all]) + (:import (org.openqa.selenium.remote DesiredCapabilities) + (org.openqa.selenium By) + (io.appium.java_client.android AndroidDriver) + (java.net URL) + (java.util.concurrent TimeUnit))) + + +(defn init [] + (let [dir (io/file (str (System/getProperty "user.dir") + "/android/app/build/outputs/apk")) + app (io/file dir "app-debug.apk") + capabilities (doto (DesiredCapabilities.) + (.setCapability "deviceName" "device") + (.setCapability "platformVersion" "6.0.0") + (.setCapability "app" (.getAbsolutePath app)) + (.setCapability "appPackage" "com.statusim") + (.setCapability "appActivity" ".MainActivity")) + driver (AndroidDriver. (URL. "http://127.0.0.1:4723/wd/hub") capabilities)] + (-> driver + .manage + .timeouts + (.implicitlyWait 100 TimeUnit/MILLISECONDS)) + (Thread/sleep 9000) + driver)) + +(defn by-xpath [driver xpath] + (.findElement driver (By/xpath xpath))) + +(defn elements-by-xpath [driver xpath] + (.findElements driver (By/xpath xpath))) + +(defn click [driver xpath] + (.click (by-xpath driver xpath))) + +(defn write [driver input-xpath text] + (.sendKeys (by-xpath driver input-xpath) (into-array [text]))) + +(defn get-text [driver xpath] + (.getText (by-xpath driver xpath))) + +(defn xpath-by-text [text] + (str ".//*[@text='" text "']" )) + +(defn contains-text [driver text] + (is (= 1 (->> (xpath-by-text text) + (elements-by-xpath driver) + (.size))))) + +(defn quit [driver] + (.quit driver)) diff --git a/test/status_im/console.clj b/test/status_im/console.clj new file mode 100644 index 0000000000..a99251393d --- /dev/null +++ b/test/status_im/console.clj @@ -0,0 +1,44 @@ +(ns status-im.console + (:require [clojure.test :refer :all] + [status-im.appium :refer :all])) + +(def command-request-icon + (str + "//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]" + "/android.widget.FrameLayout[1]/android.view.ViewGroup[1]" + "/android.widget.ScrollView[1]/android.view.ViewGroup[1]" + "/android.view.ViewGroup[1]/android.view.ViewGroup[1]" + "/android.view.ViewGroup[2]/android.widget.ImageView[1]")) + +(def input + (str + "//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]" + "/android.widget.FrameLayout[1]/android.view.ViewGroup[1]" + "/android.view.ViewGroup[2]/android.view.ViewGroup[1]" + "/android.widget.EditText[1]")) + +(def send-button1 + (str "//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]" + "/android.widget.FrameLayout[1]/android.view.ViewGroup[1]" + "/android.view.ViewGroup[2]/android.view.ViewGroup[1]" + "/android.view.ViewGroup[2]/android.view.ViewGroup[1]")) + +(def send-button2 + (str "//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]" + "/android.widget.FrameLayout[1]/android.view.ViewGroup[1]" + "/android.view.ViewGroup[2]/android.view.ViewGroup[2]" + "/android.view.ViewGroup[2]/android.view.ViewGroup[1]")) + +(def message-text + (str "Your phone number is also required to use the app. Type" + " the exclamation mark or hit the icon to open the command " + "list and choose the !phone command")) + +(deftest console-test + (let [driver (init)] + (click driver command-request-icon) + (write driver input "123") + (click driver send-button1) + (click driver send-button2) + (contains-text driver message-text) + (quit driver))) diff --git a/test/status_im/core_test.clj b/test/status_im/core_test.clj deleted file mode 100644 index 1224033d1c..0000000000 --- a/test/status_im/core_test.clj +++ /dev/null @@ -1,7 +0,0 @@ -(ns status-im.core-test - (:require [clojure.test :refer :all] - [status-im.core :refer :all])) - -(deftest a-test - (testing "FIXME, I fail." - (is (= 0 1))))