Saturday, May 6, 2017

Create pester test to check the status of the web site

The following powershell script will run the pester test and the test will pass when the website is up and running and fail when the web site state is other than started

We can also include this test as part of the pipeline in VSTS and publish the test results 


Param(
        [string]$computerName,
        [string]$webSiteName
    )
    describe ‘Check Web Site Status’ {
    
    #$secpasswd = ConvertTo-SecureString “PlainTextPassword” -AsPlainText -Force
    #$mycreds = New-Object System.Management.Automation.PSCredential (“username”, $secpasswd)
    $credentials = Get-Credential
     it ‘Checks if the web site is in started state after deployment’ {
        
        Invoke-Command -ComputerName $computerName -ScriptBlock {
            Import-Module WebAdministration;
            $webSite = Get-Website -Name $webSiteName
            if($webSite.state -eq "Started")
            {
                return $true
            }
            else
            {
                return $false
            }
        } -Credential $credentials | Should Be $true

     }
    
 }

No comments:

Post a Comment