public void Run() { List <Structs.TestStepResult> testResult = new List <Structs.TestStepResult>(); Structs.TestStepResult currentResult; operations = new Operations(testStuff); foreach (Structs.TestStep testStep in testPlan.testSteps) { currentResult = new Structs.TestStepResult(testStep.stepDescription, DateTime.Now, operations.Operation(testStep)); testResult.Add(currentResult); testStuff.testResult = new Structs.TestResult(testResult).DeepClone(); OnStepFinished(); if (currentResult.result != "ok") { testStuff.Log("QATest.Run(): stopping the test. Wrong result: " + currentResult.result + " in test step " + testStep.stepDescription + "."); testStuff.testResult = new Structs.TestResult(testResult).DeepClone(); OnRunFinished(); return; } } testStuff.testResult = new Structs.TestResult(testResult).DeepClone(); OnRunFinished(); return; }
public string OpActionClick(Structs.TestStep testStep1) { if (testStep1.operationText.Contains("Retarded")) { Sleep(Settings.ActionsSettings.opActionClickRetarded); } BrowserFocus(); //dodane ze względu na problemy - czasem nie klika i nie zgłasza błędu testStuff.Log("OpActions.OpActionClick() called in test step " + testStep1.stepDescription); //IWebElement element = testStuff.driver.FindElement(By.XPath(testStep1.xpath)); IWebElement element = ElementFinder(testStep1); ScrollAndMoveTo(element, testStuff.driver); element.Click(); //sprawdzenie wystąpienia błędu zdefiniowanego przez uzytkownika (jako fragment html) if ((Settings.customErrors.Count > 0) && (testStep1.operationText.Contains("Err"))) { Sleep(Settings.sleepAfterOperation); string customError = CustomErrorDetected(); if (customError != "no") { return("Custom error detected: " + customError); } else { return("ok"); } } else { return("ok"); } }
//private Structs.TestPlan testPlan; public QATestLauncher(IQATestLaunchPoint launchPoint1) { launchPoint = launchPoint1; //np. Form1 testStuff = launchPoint1.GetTestStuff(); testPlanAsDataTable = launchPoint1.GetTestPlanAsDataTable(); if (TestPlanFromDataTable.IsValid(testPlanAsDataTable)) { testStuff.testPlan = TestPlanFromDataTable.GetTestPlan(testPlanAsDataTable); qATest = new QATest(testStuff); qATest.RunFinishedEvent += OnRunFinished; qATest.StepFinishedEvent += OnStepFinished; } else { testStuff.Log("This source doesn't contain a valid test plan or read failed. Test cancelled."); } }
int catchLimit = Settings.catchLimit; //do settingsów public string Operation(Structs.TestStep testStep1) { string result = "init"; try { opActions.KeepMaximized(testStep1); //wielkość okna chrome, ważne dla niezawodności opetarions result = PerformOperation(testStep1); opActions.Sleep(Settings.sleepAfterOperation); catchCount = 0; } catch (NoAlertPresentException) { catchCount++; testStuff.Log("Exception caught \"NoAlertPresentException\" in step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next: sleep, retry."); opActions.Sleep(200); if (catchCount < catchLimit) { result = Operation(testStep1); } else { //result = "Catch limit exceeded: \"UnhandledAlertException\" in step " + testStep1.stepDescription + "."; result = "ok"; //dziwne, ale chodzi o to, że kiedy leci taki wyjątek, to praktycznie zawsze przy próbie pozbycia się jebanego alertu; więc tu zakładany, że jebańca nie ma } } catch (UnhandledAlertException) { catchCount++; testStuff.Log("Exception caught \"UnhandledAlertException\" in step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next: close alert, retry."); opActions.OpActionCloseAlert("Accept"); if (catchCount < catchLimit) { result = Operation(testStep1); } else { result = "Catch limit exceeded: \"UnhandledAlertException\" in step " + testStep1.stepDescription + "."; } } catch (StaleElementReferenceException) { catchCount++; testStuff.Log("Exception caught \"StaleElementReferenceException\" in step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next: retry."); if (catchCount < catchLimit) { result = Operation(testStep1); } else { result = "Catch limit exceeded: \"StaleElementReferenceException\" in step " + testStep1.stepDescription + "."; } } catch (ElementNotInteractableException) { catchCount++; testStuff.Log("Exception caught \"ElementNotInteractableException\" in step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next: sleep, retry."); opActions.Sleep(Settings.sleepAfterElementNotInteractible); if (catchCount < catchLimit) { if (Settings.allowTryHelps) { opActions.TryHelpNonInteractible(testStep1, catchCount); //znajduje interaktywnego rodzica i najeżdża na niego kursorem } result = Operation(testStep1); } else { result = "Catch limit exceeded. \"ElementNotInteractableException\" in step " + testStep1.stepDescription + "."; } } //niby redundantne z implicit wait, ale w praktyce pomaga catch (NoSuchElementException e) { catchCount += 1; testStuff.Log("Exception caught \"NoSuchElementException\" in test step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next actions: sleep, retry."); opActions.Sleep(Settings.sleepAfterNoSuchElement); //do tego dochodzi implicit wait, więc łącznie 40,3 s x 10... wtf if (catchCount < Settings.noSuchElementCatchLimit) { if (Settings.allowTryHelps) { opActions.TryHelpNoSuchElement(catchCount); //scrolluje } result = Operation(testStep1); } else { result = "Catch limit exceeded. \"NoSuchElementException\" in test step " + testStep1.stepDescription + ". Is test scenario up-to-date? Exception: \r\n" + e; } } catch (Exception e) { result = "Error in step named: \"" + testStep1.stepDescription + "\". Operation: \"" + testStep1.operationName + "\". Exception: \r\n" + e; } return(result); }