Stuck
unknown
csharp
3 years ago
2.9 kB
2
Indexable
Never
private void stuckButton_click(object sender, EventArgs e) { int num_iteration = 5; int curr_tentative = 0; int i = 0; for(; i<num_iteration && curr_tentative<10;++curr_tentative) { if (SolveStuck()) ++i; } if (i == num_iteration) { Console.WriteLine("Stuck effettuato"); } else { Console.WriteLine("Effettuato il processo rimozione stuck per piu di 10 volte, ricomincia da capo"); } } private Boolean SolveStuck() { try { //Do per assodato c'è già un tab con la web app aperta int num_tab = 5; for(int i=0; i<num_tab; ++i) { ((IJavaScriptExecutor)webDriver.driver).ExecuteScript("window.open();"); webDriver.driver.SwitchTo().Window(webDriver.driver.WindowHandles.Last()); if (webDriver.driver.PageSource.Contains(WebElements.PageHome)) return false; if (ChromeIsOpen() && !webDriver.driver.PageSource.Contains(WebElements.PageHome)) { //WEBAPP URL if (!webDriver.driver.Url.Contains(WebElements.URL) && !webDriver.driver.Url.Contains(WebElements.LoginURL)) webDriver.driver.Navigate().GoToUrl(WebElements.URL); WebDriverWait wait = new WebDriverWait(webDriver.driver, TimeSpan.FromSeconds(10)); try { wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//img[@class='loaderIcon']"))); continue; } catch (Exception ex) { Console.WriteLine("loader doesn't found"); return false; } } } webDriver.driver.SwitchTo().Window(webDriver.driver.WindowHandles[0]); while (webDriver.driver.WindowHandles.Count > 1) { webDriver.driver.Close(); webDriver.driver.SwitchTo().Window(webDriver.driver.WindowHandles[0]); } while ( ChromeIsOpen() && !webDriver.driver.PageSource.Contains(WebElements.PageHome)) { Thread.Sleep(500); } return true; } catch (Exception ex) { return false; } }