From 477d3ad31bb0868126a9e94182a190fe4d74f746 Mon Sep 17 00:00:00 2001 From: Chris Holt Date: Sun, 10 Aug 2014 18:54:57 -0500 Subject: [PATCH] Fix for #161 iframe problems --- src/canopy/canopy.fs | 32 +++++++++++++++++++++----------- tests/basictests/Program.fs | 8 ++++++++ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/canopy/canopy.fs b/src/canopy/canopy.fs index 4b1e0e73..6a2d218c 100644 --- a/src/canopy/canopy.fs +++ b/src/canopy/canopy.fs @@ -159,16 +159,25 @@ let suggestOtherSelectors cssSelector = let ids = js idsViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection |> Seq.map (fun item -> "#" + item.ToString()) |> Array.ofSeq let values = js valuesViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection |> Seq.map (fun item -> item.ToString()) |> Array.ofSeq let texts = js textsViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection |> 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 @@ -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 diff --git a/tests/basictests/Program.fs b/tests/basictests/Program.fs index 4011cc4a..ce4294c6 100644 --- a/tests/basictests/Program.fs +++ b/tests/basictests/Program.fs @@ -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"