Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
Moves webdriver launch code into it's own namesspace
Browse files Browse the repository at this point in the history
  • Loading branch information
justin taft committed Oct 18, 2015
1 parent 40a3b0c commit 88b649b
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 52 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/deploy/core/node_modules/lighttable/bootstrap.js*
.lein-deps-sum
.lein-env
.lein-failures
.lein-plugins/
.nrepl-port
/builds/
65 changes: 65 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
environment:
global:
CYG_ROOT: C:\cygwin
CYG_MIRROR: http://cygwin.mirror.constant.com
CYG_CACHE: C:\cygwin\var\cache\setup
CYG_BASH: C:\cygwin\bin\bash

cache:
- '%CYG_CACHE%'

init:
- ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

install:
- 'echo Setting up Cygwin dependencies'
- '%CYG_ROOT%\setup-x86.exe -qnNdO -R "%CYG_ROOT%" -s "%CYG_MIRROR%" -l "%CYG_CACHE%" -P autoconf -P automake -P bison -P gcc-core -P gcc-g++ -P mingw-runtime -P mingw-binutils -P mingw-gcc-core -P mingw-gcc-g++ -P mingw-pthreads -P mingw-w32api -P libtool -P make -P python -P gettext-devel -P gettext -P intltool -P libiconv -P pkg-config -P git -P wget -P curl -P unzip -P psmisc> NUL'


#DEBUG BEGIN
#- ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
#- ps: throw "Failing tests"
#DBEUG END

- 'echo Check Cygwin setup'
- '%CYG_ROOT%/bin/bash -lc "cygcheck -dc cygwin"'
- 'echo Done setting up Cygwin'
- ps: |
$base = "https://raw.githubusercontent.com/technomancy/leiningen/"
$lein = $base + "stable/bin/lein.bat"
(new-object net.webclient).DownloadFile($lein, "c:/projects/lighttable/lein.bat")
- cmd: dir
- lein self-install
- 'echo Done installing lein'
- cmd: dir
#Add random location, this prevents qutation mark being added to
#the current directory's path
- cmd: 'set PATH="%PATH%;%cd%;c:\windows\system32"'
- cmd: 'echo %PATH%'




build_script:
- cmd: 'echo Cygwin root is: %CYG_ROOT%'
- cmd: 'echo Build folder is: %APPVEYOR_BUILD_FOLDER%'
- cmd: 'echo Repo build branch is: %APPVEYOR_REPO_BRANCH%'
- cmd: 'echo Repo build commit is: %APPVEYOR_REPO_COMMIT%'
- '%CYG_ROOT%/bin/bash -lc "echo path is $PATH"'
- '%CYG_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; pwd"'
- '%CYG_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; echo \"#!/bin/bash\" > lein.sh"'
- '%CYG_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; echo \"./lein.bat \$@\" >> lein.sh"'
- '%CYG_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; chmod a+x lein.sh"'
- '%CYG_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; cat lein.sh"'
- '%CYG_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; ln -s /cygdrive/c/projects/lighttable/lein.sh lein; ls -la"'



- cmd: 'echo Running build.sh'
- '%CYG_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; ./script/build.sh"'
- cmd: 'echo Runnig tests'
- '%CYG_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; ./script/run-tests.sh"'

- cmd: 'echo run-tests.sh finished'
- '%CYG_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; ls /tmp/"'

Binary file added script/light-test.bat
Binary file not shown.
1 change: 1 addition & 0 deletions script/light-test.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

#!/bin/sh
./script/light.sh &> /tmp/lt-debug
47 changes: 42 additions & 5 deletions script/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
#!/bin/bash

echo "Checking for chromedrive"
if [ ! -f /tmp/chromedriver ]; then
ISWINDOWS=0
if [ "$(echo $(uname -s) | cut -c 1-9)" == "CYGWIN_NT" ]; then
CHROMEDRIVER_PATH=/tmp/chromedriver.exe
ISWINDOWS=1
else
CHROMEDRIVER_PATH=/tmp/chromedriver
fi


if [ ! -f "$CHROMEDRIVER_PATH" ]; then

# from: http://stackoverflow.com/a/17072017/142317
if [ "$(uname)" == "Darwin" ]; then
URL="http://chromedriver.storage.googleapis.com/2.19/chromedriver_mac32.zip"
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
URL="http://chromedriver.storage.googleapis.com/2.19/chromedriver_linux64.zip"
elif [ "$ISWINDOWS" == "1" ]; then
URL="http://chromedriver.storage.googleapis.com/2.19/chromedriver_win32.zip"
else
echo "Cannot detect a supported OS."
exit 1
fi

echo "Downloading & extracting chromedriver."
#wget http://chromedriver.storage.googleapis.com/2.19/chromedriver_mac32.zip -O /tmp/chromedriver.zip
wget http://chromedriver.storage.googleapis.com/2.19/chromedriver_linux64.zip -O /tmp/chromedriver.zip
wget $URL -O /tmp/chromedriver.zip
unzip /tmp/chromedriver.zip -d /tmp
fi

echo "Killing all chromedrivers & starting new instance".


killall "chromedriver"
/tmp/chromedriver&
killall "chromedriver.exe"

chmod u+x $CHROMEDRIVER_PATH
$CHROMEDRIVER_PATH&
CHROME_PID=$!

echo "Running tests"
lein test
Expand All @@ -19,5 +46,15 @@ RETURN_CODE=$?
echo "===LIGHT TABLE DEBUG==="
cat /tmp/lt-debug

