diff --git a/src/AzureIoTHub.Portal.Tests.E2E/EdgeModels.cs b/src/AzureIoTHub.Portal.Tests.E2E/EdgeModels.cs new file mode 100644 index 000000000..5e73b659a --- /dev/null +++ b/src/AzureIoTHub.Portal.Tests.E2E/EdgeModels.cs @@ -0,0 +1,43 @@ +// 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 EdgeModels : 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 UserCanAddAndRemoveEdgeModel() + { + var modelName = Fixture.Create(); + + var model = new EdgeModelPage(); + + model.AddEdgeModel(modelName, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vel fringilla est ullamcorper eget nulla. Vel turpis nunc eget lorem dolor sed viverra ipsum nunc. Eget dolor morbi non arcu. Urna duis convallis convallis tellus id interdum velit laoreet id. "); + + model.RemoveEdgeModel(modelName); + } + } +} diff --git a/src/AzureIoTHub.Portal.Tests.E2E/Pages/ConcentratorsPage.cs b/src/AzureIoTHub.Portal.Tests.E2E/Pages/ConcentratorsPage.cs new file mode 100644 index 000000000..4ec7f876f --- /dev/null +++ b/src/AzureIoTHub.Portal.Tests.E2E/Pages/ConcentratorsPage.cs @@ -0,0 +1,91 @@ +// 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 ConcentratorsPage + { + private readonly WebDriverWait wait; + + public ConcentratorsPage() + { + this.wait = new WebDriverWait(WebDriverFactory.Default, TimeSpan.FromSeconds(5)); + + _ = wait.Until(d => d.FindElement(By.XPath("/html/body/div[2]/div[3]/aside/div/div/div[4]/div/div/div/div/div")).Displayed); + WebDriverFactory.Default.FindElement(By.XPath("/html/body/div[2]/div[3]/aside/div/div/div[4]/div/div/div/div/div")).Click(); + } + + public void AddConcentrator(string id, string name) + { + _ = wait.Until(d => d.FindElement(By.Id("add-concentrator")).Displayed); + + WebDriverFactory.Default.FindElement(By.Id("add-concentrator")).Click(); + + _ = wait.Until(d => d.FindElement(By.Id("DeviceId")).Displayed); + + WebDriverFactory.Default.FindElement(By.Id("DeviceId")).Click(); + WebDriverFactory.Default.FindElement(By.Id("DeviceId")).SendKeys(id); + + WebDriverFactory.Default.FindElement(By.Id("DeviceName")).Click(); + WebDriverFactory.Default.FindElement(By.Id("DeviceName")).SendKeys(name); + + WebDriverFactory.Default.FindElement(By.Id("LoraRegion")).Click(); + + _ = wait.Until(d => d.FindElement(By.CssSelector(".mud-list.mud-list-padding li:first-child")).Displayed); + WebDriverFactory.Default.FindElement(By.CssSelector(".mud-list.mud-list-padding li:first-child")).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("Device" + id + " has been successfully created! Please note that changes might take some minutes to be visible in the list...")); + + 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 SearchConcentrator(string id) + { + _ = wait.Until(d => d.FindElement(By.XPath("/html/body/div[2]/div[3]/aside/div/div/div[4]/div/div/div/div/div")).Displayed); + + WebDriverFactory.Default.FindElement(By.XPath("/html/body/div[2]/div[3]/aside/div/div/div[4]/div/div/div/div/div")).Click(); + + _ = wait.Until(d => d.FindElement(By.ClassName("mud-expand-panel")).Displayed); + + WebDriverFactory.Default.FindElement(By.ClassName("mud-expand-panel-header")).Click(); + + _ = wait.Until(d => d.FindElement(By.Id("searchKeyword")).Displayed); + + WebDriverFactory.Default.FindElement(By.Id("searchKeyword")).Click(); + WebDriverFactory.Default.FindElement(By.Id("searchKeyword")).SendKeys(id); + + WebDriverFactory.Default.FindElement(By.Id("searchButton")).Click(); + } + + public void RemoveConcentrator(string id) + { + SearchConcentrator(id); + + _ = wait.Until(d => d.FindElement(By.ClassName("mud-tooltip-root mud-tooltip-inline")).Displayed); + WebDriverFactory.Default.FindElement(By.ClassName("mud-tooltip-root mud-tooltip-inline")).Click(); + + _ = wait.Until(d => d.FindElement(By.ClassName("outline-none")).Displayed); + + WebDriverFactory.Default.FindElement(By.CssSelector(".mud-button-text-primary > .mud-button-label")).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("Device " + id + " A has been successfully deleted!")); + + + 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); + } + } +} diff --git a/src/AzureIoTHub.Portal.Tests.E2E/Pages/EdgeDevicePage.cs b/src/AzureIoTHub.Portal.Tests.E2E/Pages/EdgeDevicePage.cs new file mode 100644 index 000000000..f47eb239f --- /dev/null +++ b/src/AzureIoTHub.Portal.Tests.E2E/Pages/EdgeDevicePage.cs @@ -0,0 +1,112 @@ +// 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.Interactions; + using OpenQA.Selenium.Support.UI; + + public class EdgeDevicePage + { + + private readonly WebDriverWait wait; + + public EdgeDevicePage() + { + this.wait = new WebDriverWait(WebDriverFactory.Default, TimeSpan.FromSeconds(5)); + + _ = wait.Until(d => d.FindElement(By.XPath("/ html / body / div[2] / div[3] / aside / div / div / div[3] / div / div / div / div / div[1] / a")).Displayed); + + WebDriverFactory.Default.FindElement(By.XPath("/ html / body / div[2] / div[3] / aside / div / div / div[3] / div / div / div / div / div[1] / a")).Click(); + } + + + + + public void AddEdgeDevice(string id, string name, string model) + { + _ = wait.Until(d => d.FindElement(By.XPath("/html/body/div[2]/div[3]/div/div/div/div[2]/div/div[1]/div[3]/button")).Displayed); + + WebDriverFactory.Default.FindElement(By.XPath("/html/body/div[2]/div[3]/div/div/div/div[2]/div/div[1]/div[3]/button")).Click(); + _ = wait.Until(d => d.FindElement(By.Id("ModelId")).Displayed); + + WebDriverFactory.Default.FindElement(By.Id("ModelId")).Click(); + + System.Threading.Thread.Sleep(2000); + + WebDriverFactory.Default.FindElement(By.Id("ModelId")).SendKeys(model + Keys.Enter); + + System.Threading.Thread.Sleep(2000); + + // driver.FindElement(By.Id("ModelId")).SendKeys(Keys.Enter); + + WebDriverFactory.Default.FindElement(By.Id("DeviceId")).Click(); + WebDriverFactory.Default.FindElement(By.Id("DeviceId")).SendKeys(id); + WebDriverFactory.Default.FindElement(By.Id("DeviceName")).Click(); + WebDriverFactory.Default.FindElement(By.Id("DeviceName")).SendKeys(name); + + + System.Threading.Thread.Sleep(2000); + + + // Find the "Save" button + var saveButton = WebDriverFactory.Default.FindElement(By.XPath("//span[@class='mud-button-label' and text()='Save']")); + + // Scroll to the "Save" button + //((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", saveButton); + + // Click the element + saveButton.Click(); + + System.Threading.Thread.Sleep(5000); + + _ = 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("Device " + id + " has been successfully created!")); + + 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 SearchEdgeDevice(string name) + { + _ = wait.Until(d => d.FindElement(By.ClassName("mud-expand-panel-header")).Displayed); + + WebDriverFactory.Default.FindElement(By.ClassName("mud-expand-panel-header")).Click(); + + _ = wait.Until(d => d.FindElement(By.CssSelector(".mud-input-input-control .mud-input-slot:nth-child(1)")).Displayed); + + WebDriverFactory.Default.FindElement(By.CssSelector(".mud-input-input-control .mud-input-slot:nth-child(1)")).Click(); + WebDriverFactory.Default.FindElement(By.CssSelector(".mud-input-input-control .mud-input-slot:nth-child(1)")).SendKeys(name); + + + WebDriverFactory.Default.FindElement(By.Id("searchFilterButton")).Click(); + + } + + public void RemoveEdgeDevice(string id) + { + SearchEdgeDevice(id); + + _ = wait.Until(d => d.FindElement(By.CssSelector("#delete_789456 path:nth-child(2)")).Displayed); + WebDriverFactory.Default.FindElement(By.CssSelector("#delete_789456 path:nth-child(2)")).Click(); + + _ = wait.Until(d => d.FindElement(By.ClassName("outline-none")).Displayed); + + WebDriverFactory.Default.FindElement(By.CssSelector(".mud-button-text-primary > .mud-button-label")).Click(); + System.Threading.Thread.Sleep(5000); + + + _ = 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("Device " + id + " has been successfully deleted!")); + + 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); + } + } +} diff --git a/src/AzureIoTHub.Portal.Tests.E2E/Pages/EdgeModelPage.cs b/src/AzureIoTHub.Portal.Tests.E2E/Pages/EdgeModelPage.cs new file mode 100644 index 000000000..8e1caec52 --- /dev/null +++ b/src/AzureIoTHub.Portal.Tests.E2E/Pages/EdgeModelPage.cs @@ -0,0 +1,94 @@ +// 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 EdgeModelPage + { + private readonly WebDriverWait wait; + + public EdgeModelPage() + { + this.wait = new WebDriverWait(WebDriverFactory.Default, TimeSpan.FromSeconds(5)); + + _ = wait.Until(d => d.FindElement(By.CssSelector(".mud-navmenu > .mud-nav-item:nth-child(2) .mud-nav-link-text")).Displayed); + + WebDriverFactory.Default.FindElement(By.CssSelector(".mud-navmenu > .mud-nav-item:nth-child(2) .mud-nav-link-text")).Click(); + } + + public void NavigateToEdgeModelPage() + { + _ = wait.Until(d => d.FindElement(By.CssSelector(".mud-navmenu > .mud-nav-item:nth-child(2) .mud-nav-link-text")).Displayed); + + + WebDriverFactory.Default.FindElement(By.CssSelector(".mud-navmenu > .mud-nav-item:nth-child(2) .mud-nav-link-text")).Click(); + } + + + public void AddEdgeModel(string name, string description) + { + _ = wait.Until(d => d.FindElement(By.Id("addEdgeModelButton")).Displayed); + + WebDriverFactory.Default.FindElement(By.Id("addEdgeModelButton")).Click(); + + _ = wait.Until(d => d.FindElement(By.Id("Name")).Displayed); + + WebDriverFactory.Default.FindElement(By.Id("Name")).Click(); + WebDriverFactory.Default.FindElement(By.Id("Name")).SendKeys(name); + WebDriverFactory.Default.FindElement(By.Id("Description")).Click(); + WebDriverFactory.Default.FindElement(By.Id("Description")).SendKeys(description); + WebDriverFactory.Default.FindElement(By.Id("SaveButton")).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("Device model successfully created.")); + + 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 SearchEdgeModel(string description) + { + WebDriverFactory.Default.FindElement(By.ClassName("mud-expand-panel-text")).Click(); + + _ = wait.Until(d => d.FindElement(By.Id("edge-model-search-keyword")).Displayed); + + + WebDriverFactory.Default.FindElement(By.Id("edge-model-search-keyword")).SendKeys(description); + + _ = wait.Until(d => d.FindElement(By.Id("edge-model-search-button")).Displayed); + WebDriverFactory.Default.FindElement(By.Id("edge-model-search-button")).Click(); + } + + + + + public void RemoveEdgeModel(string name) + { + SearchEdgeModel(name); + + WebDriverFactory.Default.FindElement(By.Id("deleteButton")).Click(); + + _ = wait.Until(d => d.FindElement(By.ClassName("outline-none")).Displayed); + + WebDriverFactory.Default.FindElement(By.CssSelector(".mud-button-text-primary > .mud-button-label")).Click(); + System.Threading.Thread.Sleep(5000); + + + _ = 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("Device model " + name + " has been successfully deleted!")); + + 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); + } + + + } +}