V4.4 Selenium fix
This commit is contained in:
25
AiQ_GUI.cs
25
AiQ_GUI.cs
@@ -1575,7 +1575,7 @@ namespace AiQ_GUI
|
|||||||
CancellationTokenSource cts = new();
|
CancellationTokenSource cts = new();
|
||||||
soakCtsList.Add(cts);
|
soakCtsList.Add(cts);
|
||||||
soakTasks.Add(SoakTest.StartSoak(SCL, cts.Token));
|
soakTasks.Add(SoakTest.StartSoak(SCL, cts.Token));
|
||||||
await Task.Delay(5000);
|
await Task.Delay(10000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1586,28 +1586,23 @@ namespace AiQ_GUI
|
|||||||
cts.Cancel();
|
cts.Cancel();
|
||||||
soakCtsList.Clear();
|
soakCtsList.Clear();
|
||||||
soakTasks.Clear();
|
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
|
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 CameraModules.FactoryResetModules(SCL.IP); // Reset camera modules
|
||||||
|
await FlexiAPI.HTTP_Update("GLOBAL--FlexiApplication", SCL.IP, GOD_JSON);
|
||||||
string[,] godJson = { { "propGodMode", "false" } }; // Set God mode explicitly off
|
await FlexiAPI.HTTP_Update("GLOBAL--NetworkConfig", SCL.IP, Network_JSON);
|
||||||
string GOD = await FlexiAPI.HTTP_Update("GLOBAL--FlexiApplication", SCL.IP, godJson);
|
AddToActionsList($"Setting 211 & God Mode off for camera {SCL.IP}", false);
|
||||||
if (GOD.Contains("Error"))
|
|
||||||
throw new Exception("Could not set God mode off");
|
|
||||||
|
|
||||||
bool Pass = await FlexiAPI.ChangeNetwork211(SCL.IP); // set camera to 211
|
|
||||||
if (!Pass)
|
|
||||||
throw new Exception("Could not set camera to 211");
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,10 +30,20 @@
|
|||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
<Optimize>True</Optimize>
|
<Optimize>True</Optimize>
|
||||||
|
<DefineConstants>$(DefineConstants);_PUBLISH_CHROMEDRIVER</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
|
||||||
<Optimize>True</Optimize>
|
<Optimize>True</Optimize>
|
||||||
|
<DefineConstants>$(DefineConstants);_PUBLISH_CHROMEDRIVER</DefineConstants>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||||
|
<DefineConstants>$(DefineConstants);_PUBLISH_CHROMEDRIVER</DefineConstants>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
|
||||||
|
<DefineConstants>$(DefineConstants);_PUBLISH_CHROMEDRIVER</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -51,7 +61,7 @@
|
|||||||
<PackageReference Include="PDFsharp-MigraDoc-gdi" Version="6.2.2" />
|
<PackageReference Include="PDFsharp-MigraDoc-gdi" Version="6.2.2" />
|
||||||
<PackageReference Include="Selenium.Support" Version="4.38.0" />
|
<PackageReference Include="Selenium.Support" Version="4.38.0" />
|
||||||
<PackageReference Include="Selenium.WebDriver" Version="4.38.0" />
|
<PackageReference Include="Selenium.WebDriver" Version="4.38.0" />
|
||||||
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="142.0.7444.5900" />
|
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="142.0.7444.6100" />
|
||||||
<PackageReference Include="SSH.NET" Version="2025.1.0" />
|
<PackageReference Include="SSH.NET" Version="2025.1.0" />
|
||||||
<PackageReference Include="System.Data.OleDb" Version="9.0.10" />
|
<PackageReference Include="System.Data.OleDb" Version="9.0.10" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -394,7 +394,7 @@ namespace AiQ_GUI
|
|||||||
//Filename validation
|
//Filename validation
|
||||||
string filename = Path.GetFileName(fileToUpload).ToUpper();
|
string filename = Path.GetFileName(fileToUpload).ToUpper();
|
||||||
|
|
||||||
if ((isIR && filename.Contains("IR")) || (!isIR && filename.Contains("OV")))
|
if ((!isIR && filename.Contains("IR")) || (isIR && filename.Contains("OV")))
|
||||||
{
|
{
|
||||||
MainForm.Instance.AddToActionsList($"Incorrect file selected. Expected {(isIR ? "IR" : "OV")} file", false);
|
MainForm.Instance.AddToActionsList($"Incorrect file selected. Expected {(isIR ? "IR" : "OV")} file", false);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -39,6 +39,47 @@ namespace AiQ_GUI
|
|||||||
return elementID;
|
return elementID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SwitchUser(ChromeDriver driver)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
WebDriverWait wait = new(driver, TimeSpan.FromSeconds(10));
|
||||||
|
|
||||||
|
// Click "Switch User"
|
||||||
|
IWebElement switchBtn = wait.Until(d =>
|
||||||
|
d.FindElement(By.XPath("//*[contains(text(),'Switch User')]"))
|
||||||
|
);
|
||||||
|
switchBtn.Click();
|
||||||
|
|
||||||
|
// Username
|
||||||
|
IWebElement userBox = wait.Until(d => d.FindElement(By.Id("username")));
|
||||||
|
userBox.Clear();
|
||||||
|
userBox.SendKeys("admin");
|
||||||
|
|
||||||
|
// Password
|
||||||
|
IWebElement passBox = wait.Until(d => d.FindElement(By.Id("password")));
|
||||||
|
passBox.Clear();
|
||||||
|
passBox.SendKeys("admin");
|
||||||
|
|
||||||
|
// Login button
|
||||||
|
IWebElement loginBtn = wait.Until(d =>
|
||||||
|
d.FindElement(By.XPath("//button[contains(normalize-space(text()), 'Login')]"))
|
||||||
|
);
|
||||||
|
|
||||||
|
// Wait until it's clickable manually (no SeleniumExtras)
|
||||||
|
wait.Until(d => loginBtn.Displayed && loginBtn.Enabled);
|
||||||
|
|
||||||
|
loginBtn.Click();
|
||||||
|
|
||||||
|
MainForm.Instance.AddToActionsList("Switched user and logged in.");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MainForm.Instance.AddToActionsList("SwitchUser failed: " + ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Attempts to click the web element with the specified ID; refreshes the page and retries once if the initial attempt fails
|
// 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)
|
public static void ClickElementByID(string elementID, ChromeDriver driver, bool tryagain = true)
|
||||||
{
|
{
|
||||||
@@ -65,17 +106,40 @@ namespace AiQ_GUI
|
|||||||
// Initialises and opens a ChromeDriver with specific options
|
// Initialises and opens a ChromeDriver with specific options
|
||||||
public static ChromeDriver OpenDriver()
|
public static ChromeDriver OpenDriver()
|
||||||
{
|
{
|
||||||
ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService();
|
string tempProfile = null;
|
||||||
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);
|
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);
|
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5);
|
||||||
|
|
||||||
return driver;
|
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
|
// 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)
|
public static async Task Dropdown_Change(string fullId, string value, ChromeDriver driver, string SoakLogFile, string CamAct)
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ namespace AiQ_GUI
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
driver = Selenium.OpenDriver();
|
driver = Selenium.OpenDriver();
|
||||||
|
|
||||||
// Keep retrying until connected or cancelled
|
// Keep retrying until connected or cancelled
|
||||||
bool connected = false;
|
bool connected = false;
|
||||||
while (!connected && !token.IsCancellationRequested)
|
while (!connected && !token.IsCancellationRequested)
|
||||||
@@ -27,6 +26,7 @@ namespace AiQ_GUI
|
|||||||
{
|
{
|
||||||
// Attempt initial connection and navigation to setup tab
|
// Attempt initial connection and navigation to setup tab
|
||||||
Selenium.GoToUrl($"http://{CamInfo.IP}", driver);
|
Selenium.GoToUrl($"http://{CamInfo.IP}", driver);
|
||||||
|
Selenium.SwitchUser(driver);
|
||||||
Selenium.ClickElementByID("tabSetup", driver);
|
Selenium.ClickElementByID("tabSetup", driver);
|
||||||
connected = true;
|
connected = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user