Skip to content

Commit

Permalink
Update to NUnit 4
Browse files Browse the repository at this point in the history
Update to .Net 8, update coding style.
  • Loading branch information
mialeska committed Jan 23, 2024
1 parent 20edc1b commit cb8391f
Show file tree
Hide file tree
Showing 25 changed files with 73 additions and 130 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
* @pavelanihimovsky
* @mialeska
* @mpushnikA1QA
4 changes: 2 additions & 2 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="Allure.NUnit" Version="2.11.0" />
<PackageReference Include="Humanizer" Version="2.14.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<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>
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
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 @@ -31,14 +31,14 @@ public static SKImage GetExpectedImageFromResourse(string expectedImageResourse)
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();
private const string ServicesTabItem = "Services";
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" };
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 @@ -8,14 +8,15 @@

<ItemGroup>
<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.15" />
<PackageReference Include="nunit" Version="3.13.3" />
<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>
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Schema;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using RestSharp;
using System;
using System.Collections.Generic;
Expand All @@ -12,14 +13,9 @@
namespace Aquality.Selenium.Template.SpecFlow.StepDefinitions.API.Common
{
[Binding]
public class ResponseSteps
public class ResponseSteps(ScenarioContext scenarioContext)
{
private readonly ScenarioContext scenarioContext;

public ResponseSteps(ScenarioContext scenarioContext)
{
this.scenarioContext = scenarioContext;
}
private readonly ScenarioContext scenarioContext = scenarioContext;

[Then(@"the status code of the '(.*response.*)' is '(\d*)'")]
public static void StatusCodeOfResponseIs(RestResponse response, int statusCode)
Expand All @@ -45,17 +41,15 @@ public static void CheckFieldInResponse(string fieldName, object expectedValue,
public static void AssertResponseSchemaIsValid(RestResponse response, string schemaName)
{
var schemaPath = Path.Combine(AppContext.BaseDirectory, "Resources", "JsonSchemas", $"{schemaName}.json");
using (StreamReader file = File.OpenText(schemaPath))
using (JsonTextReader reader = new JsonTextReader(file))
using StreamReader file = File.OpenText(schemaPath);
using JsonTextReader reader = new(file);
JSchema schema = JSchema.Load(reader, new JSchemaReaderSettings
{
JSchema schema = JSchema.Load(reader, new JSchemaReaderSettings
{
Resolver = new JSchemaUrlResolver(),
BaseUri = new Uri(schemaPath)
});
AttachmentHelper.AddAttachmentAsJson("json schema", schema);
Assert.That(response.GetBodyAsJson().IsValid(schema), "Json schema should match to expected");
}
Resolver = new JSchemaUrlResolver(),
BaseUri = new Uri(schemaPath)
});
AttachmentHelper.AddAttachmentAsJson("json schema", schema);
Assert.That(response.GetBodyAsJson().IsValid(schema), "Json schema should match to expected");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,10 @@
namespace Aquality.Selenium.Template.SpecFlow.StepDefinitions.API.GitHub
{
[Binding]
public class RequestSteps
public class RequestSteps(RequestHandler requestHandler, ScenarioContext scenarioContext)
{
private readonly RequestHandler requestHandler;
private readonly ScenarioContext scenarioContext;

public RequestSteps(RequestHandler requestHandler, ScenarioContext scenarioContext)
{
this.requestHandler = requestHandler;
this.scenarioContext = scenarioContext;
}

private readonly RequestHandler requestHandler = requestHandler;
private readonly ScenarioContext scenarioContext = scenarioContext;

[When(@"I send GET '/([\w-/]+)' request to github with saving the '(.*response.*)'")]
[When(@"I send GET request to github endpoint saved as '(.*)' with saving the '(.*response.*)'")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@
namespace Aquality.Selenium.Template.SpecFlow.StepDefinitions.API.GitHub
{
[Binding]
public class UserSteps
public class UserSteps(ScenarioContext scenarioContext)
{
private readonly ScenarioContext scenarioContext;

public UserSteps(ScenarioContext scenarioContext)
{
this.scenarioContext = scenarioContext;
}

private readonly ScenarioContext scenarioContext = scenarioContext;

[When(@"I save the user from the '(.*response.*)' as '(.*)'")]
public void SaveTheUserFromTheResponse(RestResponse response, string key)
Expand All @@ -28,7 +22,7 @@ public void CheckUsersAreDifferent(string user1Key, string user2Key)
{
var user1 = scenarioContext.Get<User>(user1Key);
var user2 = scenarioContext.Get<User>(user2Key);
Assert.AreNotEqual(user1, user2, "Users should not be equal");
Assert.That(user1, Is.Not.EqualTo(user2), "Users should not be equal");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
namespace Aquality.Selenium.Template.SpecFlow.StepDefinitions.UI
{
[Binding]
public class ContactUsPageSteps
public class ContactUsPageSteps(ContactUsPage contactUsPage)
{
private readonly ContactUsPage contactUsPage;

public ContactUsPageSteps(ContactUsPage contactUsPage)
{
this.contactUsPage = contactUsPage;
}
private readonly ContactUsPage contactUsPage = contactUsPage;

[When(@"I accept Privacy and Cookies Policy")]
public void IAcceptPrivacyAndCookiesPolicy()
Expand Down Expand Up @@ -45,13 +40,13 @@ public void IClickSendButton()
[Then(@"Contact us page is opened")]
public void ContactUsPageIsOpened()
{
Assert.IsTrue(contactUsPage.State.WaitForDisplayed(), "Contact us page should be opened");
Assert.That(contactUsPage.State.WaitForDisplayed(), "Contact us page should be opened");
}

[Then(@"Notification about empty fields is present")]
public void ThenNotificationAboutEmptyFieldsIsPresent()
{
Assert.IsTrue(contactUsPage.IsEmailValidationMessagePresent,
Assert.That(contactUsPage.IsEmailValidationMessagePresent,
"Email validation message should be displayed");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@
namespace Aquality.Selenium.Template.SpecFlow.StepDefinitions.UI
{
[Binding]
public class MainPageSteps
public class MainPageSteps(MainPage mainPage, TopBarMenu topBarMenu)
{
private readonly MainPage mainPage;
private readonly TopBarMenu topBarMenu;

public MainPageSteps(MainPage mainPage, TopBarMenu topBarMenu)
{
this.mainPage = mainPage;
this.topBarMenu = topBarMenu;
}
private readonly MainPage mainPage = mainPage;
private readonly TopBarMenu topBarMenu = topBarMenu;

[Given(@"Main page is opened")]
public static void MainPageIsOpened()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@
namespace Aquality.Selenium.Template.SpecFlow.Transformations.API
{
[Binding]
public class ContextTransformations
public class ContextTransformations(ScenarioContext scenarioContext)
{
private readonly ScenarioContext scenarioContext;

public ContextTransformations(ScenarioContext scenarioContext)
{
this.scenarioContext = scenarioContext;
}
private readonly ScenarioContext scenarioContext = scenarioContext;

[StepArgumentTransformation("(.*response.*)")]
public RestResponse Response(string key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="AspectInjector" Version="2.8.2" />
<PackageReference Include="Humanizer" Version="2.14.1" />
<PackageReference Include="AqualityTracking.Integrations.Core" Version="1.0.1" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit" Version="4.0.1" />
<PackageReference Include="RestSharp" Version="110.2.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.7" />
</ItemGroup>
Expand Down
Loading

0 comments on commit cb8391f

Please sign in to comment.