public virtual void Test(System.Action steps, int lineNumber) { bool noExceptionOccured = true; try { TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("SpecFlowScenarioOutline", null); testRunner.OnScenarioInitialize(scenarioInfo); this.ScenarioStart(); NUnit.Framework.Internal.TestExecutionContext.IsolatedContext testExecutionContext = new NUnit.Framework.Internal.TestExecutionContext.IsolatedContext(); try { steps(); } finally { testExecutionContext.Dispose(); } this.ScenarioCleanup(); } catch (System.Exception) { noExceptionOccured = false; } if (noExceptionOccured) { throw new System.Exception(string.Format("Line {0} is suspicious.", lineNumber)); } }
public void RetryOnNUnitException(Action action) { Policy .Handle <AssertionException>() .WaitAndRetry(TimeOut, (exception, timeSpan, retryCount, context) => { TestContext.Progress.WriteLine($"Retry Count : {retryCount}, Exception : {exception.Message}"); }) .Execute(() => { using (var testcontext = new NUnit.Framework.Internal.TestExecutionContext.IsolatedContext()) { action.Invoke(); } }); }
internal bool RetryOnException(Func <bool> func, Action beforeAction = null) { return(Policy .Handle <Exception>((x) => x.Message.Contains("verification failed")) .WaitAndRetry(TimeOut, (exception, timeSpan, retryCount, context) => { TestContext.Progress.WriteLine($"Retry Count : {retryCount}, Exception : {exception.Message}"); }) .Execute(() => { using (var testcontext = new NUnit.Framework.Internal.TestExecutionContext.IsolatedContext()) { beforeAction?.Invoke(); return func(); } })); }
internal void RetryOnElementClickInterceptedException(IWebElement element) { Action beforeAction = null, afterAction = null; Policy .Handle <ElementClickInterceptedException>() .Or <WebDriverException>() .WaitAndRetry(TimeOut, (exception, timeSpan, retryCount, context) => { TestContext.Progress.WriteLine($"Retry Count : {retryCount}, Exception : {exception.Message}"); switch (true) { case bool _ when retryCount == 1: var x = ResizeWindow(); beforeAction = x.beforeAction; afterAction = x.afterAction; break; case bool _ when retryCount >= 2: var y = ScrollIntoView(element); beforeAction = y.beforeAction; afterAction = y.afterAction; break; } }) .Execute(() => { using (var testcontext = new NUnit.Framework.Internal.TestExecutionContext.IsolatedContext()) { beforeAction?.Invoke(); ClickEvent(element).Invoke(); afterAction?.Invoke(); } }); }