canopy


Actions

start

Start an instance of a browser.

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
start firefox
start chrome
start ie
start safari
start phantomJS
start aurora
start edgeBETA
start chromium

!^ (aliased by url)

Go to a url.

1: 
2: 
!^ "http://www.google.com"
url "http://www.google.com"

quit

Quit the current browser or the specified browser.

1: 
2: 
3: 
4: 
//quit current
quit ()
//quit specific
quit browser1

<< (write)

Write text to element.

1: 
2: 
3: 
4: 
"#firstName" << "Alex"
//if you dont like the << syntax you can alias anyway you like, eg:
let write text selector =
    selector << text

read

Read the text (or value or selected option) of an element.

1: 
2: 
3: 
let selectedState = read "#states"
let firstName = read "#firstName"
let linkText = read "#someLink"

click

Click an element via selector or text, can also click selenium IWebElements.

1: 
2: 
3: 
click "#login"
click "Login"
click (element "#login")

doubleClick

Simulates a double click via JavaScript.

1: 
doubleClick "#login"

ctrlClick

Click an element via selector or text while holding down the control key, can also click selenium IWebElements.

1: 
2: 
3: 
ctrlClick "#list > option"
ctrlClick "Oklahoma"
ctrlClick (element "#list > option")

shiftClick

Click an element via selector or text while holding down the shift key, can also click selenium IWebElements.

1: 
2: 
3: 
shiftClick "#list > option"
shiftClick "Oklahoma"
shiftClick (element "#list > option")

rightClick

Right click an element.

1: 
rightClick "#settings"

check

Checks a checkbox if it is not already checked.

1: 
2: 
3: 
check "#yes"
//below code will not click the checkbox again, which would uncheck it
check "#yes"

uncheck

Unchecks a checkbox if it is not already unchecked.

1: 
2: 
3: 
uncheck "#yes"
//below code will not click the checkbox again, which would check it
uncheck "#yes"

--> (drag is an alias)

Drag on item to another.

1: 
2: 
".todo" --> ".inprogress"
drag ".todo" ".inprogress"

hover

Hover over an element.

1: 
2: 
3: 
4: 
url "http://lefthandedgoat.github.io/canopy/testpages/"
"#hover" == "not hovered"
hover "Milk"
"#hover" == "hovered"

element

Get an element (Selenium IWebElement) with given css selector or text (built in waits, automatically searches through iFrames). Most useful if you need to write some custom helpers to provide functionality that canopy does not currently have.

1: 
2: 
3: 
let logoutHref = (element "#logout").GetAttribute("href")
describe ("logout href is: " + logoutHref)
//continue with your test

unreliableElement

Try to get an element without the built in reliability. Throws exception if element not found.

1: 
let logout = unreliableElement "#logout"

elementWithText

Unreliably get the first element with specific text for a selector.

1: 
let firstBob = elementWithText ".name" "Bob"

elementWithin

Get an element by searching within another element (nested).

1: 
let name = element "#header" |> elementWithin ".name"

someElement

Like element function except it runs a Some(IWebElement) or None. Read more about Option types here.

1: 
2: 
3: 
4: 
5: 
6: 
//create your own exists helper function
let exists selector =
    let someEle = someElement selector
    match someEle with
    | Some(_) -> true
    | None -> false

someElementWithin

Like elementWithin function except it runs a Some(IWebElement) or None. Read more about Option types here.

1: 
2: 
//create your own exists helper function
let someName = element "#header" |> someElementWithin ".name"

parent

Get the parent element of provided element.

1: 
element "#firstName" |> parent

someParent

Get the Some/None parent element of provided element.

1: 
element "#firstName" |> someParent

elements

The same as element except you get all elements that match the css selector or text.

1: 
2: 
3: 
4: 
5: 
let clickAll selector =
  elements selector
  |> List.iter (fun element -> click element)

clickAll ".button"

unreliableElements

The same as elements except there is no reliability. You get an empty list if there no elements on the first try.

1: 
let names = unreliableElements ".name"

unreliableElementsWithin

Try without reliability to get elements within an existing element.

1: 
2: 
3: 
4: 
//note that the bellow can be done (better) with selector '#people tr:first'
//the space is 'within' in css selectors
let people = element "#people"
let firstPerson = unreliableElementsWithin "tr:first" people

elementsWithText

Unreliably gets elements with specific text for a selector.

1: 
let daves = elementsWithText ".name" "Dave"

