PoshCode Logo PowerShell Code Repository

PowerWatin 0.1 (modification of post by view diff)
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1108"></script>download | new post

Really basic initial scripts to enable Watin automation via powershell

  1. ## CHANGE this to point to your WatiN.Core.dll
  2. $WatinPath = Convert-Path (Resolve-Path "$(Split-Path $Profile)\Libraries\Watin2\WatiN.Core.dll")
  3. ## Load the assembly
  4. $global:watin = [Reflection.Assembly]::LoadFrom( $WatinPath )
  5.  
  6. ## initialize the global "Find" functions ...
  7. Function Start-Watin {
  8. Param([WatiN.Core.IE]$ie)
  9.    if(!(Get-Command Find-Link -EA0)) {
  10.       ## Generate Find-Button, Find-TextField, etc:
  11.       $ie | Get-Member -Type Method |
  12.          Where-Object {
  13.             $type = $_.Definition.Split(" ")[0]
  14.             [WatiN.Core.Element].IsAssignableFrom( ([type]$type) )
  15.          } |
  16.          ForEach-Object {
  17.             New-Item -Path "Function:global:Find-$($_.Name)" -Value $( iex @"
  18. {
  19. Param(`$Attribute, [regex]`$value)
  20. `$ie.$($_.Name)( ([Watin.Core.Find]::By( `$Attribute, `$value)) )
  21. }
  22. "@          )
  23.          }
  24.    }
  25. }
  26.  
  27. Function New-Watin {
  28. PARAM($URL = "http://www.google.com")
  29.    ## Create an initial window (I'm creating IE, but WatiN handles Firefox too)
  30.    $global:ie = new-object WatiN.Core.IE $URL
  31.    Start-Watin $ie
  32. }
  33.  
  34. Function Get-Watin {
  35. PARAM($URL = "http://www.google.com")
  36.    ## Find an existing window (I'm using IE, but WatiN handles Firefox too)
  37.    $global:ie = [WatiN.Core.IE]::InternetExplorers()[0]
  38.    Start-Watin $ie
  39.    Set-WatinUrl $url
  40. }
  41.  
  42. function Set-WatinUrl {
  43.    Param($url)
  44.    $IE.Goto( $url )
  45. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me