canopy


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: 
//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

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
namespace canopy.runner
namespace System
val write : text:('a -> 'b) -> selector:('b -> 'c) -> ('a -> 'c)

Full name: Actions.write
val text : ('a -> 'b)
val selector : ('b -> 'c)
val selectedState : obj

Full name: Actions.selectedState
val firstName : obj

Full name: Actions.firstName
val linkText : obj

Full name: Actions.linkText
val logoutHref : obj

Full name: Actions.logoutHref
val logout : obj

Full name: Actions.logout
val firstBob : obj

Full name: Actions.firstBob
val name : obj

Full name: Actions.name
val exists : selector:'a -> bool

Full name: Actions.exists
val selector : 'a
val someEle : obj option
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
val someName : obj

Full name: Actions.someName
val clickAll : selector:'a -> unit

Full name: Actions.clickAll
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 : obj
val names : obj

Full name: Actions.names
val people : obj

Full name: Actions.people
val firstPerson : obj

Full name: Actions.firstPerson
val daves : obj

Full name: Actions.daves
val mainBrowser : obj

Full name: Actions.mainBrowser
val secondBrowser : obj

Full name: Actions.secondBrowser
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 fiveNumbersShown : unit -> bool

Full name: Actions.fiveNumbersShown
union case direction.Left: direction
union case direction.Right: direction
union case direction.FullScreen: direction
val browser1 : obj

Full name: Actions.browser1
val browser2 : obj

Full name: Actions.browser2
val browser3 : obj

Full name: Actions.browser3
val u : obj

Full name: Actions.u
val theTitle : obj

Full name: Actions.theTitle
val findByHref : href:string -> f:('a -> #seq<'c>) -> 'c list

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

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf
val ofSeq : source:seq<'T> -> 'T list

Full name: Microsoft.FSharp.Collections.List.ofSeq
val ex : exn