public void ExecuteMultipleBrowsers() { List <TestCase> lstRunTC; Report rptTCMultiBrowser; DateTime startTime; QCHelper qcHelper = null; foreach (TestCase testCase in ExecutionSession.lstTestCase) { lstRunTC = ExecutionSession.lstAllBrowsersTC.Where(browserTC => browserTC.TestCaseName == testCase.TestCaseName).ToList(); IRunTestCases runTestCases; List <ThreadClass> lstThreads = new List <ThreadClass>(); ThreadClass storeThread; int count = lstRunTC.Count; int threadCnt = 1; startTime = DateTime.Now; foreach (TestCase currentTestCase in lstRunTC) { runTestCases = TestSetUp.GetRunTestCase(); runTestCases.CurrentTestCase = currentTestCase; Thread runThread = new Thread(runTestCases.RunTestCase); runThread.Name = "Thread" + threadCnt; storeThread = new ThreadClass(); storeThread.ThreadName = runThread.Name; storeThread.currentThread = runThread; lstThreads.Add(storeThread); runThread.Start(); if (currentTestCase.Browser == Browser.FireFox) { Thread.Sleep(8000); } threadCnt++; } while (lstThreads.Any(thread => thread.currentThread.IsAlive)) { } DateTime endTime = DateTime.Now; TimeSpan timeTaken = endTime.Subtract(startTime); string executionTime = timeTaken.Minutes + " mins and " + timeTaken.Seconds + " secs"; rptTCMultiBrowser = new Report(); rptTCMultiBrowser.GenerateMultiBrowserDetailedReport(lstRunTC, timeTaken); try { if (HelperClass.QCUpdateResults) { qcHelper = new QCHelper(); qcHelper.UploadResults(testCase); } } catch (Exception ex) { Logger.Log(ex.ToString()); } } try { SummaryReport report = new SummaryReport(); report.GenerateSummaryReport(); TestSetUp.AddFailedTCToExcel(); } catch (Exception ex) { Logger.Log(ex.ToString()); } }
public void ExecuteMultipleTestCases() { IRunTestCases runTestCases = TestSetUp.GetRunTestCase(); List <ThreadClass> lstThreads = new List <ThreadClass>(); ThreadClass storeThread; int count = ExecutionSession.lstTestCase.Count; int runTestCaseCount = 0; if (ExecutionSession.lstTestCase.Count < HelperClass.runNoofThreads) { runTestCaseCount = ExecutionSession.lstTestCase.Count; } else { runTestCaseCount = HelperClass.runNoofThreads; } int threadCnt = 0; while (threadCnt < count) { if (threadCnt == 0) { for (int iLp = 1; iLp <= runTestCaseCount; iLp++) { TestCase testCase = ExecutionSession.lstTestCase[threadCnt]; runTestCases.CurrentTestCase = testCase; Thread runThread = new Thread(runTestCases.RunTestCase); runThread.Name = "Thread" + iLp; storeThread = new ThreadClass(); storeThread.ThreadName = runThread.Name; storeThread.currentThread = runThread; lstThreads.Add(storeThread); runThread.Start(); threadCnt++; Console.WriteLine("Threads executed is : " + threadCnt); Thread.Sleep(700); } } else { foreach (ThreadClass currentThread in lstThreads) { if (currentThread.currentThread.IsAlive == false) { if (threadCnt < count) { Console.WriteLine("Thread " + currentThread.ThreadName + " is alive :" + currentThread.currentThread.IsAlive); runTestCases = TestSetUp.GetRunTestCase(); TestCase testCase = ExecutionSession.lstTestCase[threadCnt]; runTestCases.CurrentTestCase = testCase; Thread runThread = new Thread(runTestCases.RunTestCase); runThread.Name = currentThread.ThreadName; currentThread.currentThread = runThread; runThread.Start(); threadCnt++; Console.WriteLine("Threads executed is : " + threadCnt); Thread.Sleep(700); } } } } } while (lstThreads.Any(thread => thread.currentThread.IsAlive)) { } try { SummaryReport report = new SummaryReport(); report.GenerateSummaryReport(); TestSetUp.AddFailedTCToExcel(); } catch (Exception ex) { Logger.Log(ex.ToString()); } }