Skip to content

Commit

Permalink
Take screenshots during UI tests and upload them as artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuBuisson committed Jul 16, 2017
1 parent 6c2ca3c commit 804d767
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions PSCodeHealth.BuildSettings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ $Settings = @{
GitHubKey = $env:GitHub_Key
Email = 'MathieuBuisson@users.noreply.github.com'
Name = 'Mathieu Buisson'
ScreenshotPath = "$($env:TEMP)\*Screenshot.png"
}
13 changes: 12 additions & 1 deletion PSCodeHealth.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,23 @@ task Upload_Test_Results_To_AppVeyor {
}
}

task Upload_Test_Screenshots_To_Appveyor {
Write-TaskBanner -TaskName $Task.Name

$ScreenShots = Get-ChildItem -Path $Settings.ScreenshotPath
Foreach ( $ScreenShot in $ScreenShots ) {
"Uploading file $($Screenshot.Name) as an Appveyor artifact"
Push-AppveyorArtifact $ScreenShot.FullName
}
}

task Test Unit_Tests,
Fail_If_Failed_Unit_Test,
Publish_Unit_Tests_Coverage,
Integration_Tests,
Fail_If_Failed_Integration_Test,
Upload_Test_Results_To_AppVeyor
Upload_Test_Results_To_AppVeyor,
Upload_Test_Screenshots_To_Appveyor

task Analyze {
Write-TaskBanner -TaskName $Task.Name
Expand Down
8 changes: 8 additions & 0 deletions Tests/Integration/HtmlReport.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,17 @@ Describe 'HTML Report UI tests' {
$Driver = New-Object OpenQA.Selenium.Chrome.ChromeDriver
$Driver.Manage().Window.Maximize()
$Driver.Navigate().GoToUrl($ReportUrl)
$summarySectionScreen = $Driver.GetScreenShot()
$summarySectionScreen.SaveAsFile("$($env:TEMP)\SummarySectionScreenshot.png", [OpenQA.Selenium.ScreenshotImageFormat]::Png)

Context 'Given the "bestPractices" link in the sidebar has been clicked' {

$Driver.FindElementByPartialLinkText(' Best Practices').Click()
$bestPracticesSection = $Driver.FindElementById('bestPractices')
$bestPracticesPerFunctionTable = $bestPracticesSection.FindElementsByCssSelector('div.table-responsive')
$Button = $bestPracticesPerFunctionTable.FindElementByTagName('button')
$bestPracticesSectionScreen = $Driver.GetScreenShot()
$bestPracticesSectionScreen.SaveAsFile("$($env:TEMP)\BestPracticesSectionScreenshot.png", [OpenQA.Selenium.ScreenshotImageFormat]::Png)

It 'Should make the "bestPractices" section active' {

Expand Down Expand Up @@ -182,6 +186,8 @@ Describe 'HTML Report UI tests' {
$Driver.FindElementByLinkText('Maintainability').Click()
$maintainabilitySection = $Driver.FindElementById('maintainability')
$maintainabilityPerFunctionTable = $maintainabilitySection.FindElementsByCssSelector('div.table-responsive')
$maintainabilitySectionScreen = $Driver.GetScreenShot()
$maintainabilitySectionScreen.SaveAsFile("$($env:TEMP)\MaintainabilitySectionScreenshot.png", [OpenQA.Selenium.ScreenshotImageFormat]::Png)

It 'Should make the "maintainability" section active' {
Start-Sleep -Seconds 2
Expand Down Expand Up @@ -212,6 +218,8 @@ Describe 'HTML Report UI tests' {
$testsSection = $Driver.FindElementById('tests')
$testsTablePanels = $testsSection.FindElementsByClassName('tablePanel')
$testsTableTitles = $testsTablePanels.FindElementsByClassName('panel-title')
$testsSectionScreen = $Driver.GetScreenShot()
$testsSectionScreen.SaveAsFile("$($env:TEMP)\TestsSectionScreenshot.png", [OpenQA.Selenium.ScreenshotImageFormat]::Png)

It 'Should make the "Tests" section active' {
Start-Sleep -Seconds 2
Expand Down

0 comments on commit 804d767

Please sign in to comment.