elementsWithin

Get elements by searching within another element (nested).

1: 
let names = element "#header" |> elementsWithin ".name"

nth

Get the nth element.

1: 
click (nth 4 ".button")

first

Get the first element.

1: 
click (first ".button")

last

Get the last element.

1: 
click (last ".button")

fastTextFromCSS

Effeciently get the text values for all elements matching a css selector.

1: 
let names = fastTextFromCSS ".name"

switchTo

Switch to an existing instance of a browser.

1: 
2: 
3: 
4: 
5: 
6: 
start firefox
let mainBrowser = browser
start chrome
let secondBrowser = browser
//switch back to mainBrowser after opening secondBrowser
switchTo mainBrowser

switchToTab

Switch browser focus between tabs.

1: 
switchToTab 2

closeTab

Close a specific tab.

1: 
closeTab 2

resize

Resize the browser to a specific size.

1: 
resize (1920, 1080)

rotate

Rotate the browser by switching the Height and Width.

1: 
rotate()

js

Run JavaScript in the current browser.

1: 
2: 
//give the title a border
js "document.querySelector('#title').style.border = 'thick solid #FFF467';"

screenshot

Take a screenshot and save it to the specified path with specified filename. Returns image as byte array.

1: 
2: 
3: 
let path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\canopy\"
let filename = DateTime.Now.ToString("MMM-d_HH-mm-ss-fff")
screenshot path filename

sleep

Sleep for X seconds.

1: 
2: 
3: 
4: 
5: 
6: 
//sleep for 1 second
sleep ()
//sleep for 1 second
sleep 1
//sleep for 3 seconds
sleep 3

highlight

Place a border around an element to help you identify it visually, used in wip test mode.

1: 
highlight ".btn"

describe (aliased as puts)

Describe something in your test, currently writes description to console.

1: 
describe "on main page, testing logout"

waitFor

Wait until custom function is true (better alternative to sleeping X seconds).

1: 
2: 
3: 
4: 
5: 
6: 
let fiveNumbersShown () =
    (elements ".number").Length = 5

url "http://somepage.com/countdown"
waitFor fiveNumbersShown
//continue with your test

waitFor2

Wait (with message) until custom function is true (better alternative to sleeping X seconds).

1: 
2: 
3: 
4: 
5: 
6: 
let fiveNumbersShown () =
    (elements ".number").Length = 5

url "http://somepage.com/countdown"
waitFor2 "waiting for five numbers to be shown" fiveNumbersShown
//continue with your test

waitForElement

Wait until an element with a given CSS selector appears in the DOM. This is useful when you need to wait for data being loaded and displayed.

1: 
2: 
3: 
url "http://somepage.com/countdown"
waitForElement ".number"
//continue with your test

clear

Clear the text of an element.

1: 
clear "#firstName"

press

Simulate a key press. Other keys can be sent by first importing OpenQA.Selenium and using the keys defined there.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
press tab
press enter
press down
press up
press left
press right
press esc

open OpenQA.Selenium
press Keys.Backspace

alert

Gets the current alert.

1: 
alert() == "Welcome to Test Page!"

acceptAlert

Accepts the current alert.

1: 
acceptAlert()

dismissAlert

Dismiss the current alert.

1: 
dismissAlert()

pin

Pin a browser to the left, right, or fullscreen (any browser you start is pinned right automatically).

1: 
2: 
3: 
pin Left
pin Right
pin FullScreen

pinToMonitor

Move the browser to another monitor.

1: 
pinToMonitor 2

tile

Tile listed browsers equally across your screen. 4 open browsers would each take 25% of the screen.

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
start chrome
let browser1 = browser
start chrome
let browser2 = browser
start chrome
let browser3 = browser

tile [browser1; browser2; browser3]

positionBrowser

Position current browser on the screen - position is in percentages: positionBrowser left top width height

1: 
positionBrowser 66 0 33 50

currentUrl

Gets the current url.

1: 
let u = currentUrl ()

title

Gets the title of the current page.

1: 
let theTitle = title ()

reload

Reload the current page.

1: 
reload ()

navigate

Navigate forward or back.

1: 
2: 
navigate back
navigate forward

coverage

Create a coverage report for a url.

1: 
coverage "http://www.google.com"

addFinder

Add a finder to the list of current finders to make your selectors cleaner.

