From iMacros
Jump to: navigation, search

This script runs all available demo macros for the specified browser, e.g. iMacros Browser, iMacros for Internet Explorer or iMacros for Firefox, and creates a test report as PowerShell grid table (exported also as a xml file).

There are two options to run macros in the following script: 1. You can ran all macros in a selected folder. 2. You can specify the macros names in the PowerShell script directly.

This script can also serve as template for your own web application regression test scripts.

    iMacros Demo Macros Self-Test Script
    by iOpus/Ipswitch Inc.
# Region Using
# endregion

# Region Main code
Write-Host "Start Self-Test.ps1" -ForegroundColor Yellow

$iim1 = new-object -com "imacros" 

# Specify macros folder
$iMacrosPath = "C:\Users\ipswitch\Documents\iMacros\Macros\Demo";

# Specify the browser, e.g. IM: " "
$Browser=" "
# Specify the macro(s) to be run or just run all macros in the selected folder
$macro = @()
$macro = Get-ChildItem $iMacrosPath -Filter *.iim -Name # runs all the macros in the folder
#$macro += "Filter.iim"
#$macro += "SavePdf.iim"
$countMacros = $macro.Length

# Start browser
$i = $iim1.iimOpen($Browser, "false")
Write-Host "Start browser, return message:" $i $iim1.iimGetErrorText() -ForegroundColor Green

# Execute macro and store the result
Write-Host "Execute test macros" -ForegroundColor Green    
$m = 0
foreach ($element in $macro)
    #Create new row in the table
    $ResultRow = New-Object PSObject
    Add-Member -InputObject $ResultRow -MemberType NoteProperty -Name "No" -Value ""
    Add-Member -InputObject $ResultRow -MemberType NoteProperty -Name Time -Value ""
    Add-Member -InputObject $ResultRow -MemberType NoteProperty -Name "Macro Name" -Value ""
    Add-Member -InputObject $ResultRow -MemberType NoteProperty -Name "Return Result" -Value ""
    Add-Member -InputObject $ResultRow -MemberType NoteProperty -Name "Return Message" -Value ""

    #Retrieve results
    #Macro No.
    $ResultRow."No" = $m + 1

    # Date
    $ResultRow.Time = Get-Date -Format HH:mm:ss
    $ResultRow."Macro Name" = $macro[$m]
    # Return Result
    $ResultRow."Return Result" = $iim1.iimPlay("$iMacrosPath\"+$macro[$m])

    # Return Message
    $ResultRow."Return Message" = $iim1.iimGetErrorText()

    #Save the row to the result table
    $ResultTable += $ResultRow  

#Create GridView of the results
$ResultTable | Export-Clixml -Path $PSScriptRoot\Self-Test-Results.xml
$Date = (Get-Date -Format f)
Import-Clixml -Path $PSScriptRoot\Self-Test-Results.xml | Out-GridView -Title "iMacros Demos Self Test Results ($Date)"
Write-Host "End Test" -ForegroundColor Yellow

$i = $iim1.iimClose()