From 8823f732421ead8e2f4079cdfb0e946d994a5651 Mon Sep 17 00:00:00 2001 From: YASSIR MRANI ALAOUI <85866165+yassir-ai@users.noreply.github.com> Date: Sun, 19 Mar 2023 19:49:03 +0100 Subject: [PATCH] Adding TagsPage scenario (#1920) * add TagsPage * add DeviceTags scenario * Update and rename TagsPage.cs to TagsConfigurationPage.cs * Update and rename DeviceTags.cs to TagsConfiguration.cs --------- Co-authored-by: unknown Co-authored-by: Achraf-Git-dev <78796647+Achraf-Git-dev@users.noreply.github.com> --- .../Pages/TagsConfigurationPage.cs | 52 ++++++++++++++++++ .../TagsConfiguration.cs | 55 +++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 src/AzureIoTHub.Portal.Tests.E2E/Pages/TagsConfigurationPage.cs create mode 100644 src/AzureIoTHub.Portal.Tests.E2E/TagsConfiguration.cs diff --git a/src/AzureIoTHub.Portal.Tests.E2E/Pages/TagsConfigurationPage.cs b/src/AzureIoTHub.Portal.Tests.E2E/Pages/TagsConfigurationPage.cs new file mode 100644 index 000000000..e905964ac --- /dev/null +++ b/src/AzureIoTHub.Portal.Tests.E2E/Pages/TagsConfigurationPage.cs @@ -0,0 +1,52 @@ +// Copyright (c) CGI France. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace AzureIoTHub.Portal.Tests.E2E.Pages +{ + using NUnit.Framework; + using OpenQA.Selenium; + using OpenQA.Selenium.Support.UI; + + public class TagsConfigurationPage + { + public WebDriverWait wait; + + public TagsConfigurationPage() + { + this.wait = new WebDriverWait(WebDriverFactory.Default, TimeSpan.FromSeconds(5)); + + _ = wait.Until(d => d.FindElement(By.CssSelector(".mud-nav-group:nth-child(5) > .mud-collapse-container .mud-nav-link-text")).Displayed); + WebDriverFactory.Default.FindElement(By.CssSelector(".mud-nav-group:nth-child(5) > .mud-collapse-container .mud-nav-link-text")).Click(); + } + + public void NavigateToTagsPage() + { + _ = wait.Until(d => d.FindElement(By.CssSelector(".mud-nav-group:nth-child(5) > .mud-collapse-container .mud-nav-link-text")).Displayed); + WebDriverFactory.Default.FindElement(By.CssSelector(".mud-nav-group:nth-child(5) > .mud-collapse-container .mud-nav-link-text")).Click(); + } + + public void AddTag(string name, string label) + { + _ = wait.Until(d => d.FindElement(By.Id("addTagButton")).Displayed); + WebDriverFactory.Default.FindElement(By.Id("addTagButton")).Click(); + + WebDriverFactory.Default.FindElement(By.CssSelector(".tag- > .mud-table-cell:nth-child(1) .mud-input-slot:nth-child(1)")).Click(); + WebDriverFactory.Default.FindElement(By.CssSelector(".tag- > .mud-table-cell:nth-child(1) .mud-input-slot:nth-child(1)")).SendKeys(name); + + _ = wait.Until(d => d.FindElement(By.CssSelector(".tag- > .mud-table-cell:nth-child(2) .mud-input-slot:nth-child(1)")).Displayed); + WebDriverFactory.Default.FindElement(By.CssSelector(".tag- > .mud-table-cell:nth-child(2) .mud-input-slot:nth-child(1)")).SendKeys(label); + + WebDriverFactory.Default.FindElement(By.CssSelector(".tag-" + name + " #saveButton .mud-icon-root")).Click(); + + _ = wait.Until(d => d.FindElement(By.ClassName("mud-snackbar-content-message")).Displayed); + Assert.That(WebDriverFactory.Default.FindElement(By.ClassName("mud-snackbar-content-message")).Text, Is.EqualTo("Settings have been successfully updated!")); + WebDriverFactory.Default.FindElement(By.CssSelector("button[class='mud-button-root mud-icon-button mud-ripple mud-ripple-icon mud-icon-button-size-small ms-2']")).Click(); + _ = wait.Until(d => !d.FindElement(By.Id("mud-snackbar-container")).Displayed); + } + + public void RemoveTag(string name) + { + WebDriverFactory.Default.FindElement(By.CssSelector(".tag-" + name + " #deleteButton .mud-icon-root")).Click(); + } + } +} diff --git a/src/AzureIoTHub.Portal.Tests.E2E/TagsConfiguration.cs b/src/AzureIoTHub.Portal.Tests.E2E/TagsConfiguration.cs new file mode 100644 index 000000000..c2abd48c5 --- /dev/null +++ b/src/AzureIoTHub.Portal.Tests.E2E/TagsConfiguration.cs @@ -0,0 +1,55 @@ +// Copyright (c) CGI France. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace AzureIoTHub.Portal.Tests.E2E +{ + using AutoFixture; + using AzureIoTHub.Portal.Tests.E2E.Pages; + using NUnit.Framework; + using NUnit.Framework.Internal; + + public class DeviceTags : E2ETest + { + private LoginPage loginPage; + + [SetUp] + public void SetUp() + { + loginPage = new LoginPage(Configuration); + + loginPage.Login(); + } + + [TearDown] + public override void TearDown() + { + loginPage.Logout(); + + base.TearDown(); + } + + [Test] + public void UserCanAddAndRemoveTagsConfiguration() + { + var fixture = new Fixture(); + + var tagName = new string( + fixture.CreateMany(4) + .Where(c => char.IsLetterOrDigit(c)) + .ToArray() + ); + + var tagLabel = new string( + fixture.CreateMany(4) + .Where(c => char.IsLetterOrDigit(c)) + .ToArray() + ); + + var tag = new TagsConfigurationPage(); + + tag.AddTag(tagName, tagLabel); + + tag.RemoveTag(tagName); + } + } +}