diff --git a/paket.dependencies b/paket.dependencies index baefdaf9..f7412fbb 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -2,8 +2,6 @@ source https://www.nuget.org/api/v2/ nuget NuGet.CommandLine nuget FSharp.Core >= 3.0.2 lowest_matching:true -nuget Newtonsoft.Json framework: >= net40 nuget Selenium.WebDriver -nuget SizSelCsZzz framework: >= net40 nuget FAKE nuget FSharp.Formatting \ No newline at end of file diff --git a/paket.lock b/paket.lock index c9db2779..8095cc0a 100644 --- a/paket.lock +++ b/paket.lock @@ -1,7 +1,7 @@ NUGET remote: https://www.nuget.org/api/v2 specs: - FAKE (4.21.4) + FAKE (4.22.0) FSharp.Compiler.Service (2.0.0.6) FSharp.Core (3.0.2) FSharp.Formatting (2.14.0) @@ -9,12 +9,5 @@ NUGET FSharpVSPowerTools.Core (>= 2.3.0 < 2.4.0) FSharpVSPowerTools.Core (2.3.0) FSharp.Compiler.Service (>= 2.0.0.3) - Newtonsoft.Json (6.0.8) - framework: >= net40 NuGet.CommandLine (3.3.0) - Selenium.Support (2.52.0) - framework: >= net40 - Selenium.WebDriver (>= 2.52.0) Selenium.WebDriver (2.52.0) - SizSelCsZzz (0.3.36) - framework: >= net40 - Newtonsoft.Json (>= 6.0) - Selenium.Support (>= 2.40) - Selenium.WebDriver (>= 2.40) diff --git a/src/canopy/canopy.fs b/src/canopy/canopy.fs index 8a513d81..d63657e6 100644 --- a/src/canopy/canopy.fs +++ b/src/canopy/canopy.fs @@ -4,7 +4,6 @@ module canopy.core open OpenQA.Selenium.Firefox open OpenQA.Selenium open OpenQA.Selenium.Interactions -open SizSelCsZzz open Microsoft.FSharp.Core.Printf open System.IO open System @@ -16,7 +15,6 @@ open finders open System.Drawing open System.Drawing.Imaging -let mutable (browser : IWebDriver) = null let mutable (failureMessage : string) = null let mutable wipTest = false let mutable searchedFor : (string * string) list = [] @@ -94,7 +92,7 @@ let puts text = document.getElementsByTagName('body')[0].appendChild(infoDiv); infoDiv.innerHTML = 'locating: " + escapedText + "';" swallowedJs info - + let private colorizeAndSleep cssSelector = puts cssSelector swallowedJs <| sprintf "document.querySelector('%s').style.border = 'thick solid #FFF467';" cssSelector diff --git a/src/canopy/canopy.fsproj b/src/canopy/canopy.fsproj index fbe9545b..a23927bd 100644 --- a/src/canopy/canopy.fsproj +++ b/src/canopy/canopy.fsproj @@ -109,37 +109,6 @@ - - - - - ..\..\packages\Newtonsoft.Json\lib\net40\Newtonsoft.Json.dll - True - True - - - - - - - ..\..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll - True - True - - - - - - - - - ..\..\packages\Selenium.Support\lib\net40\WebDriver.Support.dll - True - True - - - - @@ -160,15 +129,4 @@ - - - - - ..\..\packages\SizSelCsZzz\lib\SizSelCsZzz.dll - True - True - - - - \ No newline at end of file diff --git a/src/canopy/finders.fs b/src/canopy/finders.fs index 3f7fd317..22469568 100644 --- a/src/canopy/finders.fs +++ b/src/canopy/finders.fs @@ -1,19 +1,15 @@ module canopy.finders open OpenQA.Selenium -open SizSelCsZzz +open System.Collections.ObjectModel +open System.Collections.Generic //have to use the ReadonlyCollection because thats what selenium uses and it wont cast to seq or something, and type inference isnt playing nice //basically a hack because I dont know a better way -let findByCss (cssSelector : string) (f : (By -> System.Collections.ObjectModel.ReadOnlyCollection)) = +let findByCss (cssSelector : string) (f : (By -> ReadOnlyCollection)) = try f(By.CssSelector(cssSelector)) |> List.ofSeq with | ex -> [] - -let findByJQuery cssSelector f = - try - f(ByJQuery.CssSelector(cssSelector)) |> List.ofSeq - with | ex -> [] let findByXpath xpath f = try @@ -53,6 +49,29 @@ let findByValue value f = findByCss (sprintf """*[value="%s"]""" value) f |> List.ofSeq with | _ -> [] +//Inspired by https://github.com/RaYell/selenium-webdriver-extensions +let private loadJQuery () = + let jsBrowser = browser :?> IJavaScriptExecutor + let jqueryExistsScript = """return (typeof window.jQuery) === 'function';""" + let exists = jsBrowser.ExecuteScript(jqueryExistsScript) :?> bool + if not exists then + let load = """ + var jq = document.createElement('script'); + jq.src = '//code.jquery.com/jquery-2.2.1.min.js'; + document.getElementsByTagName('head')[0].appendChild(jq); + """ + jsBrowser.ExecuteScript(load) |> ignore + wait 2.0 (fun _ -> jsBrowser.ExecuteScript(jqueryExistsScript) :?> bool) + +//total cheese but instead of making a By type, we will just do 'FindElements' style because +//thats the only way its currently used. Cry +let findByJQuery cssSelector _ = + try + loadJQuery() + let script = sprintf "return jQuery('%s').get();" cssSelector + (browser :?> IJavaScriptExecutor).ExecuteScript(script) :?> ReadOnlyCollection |> List.ofSeq + with | ex -> [] + //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 let mutable defaultFinders = (fun cssSelector f -> @@ -66,5 +85,5 @@ let mutable defaultFinders = } ) -let addedHints = System.Collections.Generic.Dictionary() -let hints = new System.Collections.Generic.Dictionary (By -> System.Collections.ObjectModel.ReadOnlyCollection) -> IWebElement list)>>() \ No newline at end of file +let addedHints = Dictionary() +let hints = new Dictionary (By -> ReadOnlyCollection) -> IWebElement list)>>() \ No newline at end of file diff --git a/src/canopy/paket.references b/src/canopy/paket.references index 50d0f970..f0c817ae 100644 --- a/src/canopy/paket.references +++ b/src/canopy/paket.references @@ -1,5 +1,2 @@ FSharp.Core -Newtonsoft.Json -Selenium.Support -Selenium.WebDriver -SizSelCsZzz +Selenium.WebDriver \ No newline at end of file diff --git a/src/canopy/types.fs b/src/canopy/types.fs index ee42dcc8..75091bc9 100644 --- a/src/canopy/types.fs +++ b/src/canopy/types.fs @@ -5,6 +5,8 @@ open System open OpenQA.Selenium open Microsoft.FSharp.Reflection +let mutable (browser : IWebDriver) = null + type CanopyException(message) = inherit Exception(message) type CanopyReadOnlyException(message) = inherit CanopyException(message) type CanopyOptionNotFoundException(message) = inherit CanopyException(message) diff --git a/src/sampleprojectstructure/paket.references b/src/sampleprojectstructure/paket.references index 1bf7e147..d0ceddeb 100644 --- a/src/sampleprojectstructure/paket.references +++ b/src/sampleprojectstructure/paket.references @@ -1,3 +1,2 @@ FSharp.Core -Selenium.Support Selenium.WebDriver diff --git a/src/sampleprojectstructure/sampleprojectstructure.fsproj b/src/sampleprojectstructure/sampleprojectstructure.fsproj index 73b6082c..fe5bf0f1 100644 --- a/src/sampleprojectstructure/sampleprojectstructure.fsproj +++ b/src/sampleprojectstructure/sampleprojectstructure.fsproj @@ -113,17 +113,6 @@ - - - - - ..\..\packages\Selenium.Support\lib\net40\WebDriver.Support.dll - True - True - - - - diff --git a/tests/basictests/basictests.fsproj b/tests/basictests/basictests.fsproj index 79b7a497..49c23ca9 100644 --- a/tests/basictests/basictests.fsproj +++ b/tests/basictests/basictests.fsproj @@ -110,37 +110,6 @@ - - - - - ..\..\packages\Newtonsoft.Json\lib\net40\Newtonsoft.Json.dll - True - True - - - - - - - ..\..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll - True - True - - - - - - - - - ..\..\packages\Selenium.Support\lib\net40\WebDriver.Support.dll - True - True - - - - diff --git a/tests/basictests/paket.references b/tests/basictests/paket.references index 5e6caa75..d0ceddeb 100644 --- a/tests/basictests/paket.references +++ b/tests/basictests/paket.references @@ -1,4 +1,2 @@ FSharp.Core -Newtonsoft.Json -Selenium.Support Selenium.WebDriver