diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Actions/ActionKey.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Actions/ActionKey.cs index 41fd9ab..bc31b6d 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Actions/ActionKey.cs +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Actions/ActionKey.cs @@ -1,11 +1,9 @@ -using OpenQA.Selenium; - -namespace Aquality.WinAppDriver.Actions +namespace Aquality.WinAppDriver.Actions { /// /// Represents action keys which could be used in . /// Used to enhance logging of SendKeys actions - /// Directly related to + /// Directly related to /// public enum ActionKey { diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Actions/ApplicationActions.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Actions/ApplicationActions.cs index 99c17b0..1608609 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Actions/ApplicationActions.cs +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Actions/ApplicationActions.cs @@ -14,7 +14,6 @@ public abstract class ApplicationActions private readonly ILocalizedLogger localizedLogger; private readonly Func> windowsDriverSupplier; - /// /// Instantiates Application actions. /// diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Actions/ModifierKey.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Actions/ModifierKey.cs index f87a8ca..17ae15d 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Actions/ModifierKey.cs +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Actions/ModifierKey.cs @@ -1,10 +1,8 @@ -using OpenQA.Selenium; - -namespace Aquality.WinAppDriver.Actions +namespace Aquality.WinAppDriver.Actions { /// /// Represents modifier keys which could be used in . - /// Directly related to + /// Directly related to /// public enum ModifierKey { @@ -33,10 +31,6 @@ public enum ModifierKey /// LeftShift, /// - /// Represents the function key META. - /// - Meta, - /// /// Represents the Shift key. /// Shift diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.xml b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.xml index 3c52247..c6e1ab9 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.xml +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.xml @@ -685,7 +685,8 @@ - Is remote WinAppDriver service or not: true to use and false to create default . + Is remote WinAppDriver service or not: true to use + and false to create default . diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Configurations/IApplicationProfile.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Configurations/IApplicationProfile.cs index b52525b..f89a006 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Configurations/IApplicationProfile.cs +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Configurations/IApplicationProfile.cs @@ -1,5 +1,4 @@ using System; -using OpenQA.Selenium.Appium.Service; namespace Aquality.WinAppDriver.Configurations { @@ -9,7 +8,8 @@ namespace Aquality.WinAppDriver.Configurations public interface IApplicationProfile { /// - /// Is remote WinAppDriver service or not: true to use and false to create default . + /// Is remote WinAppDriver service or not: true to use + /// and false to create default . /// bool IsRemote { get; } diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Aquality.WinAppDriver.Tests.csproj b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Aquality.WinAppDriver.Tests.csproj index af6dcfa..269429c 100644 --- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Aquality.WinAppDriver.Tests.csproj +++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Aquality.WinAppDriver.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1 + netcoreapp3.1 false @@ -12,7 +12,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/ScreenshotProvider.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/ScreenshotProvider.cs new file mode 100644 index 0000000..7350857 --- /dev/null +++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/ScreenshotProvider.cs @@ -0,0 +1,45 @@ +using Aquality.WinAppDriver.Applications; +using System; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; + +namespace Aquality.WinAppDriver.Tests +{ + internal class ScreenshotProvider + { + private readonly IWindowsApplication application; + + internal ScreenshotProvider(IWindowsApplication application) + { + this.application = application; + } + + internal string TakeScreenshot() + { + var image = GetImage(); + var directory = Path.Combine(Environment.CurrentDirectory, "screenshots"); + EnsureDirectoryExists(directory); + var screenshotName = $"{GetType().Name}_{DateTime.Now:yyyyMMdd_HHmmss}_{Guid.NewGuid().ToString("n").Substring(0, 5)}.png"; + var path = Path.Combine(directory, screenshotName); + image.Save(path, ImageFormat.Png); + return path; + } + + private Image GetImage() + { + using (var stream = new MemoryStream(application.RootSession.GetScreenshot().AsByteArray)) + { + return Image.FromStream(stream); + } + } + + private static void EnsureDirectoryExists(string directory) + { + if (!Directory.Exists(directory)) + { + Directory.CreateDirectory(directory); + } + } + } +} diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/TestWithApplication.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/TestWithApplication.cs index 57ef01b..18f96d0 100644 --- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/TestWithApplication.cs +++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/TestWithApplication.cs @@ -1,5 +1,6 @@ using Aquality.WinAppDriver.Applications; using NUnit.Framework; +using NUnit.Framework.Interfaces; namespace Aquality.WinAppDriver.Tests { @@ -11,6 +12,11 @@ public virtual void CleanUp() { if (AqualityServices.IsApplicationStarted) { + if (TestContext.CurrentContext.Result.Outcome.Status != TestStatus.Passed) + { + TestContext.AddTestAttachment(new ScreenshotProvider(AqualityServices.Application).TakeScreenshot()); + } + AqualityServices.Application.Quit(); } AqualityServices.TryToStopAppiumLocalService(); diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5662657..64c0de3 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -25,8 +25,12 @@ steps: extraProperties: | sonar.coverage.exclusions=**/** -- script: dotnet build Aquality.WinAppDriver/Aquality.WinAppDriver.sln -c $(buildConfiguration) - displayName: 'Build solution - $(buildConfiguration)' +- task: DotNetCoreCLI@2 + displayName: 'Build solution' + inputs: + command: 'build' + projects: Aquality.WinAppDriver/Aquality.WinAppDriver.sln + arguments: -c $(buildConfiguration) - task: SonarCloudAnalyze@1 displayName: 'Run SonarCloud code analysis' @@ -36,6 +40,13 @@ steps: displayName: 'Publish SonarCloud quality gate results' continueOnError: true +- task: ScreenResolutionUtility@1 + displayName: 'Set up screen resolution 1920x1080' + inputs: + displaySettings: 'specific' + width: '1920' + height: '1080' + - task: Windows Application Driver@0 displayName: 'Start WinAppDriver' inputs: @@ -50,21 +61,12 @@ steps: publishTestResults: true - task: Windows Application Driver@0 - displayName: stop WinAppDriver + displayName: Stop WinAppDriver inputs: OperationType: 'Stop' - script: dotnet pack Aquality.WinAppDriver\src\Aquality.WinAppDriver\Aquality.WinAppDriver.csproj -c $(buildConfiguration) --no-build -p:Version=$(GitVersion.NuGetVersion) -o $(Build.ArtifactStagingDirectory) - displayName: 'Create NuGet package' - condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - -- task: NuGetCommand@2 - displayName: 'Push NuGet package' - inputs: - command: 'push' - packagesToPush: '$(Build.ArtifactStagingDirectory)/**/Aquality.WinAppDriver*.nupkg;!$(Build.ArtifactStagingDirectory)/**/Aquality.WinAppDriver*.symbols.nupkg' - nuGetFeedType: 'external' - publishFeedCredentials: 'NuGet' + displayName: 'Pack to NuGet package' condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - task: GitHubRelease@0 @@ -76,4 +78,10 @@ steps: tag: 'v$(GitVersion.NuGetVersion)' tagSource: 'manual' isPreRelease: contains(variables['GitVersion.NuGetVersion'], '-') + condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) + +- task: PublishBuildArtifacts@1 + inputs: + targetPath: '$(Build.ArtifactStagingDirectory)' + artifactName: '_aquality-automation.aquality-winappdriver-dotnet' condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) \ No newline at end of file