diff --git a/AiQ_GUI.cs b/AiQ_GUI.cs index 6f10471..a6c289d 100644 --- a/AiQ_GUI.cs +++ b/AiQ_GUI.cs @@ -1575,7 +1575,7 @@ namespace AiQ_GUI CancellationTokenSource cts = new(); soakCtsList.Add(cts); soakTasks.Add(SoakTest.StartSoak(SCL, cts.Token)); - await Task.Delay(5000); + await Task.Delay(10000); } } else @@ -1588,15 +1588,19 @@ namespace AiQ_GUI soakTasks.Clear(); int i = soakCameraList.Count + 1; // Add 1 for 211 itself staying in the list - foreach (Camera SCL in soakCameraList) // Reset all cameras that were being soaked to default module settings + string[,] Network_JSON = { { "propDHCP", "false" }, { "propHost", "192.168.1.211" }, { "propNetmask", "255.255.255.0" }, { "propGateway", "192.168.1.1" } }; + string[,] GOD_JSON = { { "propGodMode", "false" } }; + foreach (Camera SCL in soakCameraList.Where(c => c.IsChecked)) // only checked cameras { if (!SCL.IsChecked) continue; - try { - Network.Initialize("developer", SCL.DevPass); // Ensure network is initialized to the right camera, cannot be done in soak test finally becuase of this. + Network.Initialize("developer", SCL.DevPass); // Ensure network is initialized to the right camera await CameraModules.FactoryResetModules(SCL.IP); // Reset camera modules + await FlexiAPI.HTTP_Update("GLOBAL--FlexiApplication", SCL.IP, GOD_JSON); + await FlexiAPI.HTTP_Update("GLOBAL--NetworkConfig", SCL.IP, Network_JSON); + AddToActionsList($"Setting 211 & God Mode off for camera {SCL.IP}", false); string[,] godJson = { { "propGodMode", "false" } }; // Set God mode explicitly off string GOD = await FlexiAPI.HTTP_Update("GLOBAL--FlexiApplication", SCL.IP, godJson); @@ -1610,7 +1614,7 @@ namespace AiQ_GUI } catch (Exception ex) { - AddToActionsList("Failed to set God mode, reset camera modules or 211 for camera " + SCL.IP + ". Reason: " + ex.Message); + AddToActionsList("Failed to set all cameras to 211 and god mode off. Reason: " + ex.Message); // In case non AiQ's get caught up } } diff --git a/AiQ_GUI_NET_Test.csproj b/AiQ_GUI_NET_Test.csproj index 212d873..42a72f2 100644 --- a/AiQ_GUI_NET_Test.csproj +++ b/AiQ_GUI_NET_Test.csproj @@ -30,10 +30,20 @@ True + $(DefineConstants);_PUBLISH_CHROMEDRIVER True + $(DefineConstants);_PUBLISH_CHROMEDRIVER + + + + $(DefineConstants);_PUBLISH_CHROMEDRIVER + + + + $(DefineConstants);_PUBLISH_CHROMEDRIVER @@ -51,7 +61,7 @@ - + diff --git a/Soak/Selenium.cs b/Soak/Selenium.cs index 17fb6e0..8fdb859 100644 --- a/Soak/Selenium.cs +++ b/Soak/Selenium.cs @@ -39,54 +39,6 @@ namespace AiQ_GUI return elementID; } - // Attempts to click the web element with the specified ID; refreshes the page and retries once if the initial attempt fails - public static void ClickElementByID(string elementID, ChromeDriver driver, bool tryagain = true) - { - try - { - WebDriverWait wait = new(driver, TimeSpan.FromSeconds(10)); - IWebElement element = wait.Until(driver => driver.FindElement(By.Id(elementID))); - element.Click(); - } - catch - { - if (tryagain) - { - driver.Navigate().Refresh(); - WebDriverWait wait = new(driver, TimeSpan.FromSeconds(10)); - wait.Until(d => ((IJavaScriptExecutor)d).ExecuteScript("return document.readyState").Equals("complete")); - ClickElementByID(elementID, driver, false); - } - - MainForm.Instance.AddToActionsList("Could not click " + elementID); - } - } - - // Initialises and opens a ChromeDriver with specific options - public static ChromeDriver OpenDriver() - { - try - { - ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService(); - chromeDriverService.HideCommandPromptWindow = true; - ChromeOptions options = new(); - options.AddArguments("--app=data:,", "--window-size=960,1040", "--window-position=0,0"); - options.AddExcludedArgument("enable-automation"); - options.AddAdditionalChromeOption("useAutomationExtension", false); - - ChromeDriver driver = new(chromeDriverService, options); - driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5); - - return driver; - - } - catch (Exception ex) - { - MainForm.Instance.AddToActionsList("Error Creating ChromeDriver " + ex.Message); - throw; - } - } - public static void SwitchUser(ChromeDriver driver) { try @@ -127,6 +79,68 @@ namespace AiQ_GUI } } + + // Attempts to click the web element with the specified ID; refreshes the page and retries once if the initial attempt fails + public static void ClickElementByID(string elementID, ChromeDriver driver, bool tryagain = true) + { + try + { + WebDriverWait wait = new(driver, TimeSpan.FromSeconds(10)); + IWebElement element = wait.Until(driver => driver.FindElement(By.Id(elementID))); + element.Click(); + } + catch + { + if (tryagain) + { + driver.Navigate().Refresh(); + WebDriverWait wait = new(driver, TimeSpan.FromSeconds(10)); + wait.Until(d => ((IJavaScriptExecutor)d).ExecuteScript("return document.readyState").Equals("complete")); + ClickElementByID(elementID, driver, false); + } + + MainForm.Instance.AddToActionsList("Could not click " + elementID); + } + } + + // Initialises and opens a ChromeDriver with specific options + public static ChromeDriver OpenDriver() + { + string tempProfile = null; + + try + { + ChromeOptions options = new(); + options.AddArguments("--app=data:,", + "--window-size=960,1040", + "--window-position=0,0", + "--no-sandbox", + "--incognito", + "--no-first-run", + "--no-default-browser-check", + "--disable-features=BrowserAddPersonFeature,InterestFeedContentSuggestions"); + + // Use a unique temporary profile to avoid conflicts + tempProfile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); + options.AddArguments($"--user-data-dir={tempProfile}"); + + // manual driver path + string driverPath = @"C:\ProgramData\MAV\AiQ_GUI"; + ChromeDriverService service = ChromeDriverService.CreateDefaultService(driverPath); + service.HideCommandPromptWindow = true; + + ChromeDriver driver = new(service, options); + driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5); + + return driver; + } + catch (Exception ex) + { + MainForm.Instance.AddToActionsList("Failed to create ChromeDriver: " + ex.Message); + throw; + } + } + // Changes the value of a dropdown element by ID, logs the action, and verifies the result using flashline feedback public static async Task Dropdown_Change(string fullId, string value, ChromeDriver driver, string SoakLogFile, string CamAct) {