Skip to content

Commit

Permalink
Added regex NOT for #237
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Feb 27, 2016
1 parent b2663f5 commit f748591
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,13 @@ let ( =~ ) cssSelector pattern =
| :? CanopyElementNotFoundException as ex -> raise (CanopyEqualityFailedException(sprintf "%s%sregex equality check failed. expected: %s, got:" ex.Message Environment.NewLine pattern))
| :? WebDriverTimeoutException -> raise (CanopyEqualityFailedException(sprintf "regex equality check failed. expected: %s, got: %s" pattern (read cssSelector)))

let ( !=~ ) cssSelector pattern =
try
wait compareTimeout (fun _ -> regexMatch pattern (read cssSelector) |> not)
with
| :? CanopyElementNotFoundException as ex -> raise (CanopyEqualityFailedException(sprintf "%s%sregex not equality check failed. expected NOT: %s, got:" ex.Message Environment.NewLine pattern))
| :? WebDriverTimeoutException -> raise (CanopyEqualityFailedException(sprintf "regex not equality check failed. expected NOT: %s, got: %s" pattern (read cssSelector)))

let ( *~ ) cssSelector pattern =
try
wait compareTimeout (fun _ -> ( cssSelector |> elements |> Seq.exists(fun element -> regexMatch pattern (textOf element))))
Expand Down
7 changes: 7 additions & 0 deletions tests/basictests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ context "other tests"
"#lastName" << "Grey"
"#lastName" =~ "Gr[ae]y"

"regex not test" &&& fun _ ->
url testpage
"#lastName" << "Gray"
"#lastName" !=~ "Gr[o]y"
"#lastName" << "Grey"
"#lastName" !=~ "Gr[o]y"

"regex one of many test" &&& fun _ ->
url testpage
"#colors li" *~ "gr[ea]y"
Expand Down

0 comments on commit f748591

Please sign in to comment.