exit $RETURN_CODE

echo "Killing chrome"
kill $CHROME_PID


#echo "Killing java"
#taskkill /F /IM java.exe
#echo "Killing bash.exe"
#killall bash.exe
#echo "Killing bash"
#killall -9 bash
#echo "Bash killed"
60 changes: 13 additions & 47 deletions test/lt/system_tests.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
(ns lt.system-tests
(:import
(org.openqa.selenium.remote DesiredCapabilities)
(org.openqa.selenium.remote RemoteWebDriver)
(org.openqa.selenium.chrome ChromeOptions)
(org.openqa.selenium Keys)
(java.net URL)
(java.io File)
(java.nio.file Path)
(java.nio.file Paths)
Expand All @@ -13,40 +9,12 @@
(java.nio.file OpenOption)
(java.io File))
(:require
[clj-webdriver.driver :as driver]
[lt.webdriver-helper :as lt-webdriver-helper]
[clj-webdriver.taxi :as taxi]
[clj-webdriver.core :as core]
[clj-webdriver.element :as element]
[clojure.string :as str]
[clojure.test :refer :all :as test]
[clojure.java.shell :only [sh] :as shell]))


(defn log [msg]
(println msg))


(defn get-project-directory []
(System/getProperty "user.dir"))

;TODO add logic to find real location
(defn get-lt-binary-location []
(str (get-project-directory) "/script/light-test.sh"))

(defn start-lighttable-async []
(-> (Thread. (fn[]
(log (str "Starting lt at " (get-lt-binary-location)))
(Thread/sleep 5000)
(shell/sh "/bin/bash" (get-lt-binary-location))))
(.start)))

(def chromeOptions {
"debuggerAddress" "127.0.0.1:8315"
})

(def capabilities (DesiredCapabilities/chrome))
(.setCapability capabilities ChromeOptions/CAPABILITY chromeOptions)
(.setCapability capabilities "browserName" "electron")
[clojure.test :refer :all :as test]))


(defn create-temporary-file []
Expand Down Expand Up @@ -80,17 +48,14 @@
(defn get-file-name-from-path [path]
(last (str/split path #"/")))

(deftest new-file


;Connect to webdriver
(start-lighttable-async)
(def remote-web-driver (RemoteWebDriver. (URL. "http://127.0.0.1:9515") capabilities))

(def cljwebdriver (driver/init-driver remote-web-driver))
(taxi/set-driver! cljwebdriver)
(defn lt-fixture [func]
(lt-webdriver-helper/connect-to-light-table!)
(func))

(use-fixtures :each myfixture)

(deftest new-file

;TODO write better method to test if
;light table is finished initilaizing
(Thread/sleep 20000)
Expand Down Expand Up @@ -122,9 +87,10 @@
(is (= "File Persistence Test" (read-file-contents temp-file-path)))

;Close Tab
(core/->actions cljwebdriver
(core/->actions (lt-webdriver-helper/get-webdriver)
(core/move-to-element
(core/find-element cljwebdriver {:tag :span :class "file-name" :text (get-file-name-from-path temp-file-path) })))
(taxi/find-element {:tag :span :class "file-name" :text (get-file-name-from-path temp-file-path) })))

(taxi/click {:css ".tabset.active .list li.active .tab-close"})

;Open file
Expand All @@ -144,8 +110,8 @@

;Close Tab
(Thread/sleep 1000)
(core/->actions cljwebdriver
(core/->actions (lt-webdriver-helper/get-webdriver)
(core/move-to-element
(core/find-element cljwebdriver {:tag :span :class "file-name" :text (get-file-name-from-path temp-file-path) })))
(taxi/find-element {:tag :span :class "file-name" :text (get-file-name-from-path temp-file-path) })))
(taxi/click {:css ".tabset.active .list li.active .tab-close"})
)
55 changes: 55 additions & 0 deletions test/lt/webdriver_helper.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
(ns lt.webdriver-helper
(:import
(java.net URL)
(org.openqa.selenium.remote DesiredCapabilities)
(org.openqa.selenium.remote RemoteWebDriver)
(org.openqa.selenium.chrome ChromeOptions))
(:require
[clj-webdriver.taxi :as taxi]
[clojure.java.shell :only [sh] :as shell]
[clj-webdriver.driver :as driver]))


(def chromeOptions {
"debuggerAddress" "127.0.0.1:8315"
})

(def capabilities (DesiredCapabilities/chrome))
(.setCapability capabilities ChromeOptions/CAPABILITY chromeOptions)
(.setCapability capabilities "browserName" "electron")


(defn log [msg]
(println msg))


(defn get-project-directory []
(System/getProperty "user.dir"))


(defn get-lt-test-launch-script-location [os-name]
"Returns script that launches light table for tests."
(str (get-project-directory) "/script/light-test"
(if (re-matches #"^(?i)windows" os-name)
".bat"
".sh")))

(defn start-lighttable-async []
(-> (Thread. (fn[]
(Thread/sleep 5000)
(shell/sh (get-lt-test-launch-script-location (System/getProperty "os.name")))))
(.start)))

(defn connect-to-light-table! []
"Connects to light table"
;TODO check if we are already connected to light-table to avoid re-connecting?
(start-lighttable-async)
(-> (RemoteWebDriver. (URL. "http://127.0.0.1:9515") capabilities)
(driver/init-driver)
(taxi/set-driver!)))

(defn get-webdriver []
taxi/*driver*)



0 comments on commit 88b649b

Please sign in to comment.