1: 
2: 
3: 
4: 
5: 
6: 
7: 
let findByHref href f =
    try
        let cssSelector = sprintf "a[href*='%s']" href
        f(By.CssSelector(cssSelector)) |> List.ofSeq
    with | ex -> []

addFinder findByHref

Fast selectors

Skip looking through the list of finders for a specific selector, use a specific function.

1: 
2: 
3: 
4: 
5: 
6: 
css ".name"
xpath "//div/span"
jquery ".name:first"
label "First Name"
text "Last Name"
value "Submit"

failsWith

Expect a failure with a specific message and pass test if it occurs

1: 
failsWith "An expected error message"
namespace canopy
module types

from canopy
module runner

from canopy
namespace System
namespace OpenQA
namespace OpenQA.Selenium
val start : b:BrowserStartMode -> unit

Full name: canopy.core.start
val firefox : BrowserStartMode

Full name: canopy.core.firefox
val chrome : BrowserStartMode

Full name: canopy.core.chrome
val ie : BrowserStartMode

Full name: canopy.core.ie
val safari : BrowserStartMode

Full name: canopy.core.safari
val phantomJS : BrowserStartMode

Full name: canopy.core.phantomJS
val aurora : BrowserStartMode

Full name: canopy.core.aurora
val edgeBETA : BrowserStartMode

Full name: canopy.core.edgeBETA
val chromium : BrowserStartMode

Full name: canopy.core.chromium
val url : u:string -> unit

Full name: canopy.core.url
val quit : browser:'a -> unit

Full name: canopy.core.quit
val write : text:string -> selector:'a -> unit

Full name: Actions.write
val text : string
val selector : 'a
val selectedState : string

Full name: Actions.selectedState
val read : item:'a -> string

Full name: canopy.core.read
val firstName : string

Full name: Actions.firstName
val linkText : string

Full name: Actions.linkText
val click : item:'a -> unit

Full name: canopy.core.click
val element : cssSelector:string -> IWebElement

Full name: canopy.core.element
val doubleClick : item:'a -> unit

Full name: canopy.core.doubleClick
val ctrlClick : item:'a -> unit

Full name: canopy.core.ctrlClick
val shiftClick : item:'a -> unit

Full name: canopy.core.shiftClick
val rightClick : item:'a -> unit

Full name: canopy.core.rightClick
val check : item:'a -> unit

Full name: canopy.core.check
val uncheck : item:'a -> unit

Full name: canopy.core.uncheck
val drag : cssSelectorA:string -> cssSelectorB:string -> unit

Full name: canopy.core.drag
val hover : selector:string -> unit

Full name: canopy.core.hover
val logoutHref : string

Full name: Actions.logoutHref
val describe : text:string -> unit

Full name: canopy.core.describe
val logout : IWebElement

Full name: Actions.logout
val unreliableElement : cssSelector:string -> IWebElement

Full name: canopy.core.unreliableElement
val firstBob : IWebElement

Full name: Actions.firstBob
val elementWithText : cssSelector:string -> regex:string -> IWebElement

Full name: canopy.core.elementWithText
val name : IWebElement

Full name: Actions.name
val elementWithin : cssSelector:string -> elem:IWebElement -> IWebElement

Full name: canopy.core.elementWithin
val exists : selector:string -> bool

Full name: Actions.exists
val selector : string
val someEle : IWebElement option
val someElement : cssSelector:string -> IWebElement option

Full name: canopy.core.someElement
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
val someName : IWebElement option

Full name: Actions.someName
val someElementWithin : cssSelector:string -> elem:ISearchContext -> IWebElement option

Full name: canopy.core.someElementWithin
val parent : elem:IWebElement -> IWebElement

Full name: canopy.core.parent
val someParent : elem:ISearchContext -> IWebElement option

Full name: canopy.core.someParent
val clickAll : selector:string -> unit

Full name: Actions.clickAll
val elements : cssSelector:string -> IWebElement list

Full name: canopy.core.elements
Multiple items
module List

from Microsoft.FSharp.Collections

--------------------
type List<'T> =
  | ( [] )
  | ( :: ) of Head: 'T * Tail: 'T list
  interface IEnumerable
  interface IEnumerable<'T>
  member GetSlice : startIndex:int option * endIndex:int option -> 'T list
  member Head : 'T
  member IsEmpty : bool
  member Item : index:int -> 'T with get
  member Length : int
  member Tail : 'T list
  static member Cons : head:'T * tail:'T list -> 'T list
  static member Empty : 'T list

