Skip to content

Commit

Permalink
Upgrade to .NET 8 and update package versions (#18)
Browse files Browse the repository at this point in the history
Breaking changes:
- Update to NUnit 4
- Update to .Net 8
- Update coding style to use latest C# features.
- Update to use latest package versions, including Aquality.Selenium 4.13. 
  - WebDriverManager is dismissed for all browsers but Opera
  - Selenium version updated to 4.16.2
 
Also:
- Replace deprecated Allure packages and functions with actual ones
- Update BaseTest and BaseWebTest to take screenshot properly in case of the test failure
- Update HeaderTabItems in TopBarMenuSteps to fix TC0002_CheckThePossibilityToChangeTheLanguageFromGermanToEnglish
- Slightly update step logging, remove "method" wording from steps
- Attach expected image in CustomImageComparatorSteps.GetExpectedImageFromResourse
- Move aqualityTracking.json config to Template project resources for proper artifacts attaching in both NUnit and SpecFlow projects
- Update settings.json, replace outdated capabilities, remove webDriverVersion, add required opera settings
- Suppress namespace issues for Aquality wording
- Address other warnings and code enhancements
  • Loading branch information
mialeska authored Jan 24, 2024
1 parent 5258f0e commit b006e81
Show file tree
Hide file tree
Showing 40 changed files with 180 additions and 228 deletions.
3 changes: 2 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* @pavelanihimovsky
* @paveliam
* @mialeska
6 changes: 3 additions & 3 deletions .github/workflows/test-with-allure-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
env:
BUILD_CONFIGURATION: Release
SOLUTION_NAME: Aquality.Selenium.Template/Aquality.Selenium.Template.sln
ALLURE_RESULTS: Aquality.Selenium.Template/Aquality.Selenium.Template.SpecFlow/bin/Release/net6.0/allure-results
ALLURE_NUNIT_RESULTS: Aquality.Selenium.Template/Aquality.Selenium.Template.NUnit/bin/Release/net6.0/allure-results
ALLURE_RESULTS: Aquality.Selenium.Template/Aquality.Selenium.Template.SpecFlow/bin/Release/net8.0/allure-results
ALLURE_NUNIT_RESULTS: Aquality.Selenium.Template/Aquality.Selenium.Template.NUnit/bin/Release/net8.0/allure-results
ENVIRONMENT: ${{ github.event.inputs.environment == '' && 'Stage' || github.event.inputs.environment }}
GH_PAGES_URL: https://aquality-automation.github.io/aquality-selenium-dotnet-template
concurrency: test-${{ github.event.inputs.environment == '' && 'Stage' || github.event.inputs.environment }}
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x

- name: Install Google Chrome
run: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand All @@ -17,12 +17,12 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Allure.NUnit" Version="2.11.0" />
<PackageReference Include="Humanizer" Version="2.14.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit.Allure" Version="1.2.1.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="4.0.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public static class FormExtensions
{
public static void AssertIsPresent(this Form form)
{
Assert.IsTrue(form.State.WaitForDisplayed(), $"{form.Name} should be presented");
Assert.That(form.State.WaitForDisplayed(), $"{form.Name} should be presented");
}

public static void AssertIsNotPresent(this Form form)
{
Assert.IsTrue(form.State.WaitForNotDisplayed(), $"{form.Name} should not be presented");
Assert.That(form.State.WaitForNotDisplayed(), $"{form.Name} should not be presented");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Naming", "VSSpell001:Spell Check", Justification = "<Pending>", Scope = "namespaceanddescendants", Target = "~N:Aquality.Selenium.Template.NUnit")]
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Aquality.Selenium.Template.NUnit.Steps
{
public class ContactUsPageSteps
{
private readonly ContactUsPage contactUsPage = new ContactUsPage();
private readonly ContactUsPage contactUsPage = new();
private readonly ContactUsInfo contactUsInfo = JsonConvert.DeserializeObject<ContactUsInfo>(FileReader.GetTextFromEmbeddedResource(ResourceConstants.PathToContactUserWithInvalidEmail, Assembly.GetCallingAssembly()));

[LogStep(StepType.Assertion)]
Expand All @@ -33,19 +33,19 @@ public void CheckThatTheContactUsFormElementsAreDisplayed()
{
foreach(ContactUsTextFields name in Enum.GetValues(typeof(ContactUsTextFields)))
{
Assert.IsTrue(contactUsPage.IsContactUsTextBoxPresent(name), $"Text field {name} should be displayed");
Assert.That(contactUsPage.IsContactUsTextBoxPresent(name), $"Text field {name} should be displayed");
}
Assert.IsTrue(contactUsPage.IsTermsCheckBoxExist, "Terms checkBox should be exist");
Assert.IsTrue(contactUsPage.IsTermsLabelPresent, "Terms label should be displayed");
Assert.IsTrue(contactUsPage.IsSendAMessageButtonPresent, "Send a message button should be displayed");
Assert.IsTrue(contactUsPage.IsTitleLabelPresent, "Title should be displayed");
Assert.That(contactUsPage.IsTermsCheckBoxExist, "Terms checkBox should be exist");
Assert.That(contactUsPage.IsTermsLabelPresent, "Terms label should be displayed");
Assert.That(contactUsPage.IsSendAMessageButtonPresent, "Send a message button should be displayed");
Assert.That(contactUsPage.IsTitleLabelPresent, "Title should be displayed");
});
}

[LogStep(StepType.Assertion)]
public void CheckThanContactUsTitleIsCorrect()
{
Assert.AreEqual(contactUsPage.TitleLabelTextValue, TitleConstants.TitleLabelText, "Title text should be same.");
Assert.That(contactUsPage.TitleLabelTextValue, Is.EqualTo(TitleConstants.TitleLabelText), "Title text should be same.");
}

[LogStep(StepType.Step)]
Expand All @@ -64,7 +64,7 @@ public void CheckTermCheckBox()
public void CheckTermCheckBoxIsCheckedOrNot(bool isChecked = false)
{
var expectedStatus = isChecked ? "checked" : "not checked";
Assert.AreEqual(contactUsPage.IsTermsCheckBoxChecked, isChecked, $"Term CheckBox should be {expectedStatus}");
Assert.That(contactUsPage.IsTermsCheckBoxChecked, Is.EqualTo(isChecked), $"Term CheckBox should be {expectedStatus}");
}

[LogStep(StepType.Step)]
Expand Down Expand Up @@ -94,7 +94,8 @@ public void CheckThatWarningEmailMessageisPresentOrNot(bool isChecked = false)
[LogStep(StepType.Step)]
public void CheckThatWarningEmailMessageIsCorrect()
{
Assert.AreEqual(contactUsPage.WarningEmailMessageTextValue, ContactUsTextFields.Email.GetEnumDescription(), "Warning email message should be correct.");
Assert.That(contactUsPage.WarningEmailMessageTextValue, Is.EqualTo(ContactUsTextFields.Email.GetEnumDescription()),
"Warning email message should be correct.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,22 @@ public CustomImageComparatorSteps(float customThresholdValue, string modelImageR
[LogStep(StepType.Step)]
public static SKImage GetExpectedImageFromResourse(string expectedImageResourse)
{
AttachmentHelper.AddAttachment(expectedImageResourse);
return new FileInfo(expectedImageResourse).ReadImage();
}

[LogStep(StepType.Assertion)]
public void CheckThatActualAndExpectedImagesAreTheSame(SKImage expectedImage)
{
var differenceBetweenImages = customImageComparator.Compare(modelOfImage, expectedImage);
Assert.AreEqual(0, differenceBetweenImages, "The images should be the same");
Assert.That(differenceBetweenImages, Is.Zero, "The images should be the same");
}

[LogStep(StepType.Assertion)]
public void CheckThatActualAndExpectedImagesAreNotTheSame(SKImage expectedImage)
{
var differenceBetweenImages = customImageComparator.Compare(modelOfImage, expectedImage);
Assert.AreNotEqual(0, differenceBetweenImages, "The images should not be the same");
Assert.That(differenceBetweenImages, Is.Not.Zero, "The images should not be the same");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Aquality.Selenium.Template.NUnit.Steps
{
public class FooterFormSteps
{
private readonly FooterForm footerForm = new FooterForm();
private readonly FooterForm footerForm = new();
const float ComparisonThreshold = 0.1f;

[LogStep(StepType.Assertion)]
Expand All @@ -21,9 +21,9 @@ public void CheckVisualElementsPresent()
{
Assert.Multiple(() =>
{
Assert.IsTrue(footerForm.IsLogoPresent, "Logo should be displayed");
Assert.IsTrue(footerForm.IsContactsPresent, "Contacts section should be displayed");
Assert.IsTrue(footerForm.IsSubscribePresent, "Subscribe section should be displayed");
Assert.That(footerForm.IsLogoPresent, "Logo should be displayed");
Assert.That(footerForm.IsContactsPresent, "Contacts section should be displayed");
Assert.That(footerForm.IsSubscribePresent, "Subscribe section should be displayed");
});
}

Expand All @@ -37,7 +37,7 @@ public void SaveDump()
public void CheckThatTheVisualElementsAreCorrect()
{
var compareVisualElements = footerForm.Dump.Compare();
Assert.LessOrEqual(compareVisualElements, ComparisonThreshold, "The footer form should contain the correct visual elements");
Assert.That(compareVisualElements, Is.LessThanOrEqualTo(ComparisonThreshold), "The footer form should contain the correct visual elements");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Aquality.Selenium.Template.NUnit.Steps
{
public class MainPageSteps
{
private readonly MainPage mainPage = new MainPage();
private readonly MainPage mainPage = new();

[LogStep(StepType.Assertion)]
public void MainPageIsPresent()
Expand All @@ -21,7 +21,7 @@ public void MainPageIsPresent()
[LogStep(StepType.Assertion)]
public void AcceptCookiesButtonIsDisplayed()
{
Assert.IsTrue(mainPage.IsAcceptCookiesButtonDisplayed, "Accept cookies button should be displayed");
Assert.That(mainPage.IsAcceptCookiesButtonDisplayed, "Accept cookies button should be displayed");
}

[LogStep(StepType.Assertion)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
using Aquality.Selenium.Template.NUnit.Extensions;
using NUnit.Framework;
using Aquality.Selenium.Template.CustomAttributes;
using NUnit.Framework.Legacy;

namespace Aquality.Selenium.Template.NUnit.Steps
{
public class TopBarMenuSteps
{
private readonly TopBarMenu topBarMenu = new TopBarMenu();
private readonly TopBarMenu topBarMenu = new();
private const string ServicesTabItem = "Services";
private static string[] HeaderTabItems = { "Services", "Approach", "Portfolio", "Blog", "Company" };
private static string[] ServicesTitleElements = { "Full-cycle testing services", "Quality engineering", "Complete test coverage", "Systems & platforms" };
private static readonly string[] HeaderTabItems = ["Services", "Industries", "Approach", "Portfolio", "Blog", "Company"];
private static readonly string[] ServicesTitleElements = ["Full-cycle testing services", "Quality engineering", "Complete test coverage", "Systems & platforms"];

[LogStep(StepType.Assertion)]
public void TopBarMenuIsPresent()
Expand All @@ -27,7 +28,7 @@ public void ClickContactUs()
[LogStep(StepType.Assertion)]
public void ContactUsButtonIsPresent()
{
Assert.IsTrue(topBarMenu.IsContactUsButtonExist, "Contact Us button should be present");
Assert.That(topBarMenu.IsContactUsButtonExist, "Contact Us button should be present");
}

[LogStep(StepType.Assertion)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ protected static string ScenarioName

private static Logger Logger => Logger.Instance;

private static TestContext.ResultAdapter Result => TestContext.CurrentContext.Result;
private readonly ScreenshotProvider screenshotProvider = new ScreenshotProvider();
protected static TestContext.ResultAdapter Result => TestContext.CurrentContext.Result;

[OneTimeSetUp]
public void OneTimeSetUp()
Expand All @@ -43,10 +42,6 @@ private void LogScenarioResult()
Logger.Info($"Scenario [{ScenarioName}] result is {Result.Outcome.Status}!");
if (Result.Outcome.Status != TestStatus.Passed)
{
if (AqualityServices.IsBrowserStarted)
{
AttachmentHelper.AddAttachment(screenshotProvider.TakeScreenshot(), "Screenshot");
}
Logger.Error(Result.Message);
}
Logger.Info(new string('=', 100));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
using Allure.Commons;
using Aquality.Selenium.Browsers;
using Aquality.Selenium.Browsers;
using Aquality.Selenium.Template.Configurations;
using Aquality.Selenium.Template.Utilities;
using NUnit.Allure.Attributes;
using NUnit.Framework;
using NUnit.Framework.Interfaces;

namespace Aquality.Selenium.Template.NUnit.Tests
{
public abstract class BaseWebTest : BaseTest
{
private readonly ScreenshotProvider screenshotProvider = new();

[TearDown]
public void CleanUp()
public override void AfterEach()
{
base.AfterEach();
if (AqualityServices.IsBrowserStarted)
{
if (Result.Outcome.Status != TestStatus.Passed)
{
AttachmentHelper.AddAttachment(screenshotProvider.TakeScreenshot(), "Screenshot");
}
AqualityServices.Browser.Quit();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Aquality.Selenium.Template.NUnit.Tests
public class CustomImageComparatorTest : BaseTest
{
private const float CustomThresholdValue = 0.1f;
private readonly CustomImageComparatorSteps customImageComparatorSteps = new CustomImageComparatorSteps(CustomThresholdValue, ResourceConstants.ActualTestImage);
private readonly CustomImageComparatorSteps customImageComparatorSteps = new(CustomThresholdValue, ResourceConstants.ActualTestImage);


[Test(Description = "TC-0005 Compare 2 images one of which is different")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ namespace Aquality.Selenium.Template.NUnit.Tests
[AllureSuite("Demo Tests")]
public class DemoTest : BaseWebTest
{
private readonly TopBarMenuSteps topBarMenuSteps = new TopBarMenuSteps();
private readonly MainPageSteps mainPageSteps = new MainPageSteps();
private readonly ContactUsPageSteps contactUsFormSteps = new ContactUsPageSteps();
private readonly FooterFormSteps footerFormSteps = new FooterFormSteps();
private readonly TopBarMenuSteps topBarMenuSteps = new();
private readonly MainPageSteps mainPageSteps = new();
private readonly ContactUsPageSteps contactUsFormSteps = new();
private readonly FooterFormSteps footerFormSteps = new();

[SetUp]
public new void Setup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Aquality.Selenium.Template.NUnit.Tests
[AllureSuite("Main Page Demo Test")]
public class MainDemoTest : BaseWebTest
{
private readonly MainPageSteps mainPageSteps = new MainPageSteps();
private readonly MainPageSteps mainPageSteps = new();

[SetUp]
public new void Setup()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aquality.Selenium" Version="4.12.0" />
<Content Remove="C:\Users\a2.meleshko\.nuget\packages\allure.specflow\2.11.0\contentFiles\any\netstandard2.0\allureConfig.Template.json" />
<Content Remove="C:\Users\a2.meleshko\.nuget\packages\aqualitytracking.specflowplugin\1.0.1\contentFiles\any\netstandard2.0\Resources\aqualityTracking.Template.json" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Allure.SpecFlow" Version="2.11.0" />
<PackageReference Include="Aquality.Selenium" Version="4.13.0" />
<PackageReference Include="AqualityTracking.SpecFlowPlugin" Version="1.0.1" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.14" />
<PackageReference Include="nunit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2">
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.15" />
<PackageReference Include="nunit" Version="4.0.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="SpecFlow" Version="3.9.74" />
<PackageReference Include="SpecFlow.Allure" Version="3.5.0.73" />
<PackageReference Include="SpecFlow.NUnit" Version="3.9.74" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.74" />
</ItemGroup>
Expand All @@ -30,9 +35,6 @@
<None Update="allureConfig.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Resources\aqualityTracking.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Resources\JsonSchemas\Users\UserResponse.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Naming", "VSSpell001:Spell Check", Justification = "<Pending>", Scope = "namespaceanddescendants", Target = "~N:Aquality.Selenium.Template.SpecFlow")]
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@
namespace Aquality.Selenium.Template.SpecFlow.Hooks
{
[Binding]
public class BrowserHooks
public class BrowserHooks(ScreenshotProvider screenshotProvider)
{
private readonly ScreenshotProvider screenshotProvider;

public BrowserHooks(ScreenshotProvider screenshotProvider)
{
this.screenshotProvider = screenshotProvider;
}
private readonly ScreenshotProvider screenshotProvider = screenshotProvider;

[AfterScenario(Order = 0)]
public void AttachArtifacts()
Expand Down
Loading

0 comments on commit b006e81

Please sign in to comment.