From 603d26bb5f987634141962cd1dba53ad40390b59 Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 8 Oct 2020 00:07:52 -0400 Subject: [PATCH] Take Screenshot on Automation tests for build status notifications --- azure-pipelines.yml | 18 +++++++++++++++- .../AutomationTest.cs | 15 +++++++++++++ src/NzbDrone.Automation.Test/MainPagesTest.cs | 21 ++++++++++++++++--- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ede959770..a1035f5b4 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -711,6 +711,16 @@ stages: chmod a+x ${TESTSFOLDER}/test.sh ${TESTSFOLDER}/test.sh ${OSNAME} Automation Test displayName: Run Automation Tests + - task: CopyFiles@2 + displayName: 'Copy Screenshot to: $(Build.ArtifactStagingDirectory)' + inputs: + SourceFolder: '$(Build.SourcesDirectory)' + Contents: | + **/*_test_screenshot.png + TargetFolder: '$(Build.ArtifactStagingDirectory)/screenshots' + - publish: $(Build.ArtifactStagingDirectory)/screenshots + artifact: '$(osName)AutomationScreenshots' + displayName: Publish Screenshot Bundle - task: PublishTestResults@2 inputs: testResultsFormat: 'NUnit' @@ -859,8 +869,14 @@ stages: - job: displayName: Discord Notification pool: - vmImage: 'ubuntu-18.04' + vmImage: 'windows-2019' steps: + - task: DownloadPipelineArtifact@2 + displayName: Download Screenshot Artifact + inputs: + buildType: 'current' + artifactName: 'WindowsAutomationScreenshots' + targetPath: $(Build.SourcesDirectory) - checkout: none - powershell: | iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/Servarr/AzureDiscordNotify/master/DiscordNotify.ps1')) diff --git a/src/NzbDrone.Automation.Test/AutomationTest.cs b/src/NzbDrone.Automation.Test/AutomationTest.cs index 6d660e358..da3ee0855 100644 --- a/src/NzbDrone.Automation.Test/AutomationTest.cs +++ b/src/NzbDrone.Automation.Test/AutomationTest.cs @@ -42,6 +42,8 @@ namespace NzbDrone.Automation.Test // Timeout as windows automation tests seem to take alot longer to get going driver = new ChromeDriver(service, options, new TimeSpan(0, 3, 0)); + driver.Manage().Window.Size = new System.Drawing.Size(1920, 1080); + _runner = new NzbDroneRunner(LogManager.GetCurrentClassLogger()); _runner.KillAll(); _runner.Start(); @@ -62,6 +64,19 @@ namespace NzbDrone.Automation.Test .Select(e => e.Text); } + protected void TakeScreenshot(string name) + { + try + { + Screenshot image = ((ITakesScreenshot)driver).GetScreenshot(); + image.SaveAsFile($"./{name}_test_screenshot.png", ScreenshotImageFormat.Png); + } + catch (Exception ex) + { + Console.WriteLine($"Failed to save screenshot {name}, {ex.Message}"); + } + } + [OneTimeTearDown] public void SmokeTestTearDown() { diff --git a/src/NzbDrone.Automation.Test/MainPagesTest.cs b/src/NzbDrone.Automation.Test/MainPagesTest.cs index acf8c2b05..713a7144c 100644 --- a/src/NzbDrone.Automation.Test/MainPagesTest.cs +++ b/src/NzbDrone.Automation.Test/MainPagesTest.cs @@ -1,4 +1,5 @@ -using FluentAssertions; +using System.Reflection; +using FluentAssertions; using NUnit.Framework; using NzbDrone.Automation.Test.PageModel; using OpenQA.Selenium; @@ -21,6 +22,10 @@ namespace NzbDrone.Automation.Test { _page.MovieNavIcon.Click(); _page.WaitForNoSpinner(); + + var imageName = MethodBase.GetCurrentMethod().Name; + TakeScreenshot(imageName); + _page.Find(By.CssSelector("div[class*='MovieIndex']")).Should().NotBeNull(); } @@ -30,6 +35,9 @@ namespace NzbDrone.Automation.Test _page.CalendarNavIcon.Click(); _page.WaitForNoSpinner(); + var imageName = MethodBase.GetCurrentMethod().Name; + TakeScreenshot(imageName); + _page.Find(By.CssSelector("div[class*='CalendarPage']")).Should().NotBeNull(); } @@ -39,6 +47,9 @@ namespace NzbDrone.Automation.Test _page.ActivityNavIcon.Click(); _page.WaitForNoSpinner(); + var imageName = MethodBase.GetCurrentMethod().Name; + TakeScreenshot(imageName); + _page.Find(By.LinkText("Queue")).Should().NotBeNull(); _page.Find(By.LinkText("History")).Should().NotBeNull(); _page.Find(By.LinkText("Blacklist")).Should().NotBeNull(); @@ -50,6 +61,9 @@ namespace NzbDrone.Automation.Test _page.SystemNavIcon.Click(); _page.WaitForNoSpinner(); + var imageName = MethodBase.GetCurrentMethod().Name; + TakeScreenshot(imageName); + _page.Find(By.CssSelector("div[class*='Health']")).Should().NotBeNull(); } @@ -58,11 +72,12 @@ namespace NzbDrone.Automation.Test { _page.MovieNavIcon.Click(); _page.WaitForNoSpinner(); - _page.Find(By.LinkText("Add New")).Click(); - _page.WaitForNoSpinner(); + var imageName = MethodBase.GetCurrentMethod().Name; + TakeScreenshot(imageName); + _page.Find(By.CssSelector("input[class*='AddNewMovie-searchInput']")).Should().NotBeNull(); } }