Full name: Microsoft.FSharp.Collections.List<_>
val iter : action:('T -> unit) -> list:'T list -> unit

Full name: Microsoft.FSharp.Collections.List.iter
val element : IWebElement
val names : IWebElement list

Full name: Actions.names
val unreliableElements : cssSelector:string -> IWebElement list

Full name: canopy.core.unreliableElements
val people : IWebElement

Full name: Actions.people
val firstPerson : IWebElement list

Full name: Actions.firstPerson
val unreliableElementsWithin : cssSelector:string -> elem:ISearchContext -> IWebElement list

Full name: canopy.core.unreliableElementsWithin
val daves : IWebElement list

Full name: Actions.daves
val elementsWithText : cssSelector:string -> regex:string -> IWebElement list

Full name: canopy.core.elementsWithText
val elementsWithin : cssSelector:string -> elem:ISearchContext -> IWebElement list

Full name: canopy.core.elementsWithin
val nth : index:int -> cssSelector:string -> IWebElement

Full name: canopy.core.nth
val first : cssSelector:string -> IWebElement

Full name: canopy.core.first
val last : cssSelector:string -> IWebElement

Full name: canopy.core.last
val names : string list

Full name: Actions.names
val fastTextFromCSS : selector:string -> string list

Full name: canopy.core.fastTextFromCSS
val mainBrowser : IWebDriver

Full name: Actions.mainBrowser
val mutable browser : IWebDriver

Full name: canopy.types.browser
val secondBrowser : IWebDriver

Full name: Actions.secondBrowser
val switchTo : b:IWebDriver -> unit

Full name: canopy.core.switchTo
val switchToTab : number:int -> unit

Full name: canopy.core.switchToTab
val closeTab : number:int -> unit

Full name: canopy.core.closeTab
val resize : int * int -> unit

Full name: canopy.core.resize
val rotate : unit -> unit

Full name: canopy.core.rotate
val js : script:string -> obj

Full name: canopy.core.js
val path : string

Full name: Actions.path
type Environment =
  static member CommandLine : string
  static member CurrentDirectory : string with get, set
  static member Exit : exitCode:int -> unit
  static member ExitCode : int with get, set
  static member ExpandEnvironmentVariables : name:string -> string
  static member FailFast : message:string -> unit + 1 overload
  static member GetCommandLineArgs : unit -> string[]
  static member GetEnvironmentVariable : variable:string -> string + 1 overload
  static member GetEnvironmentVariables : unit -> IDictionary + 1 overload
  static member GetFolderPath : folder:SpecialFolder -> string + 1 overload
  ...
  nested type SpecialFolder
  nested type SpecialFolderOption

Full name: System.Environment
Environment.GetFolderPath(folder: Environment.SpecialFolder) : string
Environment.GetFolderPath(folder: Environment.SpecialFolder, option: Environment.SpecialFolderOption) : string
type SpecialFolder =
  | ApplicationData = 26
  | CommonApplicationData = 35
  | LocalApplicationData = 28
  | Cookies = 33
  | Desktop = 0
  | Favorites = 6
  | History = 34
  | InternetCache = 32
  | Programs = 2
  | MyComputer = 17
  ...

Full name: System.Environment.SpecialFolder
field Environment.SpecialFolder.ApplicationData = 26
val filename : string

Full name: Actions.filename
Multiple items
type DateTime =
  struct
    new : ticks:int64 -> DateTime + 10 overloads
    member Add : value:TimeSpan -> DateTime
    member AddDays : value:float -> DateTime
    member AddHours : value:float -> DateTime
    member AddMilliseconds : value:float -> DateTime
    member AddMinutes : value:float -> DateTime
    member AddMonths : months:int -> DateTime
    member AddSeconds : value:float -> DateTime
    member AddTicks : value:int64 -> DateTime
    member AddYears : value:int -> DateTime
    ...
  end

Full name: System.DateTime

--------------------
DateTime()
   (+0 other overloads)
DateTime(ticks: int64) : unit
   (+0 other overloads)
DateTime(ticks: int64, kind: DateTimeKind) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, calendar: Globalization.Calendar) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, kind: DateTimeKind) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, calendar: Globalization.Calendar) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, kind: DateTimeKind) : unit
   (+0 other overloads)
property DateTime.Now: DateTime
DateTime.ToString() : string
DateTime.ToString(provider: IFormatProvider) : string
DateTime.ToString(format: string) : string
DateTime.ToString(format: string, provider: IFormatProvider) : string
val screenshot : directory:string -> filename:string -> byte []

