Skip to content

Commit

Permalink
read, clear, selected, deselected now take string or element for #93
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Aug 30, 2013
1 parent 93b3c3a commit 437a772
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 18 deletions.
24 changes: 24 additions & 0 deletions basictests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,24 @@ test (fun _ ->
!^ testpage
"#lastName" == "Doe")

"#lastName should have Doe via read cssSelector" &&& fun _ ->
!^ testpage
read "#lastName" |> is "Doe"

"#lastName should have Doe via read IWebElements" &&& fun _ ->
!^ testpage
element "#lastname" |> read |> is "Doe"

"clearing #firstName sets text to new empty string" &&& (fun _ ->
!^ testpage
clear "#firstName"
"#firstName" == "")

"clearing #firstName sets text to new empty string via IWebElement" &&& (fun _ ->
!^ testpage
element "#firstName" |> clear
"#firstName" == "")

"writing to #lastName sets text to Smith" &&& (fun _ ->
!^ testpage
clear "#lastName"
Expand Down Expand Up @@ -159,6 +172,11 @@ test (fun _ ->
click "#radio1"
selected "#radio1")

"clicking #radio1 selects it via IWebElement" &&& (fun _ ->
!^ testpage
click "#radio1"
element "#radio1" |> selected)

"clicking #radio2 selects it" &&& (fun _ ->
!^ testpage
click "#radio2"
Expand All @@ -175,6 +193,12 @@ test (fun _ ->
uncheck "#checkbox"
deselected "#checkbox")

"clicking selected #checkbox deselects it via IWebElement" &&& (fun _ ->
!^ testpage
check "#checkbox"
uncheck "#checkbox"
element "#checkbox" |> deselected)

"element within only searching within the element" &&& (fun _ ->
url "http://lefthandedgoat.github.io/canopy/testpages/elementWithin"
count ".item" 5
Expand Down
50 changes: 32 additions & 18 deletions canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -301,27 +301,41 @@ let private textOf (element : IWebElement) =
| _ ->
element.Text

let read (cssSelector : string) =
let elem = element cssSelector
textOf elem
let read item =
match box item with
| :? IWebElement as elem -> textOf elem
| :? string as cssSelector -> element cssSelector |> textOf
| _ -> raise (CanopyNotStringOrElementException(sprintf "Can't read %O because it is not a string or element" item))
let clear (cssSelector : string) =
let elem = element cssSelector
let readonly = elem.GetAttribute("readonly")
if readonly = "true" then
raise (CanopyReadOnlyException(sprintf "element %s is marked as read only, you can not clear read only elements" cssSelector))
elem.Clear()
let clear item =
let clear cssSelector (elem : IWebElement) =
let readonly = elem.GetAttribute("readonly")
if readonly = "true" then raise (CanopyReadOnlyException(sprintf "element %s is marked as read only, you can not clear read only elements" cssSelector))
elem.Clear()
match box item with
| :? IWebElement as elem -> clear elem.TagName elem
| :? string as cssSelector -> element cssSelector |> clear cssSelector
| _ -> raise (CanopyNotStringOrElementException(sprintf "Can't clear %O because it is not a string or element" item))

//status
let selected (cssSelector : string) =
let elem = element cssSelector
if not <| elem.Selected then
raise (CanopySelectionFailedExeception(sprintf "element selected failed, %s not selected." cssSelector))
let selected item =
let selected cssSelector (elem : IWebElement) =
if not <| elem.Selected then raise (CanopySelectionFailedExeception(sprintf "element selected failed, %s not selected." cssSelector))

match box item with
| :? IWebElement as elem -> selected elem.TagName elem
| :? string as cssSelector -> element cssSelector |> selected cssSelector
| _ -> raise (CanopyNotStringOrElementException(sprintf "Can't checked selected on %O because it is not a string or element" item))
let deselected (cssSelector : string) =
let elem = element cssSelector
if elem.Selected then
raise (CanopyDeselectionFailedException(sprintf "element deselected failed, %s selected." cssSelector))
let deselected item =
let deselected cssSelector (elem : IWebElement) =
if elem.Selected then raise (CanopyDeselectionFailedException(sprintf "element deselected failed, %s selected." cssSelector))

match box item with
| :? IWebElement as elem -> deselected elem.TagName elem
| :? string as cssSelector -> element cssSelector |> deselected cssSelector
| _ -> raise (CanopyNotStringOrElementException(sprintf "Can't checked deselected on %O because it is not a string or element" item))

//keyboard
let tab = Keys.Tab
Expand Down Expand Up @@ -349,7 +363,7 @@ let dismissAlert() =
true)
//assertions
let ( == ) (item : 'a) value =
let ( == ) item value =
match box item with
| :? IAlert as alert ->
let text = alert.Text
Expand Down

0 comments on commit 437a772

Please sign in to comment.