Without futher ado, here is the RESTful method to run Fitnesse tests.
First I set up my variables, I've also added in an archive file now, so I can keep track of my results, the RESTful results are nice so I actually output each test into its own results file, and I make an aggregate to be an archive. Eventually I will get rid of the individual results and keep the archive around - this also let's me go onto any machine that ran a test and see how things have been going. The Arrays I have are suites that I set up in Fitnesse to contain my tests, I have one for QA that I would run, and a Smoke suite that is a selected set to verify the build worked.
Then I still run my check on whether Fitnesse is running, it doesn't really need to be running anyway; so I decided that since REST only runs as needed then I was going to shut down Fitnesse if it was going.
# Get the current directory Push-Location .
# Variables for the script
# This location should not change, since its the standard checkout location [string]$fitnesseLocale = "C:\MAIN\trunk\AutomatedTests\Fitnesse\Fitnesse"
[string]$fitnesseJar = "fitnesse.jar"
# Need to get the local machine here, it will be how Fitnesse runs [string]$serverName = $env:COMPUTERNAME
[string]$portName = "8080"
# These are needed for the CheckFitnessProcess function,
# placing them here $fitRunning = $false
# Set Java executable to use within PowerShell $Java = "java.exe"
# Archive file $archiveFile = "fitnesseArchive.txt"
# Use a Test Array to be able to bundle all the tests
# Tests that are commented out are having issues being run
# Smoke Testing is Development Based
# although its now geared towards checking Login $smokeArray = ( "SpringsLoginLiteTests" )
# Tests for the QA environment
# although its now geared towards checking page links $qaArray = ( "SpringsLinkChecks" )
# Tests to check how this script runs, this is a hidden command
# This just validates the Registration Verify Fields $checkArray = ( "SpringsTest.UserLoginFfTests" )
# Location of the Test Results, this is hardcoded within the SVN structure
# so it should always be available, I am sure there are better ways of doing this $testResultsDir = "C:\IHI_MAIN\trunk\AutomatedTests\Fitnesse\Fitnesse\testResults"
if (!(Test-Path -path $testResultsDir))
{
New-Item $testResultsDir -type directory > $null
}
# CheckFitnesseProcess determines if Fitnesse is running, if Fitnesse is not runningI'm going to skip the Help function, if you need that it should be in my previous post, the important one is the Main function.
# then the script continues. The current test configuration does not require Fitnesse
# to run and does a better job when it's not.
# Adapted from: http://odetocode.com/Blogs/scott/archive/2006/07/17/5330.aspx function CheckFitnesseProcess {
param ([string]$AppPoolName="" )
$ProcessId = $null
if ($AppPoolName.ToUpper() -ne $NOT_PASSED) {
[string]$filter = $null
if ((Get-Process java -ErrorAction SilentlyContinue) -ne $null) {
Get-Process java | ForEach {
# use WMI API to get process details
$filter = "Handle='" + $_.Id + "'"
$wmip = Get-WmiObject Win32_Process -filter $filter
# CommandLine property has AppPool name; grab name using contains
if($wmip.CommandLine.contains("fitnesse")) {
# Uncomment the next line for debugging
# Write-Host "Found this java process: $wmip.CommandLine `n"
$fitRunning = $true
# Saving the Process ID to stop the process later,
# using a Global as I could not get this work if I declared
# the variable at the beginning.
$Global:fitProcess = $_.Id
}
}
}
if ($fitRunning -eq $false) {
# All is good
}
if ($fitRunning -eq $true) {
Write-Host "Fitnesse is running, it's best if its not - shutting it down...`n" -ForegroundColor Red
# Stop the Fitnesse process
Stop-Process -Id $fitProcess
}
}
}
function main()
{
# Need to be in the Fitnesse directory to access TestRunner, and# the Fitnesse batch file in case Fitnesse needs to be startedcd $fitnesseLocale#Check and see if Fitnesse is runningCheckFitnesseProcessforeach ($test in $testArray){# Start the test$myDate = Get-DateWrite-Host "`nRunning $test`n"# Build RESTful URL$testLink = $test +"?" + $testType +"&format=text"# Get the output from TestRunner so we can scrape it for test passes and fails$testResults = & $Java "-jar" "$fitnesseJar" "-c" "$testLink"Write-Host "Completed $test`n"# Write-Host "Test Results..."# Scan through the output, then display the results# Dump $testResults out to a File$testFile = $test + $myDate.Day + $myDate.Month + $myDate.Year + $myDate.Hour + $myDate.Minute + ".txt"$testResults | Out-File "$testResultsDir\$testFile"# Print out date to an archive file$testDate = "Last run time: " + $myDate.Day + "/" + $myDate.Month + "/" + $myDate.Year + " at " + $myDate.Hour + ":" + $myDate.Minute$testDate >> "$testResultsDir\$archiveFile"foreach ($line in $testResults){if ($line -match "\A\.\s"){# This is a PassWrite-Host $line -ForegroundColor Green# Output to archive file$line >> "$testResultsDir\$archiveFile"}if ($line -match "\AX\s") {# This is an Exception, a warning but not a FailureWrite-Host $line -ForegroundColor Yellow# Output to archive file$line >>
No comments:
Post a Comment