Full name: canopy.core.screenshot
val sleep : seconds:'a -> unit

Full name: canopy.core.sleep
val highlight : cssSelector:string -> unit

Full name: canopy.core.highlight
val fiveNumbersShown : unit -> bool

Full name: Actions.fiveNumbersShown
val waitFor : ((unit -> bool) -> unit)

Full name: canopy.core.waitFor
val waitFor2 : message:string -> f:(unit -> bool) -> unit

Full name: canopy.core.waitFor2
val waitForElement : cssSelector:string -> unit

Full name: canopy.core.waitForElement
val clear : item:'a -> unit

Full name: canopy.core.clear
val press : key:string -> unit

Full name: canopy.core.press
val tab : string

Full name: canopy.core.tab
val enter : string

Full name: canopy.core.enter
val down : string

Full name: canopy.core.down
val up : string

Full name: canopy.core.up
val left : string

Full name: canopy.core.left
val right : string

Full name: canopy.core.right
val esc : string

Full name: canopy.core.esc
type Keys =
  static val Null : string
  static val Cancel : string
  static val Help : string
  static val Backspace : string
  static val Tab : string
  static val Clear : string
  static val Return : string
  static val Enter : string
  static val Shift : string
  static val LeftShift : string
  ...

Full name: OpenQA.Selenium.Keys
field Keys.Backspace
val alert : unit -> IAlert

Full name: canopy.core.alert
val acceptAlert : unit -> unit

Full name: canopy.core.acceptAlert
val dismissAlert : unit -> unit

Full name: canopy.core.dismissAlert
val pin : direction:direction -> unit

Full name: canopy.core.pin
union case direction.Left: direction
union case direction.Right: direction
union case direction.FullScreen: direction
val pinToMonitor : n:int -> unit

Full name: canopy.core.pinToMonitor
val browser1 : IWebDriver

Full name: Actions.browser1
val browser2 : IWebDriver

Full name: Actions.browser2
val browser3 : IWebDriver

Full name: Actions.browser3
val tile : browsers:IWebDriver list -> unit

Full name: canopy.core.tile
val positionBrowser : left:int -> top:int -> width:int -> height:int -> unit

Full name: canopy.core.positionBrowser
val u : string

Full name: Actions.u
val currentUrl : unit -> string

Full name: canopy.core.currentUrl
val theTitle : string

Full name: Actions.theTitle
val title : unit -> string

Full name: canopy.core.title
val reload : (unit -> unit)

Full name: canopy.core.reload
val navigate : _arg1:Navigate -> unit

Full name: canopy.core.navigate
val back : Navigate

Full name: canopy.core.back
val forward : Navigate

Full name: canopy.core.forward
val coverage : url:'a -> unit

Full name: canopy.core.coverage
val findByHref : href:string -> f:(By -> #seq<'b>) -> 'b list

Full name: Actions.findByHref
val href : string
val f : (By -> #seq<'b>)
val cssSelector : string
val sprintf : format:Printf.StringFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf
type By =
  member Equals : obj:obj -> bool
  member FindElement : context:ISearchContext -> IWebElement
  member FindElements : context:ISearchContext -> ReadOnlyCollection<IWebElement>
  member GetHashCode : unit -> int
  member ToString : unit -> string
  static member ClassName : classNameToFind:string -> By
  static member CssSelector : cssSelectorToFind:string -> By
  static member Id : idToFind:string -> By
  static member LinkText : linkTextToFind:string -> By
  static member Name : nameToFind:string -> By
  ...

Full name: OpenQA.Selenium.By
By.CssSelector(cssSelectorToFind: string) : By
val ofSeq : source:seq<'T> -> 'T list

Full name: Microsoft.FSharp.Collections.List.ofSeq
val ex : exn
val addFinder : finder:(string -> (#By -> Collections.ObjectModel.ReadOnlyCollection<IWebElement>) -> IWebElement list) -> unit

Full name: canopy.core.addFinder
val css : (string -> string)

Full name: canopy.core.css
val xpath : (string -> string)

Full name: canopy.core.xpath
val jquery : (string -> string)

Full name: canopy.core.jquery
val label : (string -> string)

Full name: canopy.core.label
val text : (string -> string)

Full name: canopy.core.text
val value : (string -> string)

Full name: canopy.core.value
val failsWith : message:string -> unit

Full name: canopy.core.failsWith