Skip to content

Commit

Permalink
Issue128 - Complete
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Jan 27, 2014
1 parent 1448bdf commit 03ff6b0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 20 deletions.
41 changes: 29 additions & 12 deletions basictests/Program.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module main

open System
open OpenQA.Selenium
open canopy
open runner
open configuration
Expand Down Expand Up @@ -545,19 +546,27 @@ context "User Agents tests"

context "Resize tests"

"Firefox should be resized to 400,400" &&& fun _ ->
start firefox
url "http://resizemybrowser.com/"
resize (400,400)
"#cWidth" == "400"
"#cHeight" == "400"

"Chrome should be resized to iPhone4" &&& fun _ ->
start chrome
url "http://resizemybrowser.com/"
resize screenSizes.iPhone4
"#cWidth" == "320"
"#cHeight" == "480"

"Firefox should be resized to 400,400" &&& fun _ ->
"Firefox should be resized to 400,500 then rotated to 500,400" &&& fun _ ->
start firefox
url "http://resizemybrowser.com/"
resize (400,400)
"#cWidth" == "400"
resize (400,500)
rotate()
"#cHeight" == "400"
"#cWidth" == "500"

"Chrome should be resized and rotated to iPhone4" &&& fun _ ->
start chrome
Expand All @@ -566,25 +575,33 @@ context "Resize tests"
rotate()
"#cHeight" == "320"
"#cWidth" == "480"


context "pluggable finders tests"

//example of a finder you could write so you didnt have to write boring selectors, just add this
//and let canopy do the work of trying to find something by convention
let findByHref href f =
try
let cssSelector = sprintf "a[href='%s']" href
f(By.CssSelector(cssSelector)) |> List.ofSeq
with | ex -> []

addFinder findByHref

"Firefox should be resized to 400,500 then rotated to 500,400" &&& fun _ ->
start firefox
url "http://resizemybrowser.com/"
resize (400,500)
rotate()
"#cHeight" == "400"
"#cWidth" == "500"
url "http://lefthandedgoat.github.io/canopy/index.html"
click "about.html"
on "http://lefthandedgoat.github.io/canopy/about.html"

context "todo tests"

"write a test that tests the whole internet!" &&& todo


run ()

switchTo mainBrowser
coverage testpage
coverage()
coverage "http://scrumy.com/silenter39delayed"

quit()
quit()
22 changes: 16 additions & 6 deletions canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ open configuration
open levenshtein
open reporters
open types
open finders

let mutable (browser : IWebDriver) = null
let mutable (failureMessage : string) = null
Expand Down Expand Up @@ -110,7 +111,7 @@ let waitFor (f : unit -> bool) =
let rec private findElements cssSelector (searchContext : ISearchContext) : IWebElement list =
searchedFor <- (cssSelector, browser.Url) :: searchedFor
let findInIFrame () =
let iframes = finders.findByCss "iframe" searchContext.FindElements
let iframes = findByCss "iframe" searchContext.FindElements
if iframes.IsEmpty then
browser.SwitchTo().DefaultContent() |> ignore
[]
Expand All @@ -123,10 +124,13 @@ let rec private findElements cssSelector (searchContext : ISearchContext) : IWeb
!webElements

try
configuredFinders cssSelector searchContext.FindElements
|> Seq.append (seq { yield (findInIFrame()) })
|> Seq.filter(fun list -> not(list.IsEmpty))
|> Seq.head
let results =
configuredFinders cssSelector searchContext.FindElements
|> Seq.filter(fun list -> not(list.IsEmpty))
if Seq.isEmpty results then
findInIFrame()
else
results |> Seq.head
with | ex -> []

let private findByFunction cssSelector timeout waitFunc searchContext =
Expand Down Expand Up @@ -643,4 +647,10 @@ let coverage (url : 'a) =
let p = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"canopy\")
let f = DateTime.Now.ToString("MMM-d_HH-mm-ss-fff")
let ss = screenshot p f
reporter.coverage nonMutableInnerUrl ss
reporter.coverage nonMutableInnerUrl ss

let addFinder finder =
let currentFinders = configuredFinders
configuredFinders <- (fun cssSelector f ->
currentFinders cssSelector f
|> Seq.append (seq { yield finder cssSelector f }))
3 changes: 1 addition & 2 deletions canopy/finders.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ let findByValue value f =
with | _ -> []

//you can use this as an example to how to extend canopy by creating your own set of finders, tweaking the current collection, or adding/removing
//(string -> (By -> seq<IWebElement>) -> seq<IWebElement list>)
let mutable defaultFinders =
(fun cssSelector f ->
seq {
Expand All @@ -71,4 +70,4 @@ let mutable defaultFinders =
yield findBySizzle cssSelector f
yield findByJQuery cssSelector f
}
)
)

0 comments on commit 03ff6b0

Please sign in to comment.