Skip to content

Commit

Permalink
added implicit support for xpath, issue #73
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Apr 21, 2013
1 parent d74a258 commit ee98749
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
11 changes: 11 additions & 0 deletions basictests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ test (fun _ ->
url testpage
"#firstName" == "John")

"id('firstName') should have John (using == infix operator), basic xpath test" &&& (fun _ ->
url testpage
"id('firstName')" == "John")

"#lastName should have Doe" &&& (fun _ ->
!^ testpage
"#lastName" == "Doe")
Expand All @@ -70,6 +74,13 @@ test (fun _ ->
"#lastName" == "Smith"
"#lastName2" == "Smith")

"writing to .lastName sets text to new Smith in both boxes, xpath test" &&& (fun _ ->
!^ testpage
clear "#lastName"
"//input[@class='lastName']" << "Smith"
"#lastName" == "Smith"
"#lastName2" == "Smith")

"writing to #lastName sets text to new Smith (implicit clear in write)" &&& (fun _ ->
!^ testpage
"#lastName" << "Smith"
Expand Down
11 changes: 7 additions & 4 deletions basictests/basictests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
<None Include="app.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="canopy">
<HintPath>..\packages\canopy.0.7.2\lib\canopy.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core" />
<Reference Include="System" />
Expand All @@ -61,6 +57,13 @@
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\canopy\canopy.fsproj">
<Name>canopy</Name>
<Project>{63135cf6-70a9-4382-851d-4b679ee0cbf8}</Project>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
17 changes: 11 additions & 6 deletions canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ let private findByCss cssSelector f =
f(By.CssSelector(cssSelector))
with | ex -> []

let private findByXpath xpath f =
try
f(By.XPath(xpath))
with | ex -> []

let private findByLabel locator f =
let isInputField (element : IWebElement) =
element.TagName = "input" && element.GetAttribute("type") <> "hidden"
Expand Down Expand Up @@ -163,15 +168,11 @@ let rec private findElements (cssSelector : string) =
)
!webElements

//small optimization to not try text/label searchs if it looks like a css selector
let obviousCssSelector = cssSelector.StartsWith(".") || cssSelector.StartsWith("#")
try
let cssResult = findByCss cssSelector browserFindElementsList
if cssResult.IsEmpty = false then
cssResult
else if obviousCssSelector then
findInIFrame()
else
else
let labelResult = findByLabel cssSelector browser.FindElement
if labelResult.IsEmpty = false then
labelResult
Expand All @@ -180,7 +181,11 @@ let rec private findElements (cssSelector : string) =
if textResult.IsEmpty = false then
textResult
else
findInIFrame()
let xpathResult = findByXpath cssSelector browserFindElementsList
if xpathResult.IsEmpty = false then
xpathResult
else
findInIFrame()
with | ex -> []

let private findByFunction cssSelector timeout waitFunc =
Expand Down

0 comments on commit ee98749

Please sign in to comment.