Skip to content

Commit

Permalink
Fix for #161 iframe problems
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Aug 10, 2014
1 parent ceded0c commit 477d3ad
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,25 @@ let suggestOtherSelectors cssSelector =
let ids = js idsViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection<System.Object> |> Seq.map (fun item -> "#" + item.ToString()) |> Array.ofSeq
let values = js valuesViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection<System.Object> |> Seq.map (fun item -> item.ToString()) |> Array.ofSeq
let texts = js textsViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection<System.Object> |> Seq.map (fun item -> item.ToString()) |> Array.ofSeq
Array.append classes ids
|> Array.append values
|> Array.append texts
|> Seq.distinct |> List.ofSeq
|> remove "." |> remove "#" |> Array.ofList
|> Array.Parallel.map (fun u -> levenshtein cssSelector u)
|> Array.sortBy (fun r -> r.distance)
|> Seq.take 5
|> Seq.map (fun r -> r.selector) |> List.ofSeq
|> (fun suggestions -> reporter.suggestSelectors cssSelector suggestions)

let results =
Array.append classes ids
|> Array.append values
|> Array.append texts
|> Seq.distinct |> List.ofSeq
|> remove "." |> remove "#" |> Array.ofList
|> Array.Parallel.map (fun u -> levenshtein cssSelector u)
|> Array.sortBy (fun r -> r.distance)

if results.Length >= 5 then
results
|> Seq.take 5
|> Seq.map (fun r -> r.selector) |> List.ofSeq
|> (fun suggestions -> reporter.suggestSelectors cssSelector suggestions)
else
results
|> Seq.map (fun r -> r.selector) |> List.ofSeq
|> (fun suggestions -> reporter.suggestSelectors cssSelector suggestions)

let describe text =
puts text
Expand All @@ -194,7 +203,8 @@ let rec private findElements cssSelector (searchContext : ISearchContext) : IWeb
let webElements = ref []
iframes |> List.iter (fun frame ->
browser.SwitchTo().Frame(frame) |> ignore
webElements := findElements cssSelector searchContext
let root = browser.FindElement(By.CssSelector("html"))
webElements := findElements cssSelector root
)
!webElements

Expand Down
8 changes: 8 additions & 0 deletions tests/basictests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,18 @@ context "other tests"
url "http://lefthandedgoat.github.io/canopy/testpages/iframe1"
"#firstName" == "John"

"elementWithin will find iFrame inside of outter element properly, iframe1" &&& fun _ ->
url "http://lefthandedgoat.github.io/canopy/testpages/iframe1"
first "body" |> elementWithin "#states" |> elementWithin "1" |> read |> is "Alabama"

"#firstName should have John (using == infix operator), iframe2" &&& fun _ ->
url "http://lefthandedgoat.github.io/canopy/testpages/iframe2"
"#firstName" == "John"

"elementWithin will find iFrame inside of outter element properly, iframe2" &&& fun _ ->
url "http://lefthandedgoat.github.io/canopy/testpages/iframe2"
first "body" |> elementWithin "#states" |> elementWithin "1" |> read |> is "Alabama"

context "dragging"
"draging works" &&& fun _ ->
url "http://scrumy.com/silenter39delayed"
Expand Down

0 comments on commit 477d3ad

Please sign in to comment.