Just to get started, I've set up a repository on github, and have written one quick and dirty test function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn test-with-google [] | |
(let [driver (FirefoxDriver.)] | |
(.get driver "http://www.google.com/") | |
(println "Original page title is " (.getTitle driver)) | |
(let [element (.findElement driver (By/name "q"))] | |
(.sendKeys element (into-array ["clojure\n"])) | |
(.submit element) | |
(-> (WebDriverWait. driver 10) | |
(.until (proxy [ExpectedCondition] [] | |
(apply [d] | |
(-> (.getTitle d) | |
(.toLowerCase) | |
(.startsWith "clojure")))))) | |
(println "Page title after searching is " (.getTitle driver)) | |
(.quit driver)))) |
It's not really useful, it's just a quick spot-check you can run at the REPL to make sure everything's set up right. Make sure salty is in your classpath, and then, at the REPL, type (salty.impl/test-with-google). You should see Firefox start up, open up the main Google page, search for "clojure", and then quit. The output in your REPL should be:
Original page title is Google Page title after searching is clojure - Google Search nil
More to come...
Check out clj-webdriver too: https://github.com/semperos/clj-webdriver
ReplyDeleteAh, I searched for clj-selenium but not clj-webdriver. Thanks for the link.
ReplyDelete