Skip to content

Commit

Permalink
Performance feedback for Sergey #163
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Sep 7, 2014
1 parent 47641ff commit bf6efe4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
32 changes: 23 additions & 9 deletions src/canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ let waitFor = waitFor2 "Condition not met in given amount of time. If you want t

//find related
let rec private findElements cssSelector (searchContext : ISearchContext) : IWebElement list =
if optmizeByDisablingCoverageReport = false then searchedFor <- (cssSelector, browser.Url) :: searchedFor
if optimizeByDisablingCoverageReport = false then searchedFor <- (cssSelector, browser.Url) :: searchedFor
let findInIFrame () =
let iframes = findByCss "iframe" searchContext.FindElements
if iframes.IsEmpty then
Expand All @@ -211,8 +211,10 @@ let rec private findElements cssSelector (searchContext : ISearchContext) : IWeb
try
let results =
if (hints.ContainsKey cssSelector) then
let finder = hints.[cssSelector]
seq { yield finder cssSelector searchContext.FindElements }
let finders = hints.[cssSelector]
finders
|> Seq.map (fun finder -> finder cssSelector searchContext.FindElements)
|> Seq.filter(fun list -> not(list.IsEmpty))
else
configuredFinders cssSelector searchContext.FindElements
|> Seq.filter(fun list -> not(list.IsEmpty))
Expand Down Expand Up @@ -778,9 +780,21 @@ let addFinder finder =
|> Seq.append (seq { yield finder cssSelector f }))

//hints
let css selector = hints.[selector] <- findByCss; selector
let xpath selector = hints.[selector] <- findByXpath; selector
let jquery selector = hints.[selector] <- findByJQuery; selector
let label selector = hints.[selector] <- findByLabel; selector
let text selector = hints.[selector] <- findByText; selector
let value selector = hints.[selector] <- findByValue; selector
let private addHintFinder hints finder = hints |> Seq.append (seq { yield finder })
let private addSelector finder selector hintType =
//gaurd against adding same hintType multipe times and increase size of finder seq
if not <| (hints.ContainsKey(selector) && addedHints.[selector] |> List.exists (fun hint -> hint = hintType)) then
if hints.ContainsKey(selector) then
hints.[selector] <- addHintFinder hints.[selector] finder
addedHints.[selector] <- [hintType] @ addedHints.[selector]
else
hints.[selector] <- seq { yield finder }
addedHints.[selector] <- [hintType]
selector

let css = addSelector findByCss "css"
let xpath = addSelector findByXpath "xpath"
let jquery = addSelector findByJQuery "jquery"
let label = addSelector findByLabel "label"
let text = addSelector findByText "text"
let value = addSelector findByValue "value"
2 changes: 1 addition & 1 deletion src/canopy/configuration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ let mutable throwIfMoreThanOneElement = false
let mutable configuredFinders = finders.defaultFinders
let mutable writeToSelectWithOptionValue = true
let mutable optimizeBySkippingIFrameCheck = false
let mutable optmizeByDisablingCoverageReport = false
let mutable optimizeByDisablingCoverageReport = false
3 changes: 2 additions & 1 deletion src/canopy/finders.fs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ let mutable defaultFinders =
}
)

let hints = new System.Collections.Generic.Dictionary<string, (string -> (By -> System.Collections.ObjectModel.ReadOnlyCollection<IWebElement>) -> IWebElement list)>()
let addedHints = System.Collections.Generic.Dictionary<string, string list>()
let hints = new System.Collections.Generic.Dictionary<string, seq<(string -> (By -> System.Collections.ObjectModel.ReadOnlyCollection<IWebElement>) -> IWebElement list)>>()

0 comments on commit bf6efe4

Please sign in to comment.