/// <summary> /// Executes test withnout caching exceptions /// </summary> /// <param name="testBody">Test to execute</param> /// <param name="browserFactory"></param> /// <param name="browserName"></param> /// <remarks>The ExpectException is ignored.</remarks> protected virtual void ExecuteTest(Action <BrowserWrapper> testBody, IWebDriverFactory browserFactory, out string browserName) { try { var browser = LatestLiveWebDriver = browserFactory.CreateNewInstance(); var scope = new ScopeOptions() { CurrentWindowHandle = browser.CurrentWindowHandle }; wrapper = new BrowserWrapper(browser, this, scope); browserName = browser.GetType().Name; testBody(wrapper); } finally { DisposeBrowsers(browserFactory); } }
protected virtual void TryExecuteTest(Action <BrowserWrapper> testBody, IWebDriverFactory browserFactory, out string browserName, out Exception exception) { var attemptNumber = 0; var attampsMaximum = SeleniumTestsConfiguration.TestAttempts + (SeleniumTestsConfiguration.FastMode ? 1 : 0); do { attemptNumber++; WriteLine($"Attamp #{attemptNumber} starts...."); exception = null; var browser = LatestLiveWebDriver = browserFactory.CreateNewInstance(); LogDriverId(browser, "Driver creation - TryExecuteTest"); var scope = new ScopeOptions() { CurrentWindowHandle = browser.CurrentWindowHandle }; wrapper = new BrowserWrapper(browser, this, scope); browserName = browser.GetType().Name; WriteLine($"Testing browser '{browserName}' attempt no. {attemptNumber}"); bool exceptionWasThrow = false; try { BeforeSpecificBrowserTestStarts(wrapper); Log("Execution of user test starting.", 10); testBody(wrapper); Log("Execution of user test ended.", 10); AfterSpecificBrowserTestEnds(wrapper); } catch (Exception ex) { exceptionWasThrow = true; bool isExpected = false; if (ExpectedExceptionType != null) { isExpected = ex.GetType() == ExpectedExceptionType || (AllowDerivedExceptionTypes && ExpectedExceptionType.IsInstanceOfType(ex)); } Log("Test is expected to drop: " + isExpected, 10); if (!isExpected) { TakeScreenshot(attemptNumber, wrapper); // fail the test CurrentTestExceptions.Add(exception = ex); Log("Test attemp was not successfull! - TEST ATTAMP FAILED", 10); } if (attemptNumber < attampsMaximum) { RecreateBrowsers(browserFactory); } else { DisposeBrowsers(browserFactory); } } finally { if (!exceptionWasThrow) { CleanBrowsers(browserFactory); } } if (ExpectedExceptionType != null && !exceptionWasThrow) { CurrentTestExceptions.Add(exception = new SeleniumTestFailedException("Test was supposted to fail and it did not.")); } }while (exception != null && attemptNumber < attampsMaximum); }
private void TryExecuteTest(Action<BrowserWrapper> action, IWebDriverFactory browserFactory, out string browserName, out Exception exception) { var attemptNumber = 0; do { attemptNumber++; exception = null; using (var browser = browserFactory.CreateNewInstance()) { helper = new BrowserWrapper(browser.Driver, this); browserName = browser.GetType().Name; WriteLine($"Testing browser '{browserName}' attempt no. {attemptNumber}"); try { action(helper); } catch (Exception ex) { bool isExpected = false; if (ExpectedExceptionType != null) { isExpected = ex.GetType() == ExpectedExceptionType || (AllowDerivedExceptionTypes && ExpectedExceptionType.IsInstanceOfType(ex)); } if (!isExpected) { TakeScreenshot(attemptNumber, helper); // fail the test exception = ex; } } } } while (exception != null && attemptNumber == SeleniumTestsConfiguration.TestAttemps); }