public void Run() { List <Structs.TestStepResult> testResult = new List <Structs.TestStepResult>(); Structs.TestStepResult currentResult; operations = new Operations(testSetup); foreach (Structs.TestStep testStep in testPlan.testSteps) { currentResult = new Structs.TestStepResult(testStep.stepDescription, DateTime.Now, operations.Operation(testStep)); testResult.Add(currentResult); testSetup.testResult = new Structs.TestResult(testResult).DeepClone(); OnStepFinished(); if (currentResult.result != "ok") { testSetup.Log("QATest.Run(): stopping the test. Wrong result: " + currentResult.result + " in test step " + testStep.stepDescription + "."); testSetup.testResult = new Structs.TestResult(testResult).DeepClone(); OnRunFinished(); return; } } testSetup.testResult = new Structs.TestResult(testResult).DeepClone(); OnRunFinished(); return; }
public void OpActionCloseAlert(string operationText) { try { switch (operationText) { case "Accept": testSetup.driver.SwitchTo().Alert().Accept(); break; case "Dismiss": testSetup.driver.SwitchTo().Alert().Dismiss(); break; } } catch (NoAlertPresentException) { testSetup.Log("CloseAlert(): exception caught \"NoAlertPresentException\"."); } }
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++; testSetup.Log("Exception caught \"NoAlertPresentException\" in test step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next actions: none."); } catch (UnhandledAlertException) { catchCount++; testSetup.Log("Exception caught \"UnhandledAlertException\" in test step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next actions: close alert, retry."); opActions.OpActionCloseAlert("Accept"); if (catchCount < catchLimit) { result = Operation(testStep1); } else { result = "Catch limit exceeded: \"UnhandledAlertException\" in test step " + testStep1.stepDescription + "."; } } catch (StaleElementReferenceException) { catchCount++; testSetup.Log("Exception caught \"StaleElementReferenceException\" in test step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next action: retry."); if (catchCount < catchLimit) { result = Operation(testStep1); } else { result = "Catch limit exceeded: \"StaleElementReferenceException\" in test step " + testStep1.stepDescription + "."; } } catch (ElementNotInteractableException) { catchCount++; testSetup.Log("Exception caught \"ElementNotInteractableException\" in test step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next actions: sleep, retry."); opActions.Sleep(Settings.sleepAfterElementNotInteractible); if (catchCount < catchLimit) { result = Operation(testStep1); } else { result = "Catch limit exceeded. \"ElementNotInteractableException\" in test step " + testStep1.stepDescription + "."; } } //niby redundantne z implicit wait, ale w praktyce pomaga catch (NoSuchElementException e) { catchCount += 9; //ze względu na implicit wait (jakoś to ogarnąć potem) testSetup.Log("Exception caught \"NoSuchElementException\" in test step " + testStep1.stepDescription + ". Catch number " + catchCount.ToString() + ". Next actions: sleep, retry."); //bez refresh! opActions.Sleep(Settings.sleepAfterNoSuchElement); //do tego dochodzi implicit wait, więc łącznie 40,3 s x 10... wtf if (catchCount < catchLimit) { result = Operation(testStep1); } else { result = "Catch limit exceeded. \"NoSuchElementException\" in test step " + testStep1.stepDescription + ". Exception: \r\n" + e; } } catch (Exception e) { result = "Error in step named: \"" + testStep1.stepDescription + "\". Operation: \"" + testStep1.operationName + "\". Exception: \r\n" + e; } return(result); }