Skip to content

Commit

Permalink
#244 Remove dependency on SizSelCsZzz
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Mar 13, 2016
1 parent d87bc0f commit c286447
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 113 deletions.
2 changes: 0 additions & 2 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 1 addition & 8 deletions paket.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
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)
FSharp.Compiler.Service (>= 2.0.0.3 < 2.1.0)
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)
4 changes: 1 addition & 3 deletions src/canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = []
Expand Down Expand Up @@ -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
Expand Down
42 changes: 0 additions & 42 deletions src/canopy/canopy.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,37 +109,6 @@
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.0')">
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\packages\Newtonsoft.Json\lib\net40\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.0' Or $(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="WebDriver.Support">
<HintPath>..\..\packages\Selenium.Support\lib\net40\WebDriver.Support.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v3.5'">
<ItemGroup>
Expand All @@ -160,15 +129,4 @@
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.0' Or $(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="SizSelCsZzz">
<HintPath>..\..\packages\SizSelCsZzz\lib\SizSelCsZzz.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
</Project>
37 changes: 28 additions & 9 deletions src/canopy/finders.fs
Original file line number Diff line number Diff line change
@@ -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<IWebElement> because thats what selenium uses and it wont cast to seq<IWebElement> 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<IWebElement>)) =
let findByCss (cssSelector : string) (f : (By -> ReadOnlyCollection<IWebElement>)) =
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
Expand Down Expand Up @@ -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<IWebElement> |> 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 ->
Expand All @@ -66,5 +85,5 @@ let mutable defaultFinders =
}
)

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)>>()
let addedHints = Dictionary<string, string list>()
let hints = new Dictionary<string, seq<(string -> (By -> ReadOnlyCollection<IWebElement>) -> IWebElement list)>>()
5 changes: 1 addition & 4 deletions src/canopy/paket.references
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
FSharp.Core
Newtonsoft.Json
Selenium.Support
Selenium.WebDriver
SizSelCsZzz
Selenium.WebDriver
2 changes: 2 additions & 0 deletions src/canopy/types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/sampleprojectstructure/paket.references
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
FSharp.Core
Selenium.Support
Selenium.WebDriver
11 changes: 0 additions & 11 deletions src/sampleprojectstructure/sampleprojectstructure.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,6 @@
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.0' Or $(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="WebDriver.Support">
<HintPath>..\..\packages\Selenium.Support\lib\net40\WebDriver.Support.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v3.5'">
<ItemGroup>
Expand Down
31 changes: 0 additions & 31 deletions tests/basictests/basictests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,37 +110,6 @@
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.0')">
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\packages\Newtonsoft.Json\lib\net40\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.0' Or $(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="WebDriver.Support">
<HintPath>..\..\packages\Selenium.Support\lib\net40\WebDriver.Support.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v3.5'">
<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions tests/basictests/paket.references
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
FSharp.Core
Newtonsoft.Json
Selenium.Support
Selenium.WebDriver

0 comments on commit c286447

Please sign in to comment.