internal static void CheckExpectations(ExceptionTracker exceptionTracker, SignalX signalX, int numberOfClients, Action operation, string url, List <TestObject> testObjects, BrowserType browserType = BrowserType.Default, TestEventHandler events = null) { Thread thread = null; var browserProcess = new List <Process>(); /* * */ //https://stackoverflow.com/questions/22538457/put-a-string-with-html-javascript-into-selenium-webdriver //https://www.automatetheplanet.com/selenium-webdriver-csharp-cheat-sheet/ var option = new FirefoxOptions(); option.AddArgument("--headless"); var _drivers = new List <IWebDriver>(); if (browserType == BrowserType.HeadlessBrowser) { for (int i = 0; i < testObjects.Count; i++) { _drivers.Add( new FirefoxDriver( option // Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), )); } } try { using (WebApp.Start <Startup>(url)) { events?.OnAppStarted?.Invoke(); thread = new Thread( () => { try { for (int i = 0; i < testObjects.Count; i++) { TestObject testObject = testObjects[i]; if (browserType == BrowserType.SystemBrowser) { browserProcess.Add(Process.Start(url + testObject.FileName)); } if (browserType == BrowserType.Default || browserType == BrowserType.HeadlessBrowser) { _drivers[i].Navigate().GoToUrl(url); ((IJavaScriptExecutor)_drivers[i]).ExecuteScript($"arguments[0].innerHTML = '{testObject.PageHtml}'"); } } } catch (Exception e) { events?.OnClientError?.Invoke(new AggregateException(e, exceptionTracker.Exception)); } }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); // SpinWait.SpinUntil(() => (!SignalX.Settings.HasOneOrMoreConnections || SignalX.CurrentNumberOfConnections < (ulong)numberOfClients), MaxTestWaitTimeBeforeChecks); AwaitAssert( () => { if (!signalX.Settings.HasOneOrMoreConnections) { throw new Exception("No connection received from any client.This may also be caused by a slow connection " + exceptionTracker?.Exception?.Message); } if (signalX.ConnectionCount < (ulong)numberOfClients) { throw new Exception($"Wait timeout for expected number of clients {numberOfClients} to show up.This may also be caused by a slow connection " + exceptionTracker?.Exception?.Message); } }, () => { if (exceptionTracker.Exception != null) { throw exceptionTracker.Exception; } }, MaxWaitTimeForAllExpectedConnectionsToArrive); new SignalXAssertionLib().WaitForSomeTime(MaxTestWaitTimeBeforeChecks); events?.OnClientLoaded?.Invoke(); //wait for some time before checks to allow side effects to occur AwaitAssert( () => { operation(); //if we got this far, then we made it events?.OnCheckSucceeded?.Invoke(); }, () => { if (exceptionTracker.Exception != null) { throw exceptionTracker.Exception; } }, MaxTestTimeSpan, null, ex => { //to handle both exceptions if (exceptionTracker.Exception != null) { events?.OnFinally?.Invoke(exceptionTracker.Exception); } else { events?.OnFinally?.Invoke(ex); } }, events?.OnCheckFailures); } } finally { QuitAllBrowsers(_drivers, browserProcess, thread, testObjects, browserType); signalX.Dispose(); } }