Actions

start

Start an instance of a browser.

1: 
2: 
3: 
4: 
5: 
6: 
7: 
start firefox
start chrome
start ie
start safari
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: 
5: 
//quit current
quit ()
//quit specific
let browser1 = start chrome
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 names2 = 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 names3 = 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: 
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

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 browser2 = browser
start chrome
let browser3 = browser
start chrome
let browser4 = browser

tile [browser2; browser3; browser4]

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

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 webdriver =
    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
namespace canopy.runner
namespace System
namespace OpenQA
namespace OpenQA.Selenium
module classic

from canopy
val start : b:BrowserStartMode -> unit
val firefox : BrowserStartMode
val chrome : BrowserStartMode
val ie : BrowserStartMode
val safari : BrowserStartMode
val aurora : BrowserStartMode
val edgeBETA : BrowserStartMode
val chromium : BrowserStartMode
val url : u:string -> unit
val quit : browser:'a6 -> unit
val browser1 : unit
val write : text:string -> selector:'a -> unit
val text : string
val selector : 'a
val selectedState : string
val read : item:'a -> string
val firstName : string
val linkText : string
val click : item:'a -> unit
val element : cssSelector:string -> IWebElement
val doubleClick : item:'a -> unit
val ctrlClick : item:'a -> unit
val shiftClick : item:'a -> unit
val rightClick : item:'a -> unit
val check : item:'a -> unit
val uncheck : item:'a -> unit
val drag : cssSelectorA:string -> cssSelectorB:string -> (IWebDriver -> unit)
val hover : selector:string -> unit
val logoutHref : string
val describe : text:string -> unit
val logout : IWebElement
val unreliableElement : cssSelector:string -> IWebElement
val firstBob : IWebElement
val elementWithText : cssSelector:string -> regex:string -> IWebElement
val name : IWebElement
val elementWithin : cssSelector:string -> elem:IWebElement -> IWebElement
val exists : selector:string -> bool
val selector : string
val someEle : IWebElement option
val someElement : cssSelector:string -> IWebElement option
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
val someName : IWebElement option
val someElementWithin : cssSelector:string -> elem:ISearchContext -> IWebElement option
val parent : elem:IWebElement -> IWebElement
val someParent : elem:ISearchContext -> IWebElement option
val clickAll : selector:string -> unit
val elements : cssSelector:string -> IWebElement list
Multiple items
module List

from Microsoft.FSharp.Collections

--------------------
type List<'T> =
  | ( [] )
  | ( :: ) of Head: 'T * Tail: 'T list
    interface IReadOnlyList<'T>
    interface IReadOnlyCollection<'T>
    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
    ...
val iter : action:('T -> unit) -> list:'T list -> unit
val element : IWebElement
val names : IWebElement list
val unreliableElements : cssSelector:string -> IWebElement list
val people : IWebElement
val firstPerson : IWebElement list
val unreliableElementsWithin : cssSelector:string -> elem:ISearchContext -> IWebElement list
val daves : IWebElement list
val elementsWithText : cssSelector:string -> regex:string -> IWebElement list
val names2 : IWebElement list
val elementsWithin : cssSelector:string -> elem:ISearchContext -> IWebElement list
val nth : index:int -> cssSelector:string -> IWebElement
val first : cssSelector:string -> IWebElement
val last : cssSelector:string -> IWebElement
val names3 : string list
val fastTextFromCSS : selector:string -> string list
val mainBrowser : IWebDriver
val mutable browser : IWebDriver
val secondBrowser : IWebDriver
val switchTo : b:IWebDriver -> unit
val switchToTab : number:int -> unit
val closeTab : number:int -> unit
val resize : int * int -> unit
val rotate : unit -> unit
val js : script:string -> obj
val path : string
type Environment =
  static member CommandLine : string
  static member CurrentDirectory : string with get, set
  static member CurrentManagedThreadId : int
  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 + 2 overloads
  static member GetCommandLineArgs : unit -> string[]
  static member GetEnvironmentVariable : variable:string -> string + 1 overload
  static member GetEnvironmentVariables : unit -> IDictionary + 1 overload
  ...
  nested type SpecialFolder
  nested type SpecialFolderOption
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
  ...
field Environment.SpecialFolder.ApplicationData: Environment.SpecialFolder = 26
val filename : string
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

--------------------
DateTime ()
   (+0 other overloads)
DateTime(ticks: int64) : DateTime
   (+0 other overloads)
DateTime(ticks: int64, kind: DateTimeKind) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, calendar: Globalization.Calendar) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, kind: DateTimeKind) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, calendar: Globalization.Calendar) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, kind: DateTimeKind) : DateTime
   (+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 []
val sleep : seconds:'a -> unit
val highlight : cssSelector:string -> unit
val fiveNumbersShown : unit -> bool
val waitFor : ((unit -> bool) -> unit)
val waitFor2 : message:string -> f:(unit -> bool) -> unit
val waitForElement : cssSelector:string -> unit
val clear : item:'a -> unit
val press : key:string -> unit
val tab : string
val enter : string
val down : string
val up : string
val left : string
val right : string
val esc : string
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
  ...
field Keys.Backspace: string
val alert : unit -> IAlert
val acceptAlert : unit -> unit
val dismissAlert : unit -> unit
val pin : direction:direction -> unit
union case direction.Left: direction
union case direction.Right: direction
union case direction.FullScreen: direction
val browser2 : IWebDriver
val browser3 : IWebDriver
val browser4 : IWebDriver
val tile : browsers:IWebDriver list -> unit
val positionBrowser : left:int -> top:int -> width:int -> height:int -> unit
val u : string
val currentUrl : unit -> string
val theTitle : string
val title : unit -> string
val reload : unit -> unit
val navigate : direction:canopy.parallell.functions.Navigate -> unit
val back : canopy.parallell.functions.Navigate
val forward : canopy.parallell.functions.Navigate
val findByHref : href:string -> f:(By -> #seq<'b>) -> webdriver:'c -> 'b list
val href : string
val f : (By -> #seq<'b>)
val webdriver : 'c
val cssSelector : string
val sprintf : format:Printf.StringFormat<'T> -> 'T
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
  ...
By.CssSelector(cssSelectorToFind: string) : By
val ofSeq : source:seq<'T> -> 'T list
val ex : exn
val addFinder : finder:(string -> (#By -> Collections.ObjectModel.ReadOnlyCollection<IWebElement>) -> IWebDriver -> IWebElement list) -> unit
val css : (string -> string)
val xpath : (string -> string)
val jquery : (string -> string)
val label : (string -> string)
val text : (string -> string)
val value : (string -> string)
val failsWith : message:string -> unit