PoshCode Archive  Artifact [d841e3fe90]

Artifact d841e3fe90da2ed576b9a0b97463ca135e0f6c905db4df63c26c561f717cbaa0:

  • File PowerWatin.ps1 — part of check-in [45d957b9e7] at 2018-06-10 12:56:26 on branch trunk — Really basic initial scripts to enable Watin automation via powershell (user: Joel Bennett size: 1741)

# encoding: ascii
# api: powershell
# title: PowerWatin
# description: Really basic initial scripts to enable Watin automation via powershell
# version: 0.1
# type: function
# author: Joel Bennett
# license: CC0
# function: Start-Watin
# x-poshcode-id: 1108
# x-archived: 2017-05-13T00:45:04
# x-published: 2010-05-15T14:51:00
#
#
## CHANGE this to point to your WatiN.Core.dll
$WatinPath = Convert-Path (Resolve-Path "$(Split-Path $Profile)\Libraries\Watin2\WatiN.Core.dll")
## Load the assembly
$global:watin = [Reflection.Assembly]::LoadFrom( $WatinPath )

## initialize the global "Find" functions ...
Function Start-Watin {
Param([WatiN.Core.IE]$ie)
   if(!(Get-Command Find-Link -EA0)) {
      ## Generate Find-Button, Find-TextField, etc:
      $ie | Get-Member -Type Method |
         Where-Object {
            $type = $_.Definition.Split(" ")[0]
            [WatiN.Core.Element].IsAssignableFrom( ([type]$type) )
         } | 
         ForEach-Object {
            New-Item -Path "Function:global:Find-$($_.Name)" -Value $( iex @"
{
Param(`$Attribute, [regex]`$value)
`$ie.$($_.Name)( ([Watin.Core.Find]::By( `$Attribute, `$value)) )
}
"@          )
         }
   }
}

Function New-Watin {
PARAM($URL = "http://www.google.com")
   ## Create an initial window (I'm creating IE, but WatiN handles Firefox too)
   $global:ie = new-object WatiN.Core.IE $URL
   Start-Watin $ie
}

Function Get-Watin {
PARAM($URL = "http://www.google.com")
   ## Find an existing window (I'm using IE, but WatiN handles Firefox too)
   $global:ie = [WatiN.Core.IE]::InternetExplorers()[0]
   Start-Watin $ie
   Set-WatinUrl $url
}

function Set-WatinUrl {
   Param($url) 
   $IE.Goto( $url )
}