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
- ## 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 )
- }
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.
PowerShell Code Repository