private void btn_ExecuteTests_Click(object sender, EventArgs e) { try { Automation.Mercury.Report.Engine reportEngine = new Automation.Mercury.Report.Engine(Util.EnvironmentSettings["ReportsPath"], Util.EnvironmentSettings["Server"]); try { foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[0].Value.Equals(true)) { string testCaseModuleName = row.Cells[1].Value.ToString().Trim(); string testCaseSubModuleName = row.Cells[2].Value.ToString().Trim(); string strBrowserName = ConfigurationManager.AppSettings.Get("DefaultBrowser").ToString(); string testCaseRequirementFeature = string.Concat(testCaseModuleName, " - ", testCaseSubModuleName); string testCaseName = row.Cells[3].Value.ToString().Trim(); TestCase testCaseReporter = new TestCase(testCaseName.Split('_')[0], testCaseName, testCaseRequirementFeature); testCaseReporter.Summary = reportEngine.Reporter; reportEngine.Reporter.TestCases.Add(testCaseReporter); string strBrowserId = string.Empty; // browsers foreach (String browserId in strBrowserName.ToString().Split(new char[] { ';' })) { strBrowserId = browserId != String.Empty ? browserId : ConfigurationManager.AppSettings.Get("DefaultBrowser").ToString(); Browser browserReporter = new Browser(strBrowserId); browserReporter.TestCase = testCaseReporter; testCaseReporter.Browsers.Add(browserReporter); // Get the Test data details XmlDocument xmlTestDataDoc = new XmlDocument(); xmlTestDataDoc.Load("TestData/" + testCaseModuleName + ".xml"); XmlNodeList testdataNodeList = xmlTestDataDoc.DocumentElement.SelectNodes("/TestData/" + testCaseName.Split(',')[0].Replace("CAO.Automation.Tests.", string.Empty)); //XmlNodeList testdataNodeList = xmlTestDataDoc.DocumentElement.SelectNodes("/TestData/" + testCaseName.Replace("CAO.Automation.Tests", string.Empty)); //Iterate for each data foreach (XmlNode testDataNode in testdataNodeList) { Dictionary <String, String> browserConfig = Util.GetBrowserConfig(strBrowserId); string iterationId = testDataNode.SelectSingleNode("TDID").InnerText; string defectID = testDataNode.SelectSingleNode("DefectID").InnerText; Iteration iterationReporter = new Iteration(iterationId, defectID); iterationReporter.Browser = browserReporter; browserReporter.Iterations.Add(iterationReporter); //testCaseToExecute.Add(new Object[] { testCaseName,browserConfig, testCaseId, iterationId, iterationReporter, null, testDataNode, reportEngine }); testCaseToExecute.Add(new Object[] { testCaseReporter, browserConfig, testDataNode, iterationReporter, reportEngine }); } } } } Processor(Int32.Parse(ConfigurationManager.AppSettings.Get("MaxDegreeOfParallelism"))); reportEngine.Summarize(); this.Activate(); LinkLabel.Link link = new LinkLabel.Link(); String fileName = Path.Combine(reportEngine.ReportPath, "Summary.html"); link.LinkData = fileName; lnklbl_OverallExeStatResult.Links.Add(link); lnklbl_OverallExeStatResult.Text = "PASSED " + DateTime.Now; } catch (Exception) { this.Activate(); LinkLabel.Link link = new LinkLabel.Link(); String fileName = Path.Combine(reportEngine.ReportPath, "Summary_Provisional.html"); link.LinkData = fileName; lnklbl_OverallExeStatResult.Links.Add(link); bool overallPassed = true; foreach (TestCase testCase in reportEngine.Reporter.TestCases) { if (!testCase.IsSuccess) { overallPassed = false; break; } } if (!overallPassed) { lnklbl_OverallExeStatResult.Text = "FAILED " + DateTime.Now; } else { lnklbl_OverallExeStatResult.Text = "PASSED " + DateTime.Now; } } } catch { } }
/// <summary> /// Executes Test Cases /// </summary> public void Execute(Dictionary <String, String> browserConfig, String testCaseId, String iterationId, Report.Iteration iteration, Dictionary <String, String> testData, Report.Engine reportEngine, string iterationTestCasename) { try { this.Driver = Util.GetDriver(browserConfig); this.Reporter = iteration; this.TestCaseId = testCaseId; this.TestDataId = iterationId; this.TestData = testData; this.resultsPath = reportEngine.ReportPath; this.IterationTestCaseName = iterationTestCasename; if (browserConfig["target"] == "local") { var wmi = new ManagementObjectSearcher("select * from Win32_OperatingSystem").Get().Cast <ManagementObject>().First(); this.Reporter.Browser.PlatformName = String.Format("{0} {1}", ((string)wmi["Caption"]).Trim(), (string)wmi["OSArchitecture"]); this.Reporter.Browser.PlatformVersion = ((string)wmi["Version"]); this.Reporter.Browser.BrowserName = Driver.Capabilities.BrowserName; this.Reporter.Browser.BrowserVersion = Driver.Capabilities.Version.Substring(0, 2); } else { this.Reporter.Browser.PlatformName = browserConfig.ContainsKey("os") ? browserConfig["os"] : browserConfig["device"]; this.Reporter.Browser.PlatformVersion = browserConfig.ContainsKey("os_version") ? browserConfig["os_version"] : browserConfig.ContainsKey("realMobile") ? "Real" : "Emulator"; this.Reporter.Browser.BrowserName = browserConfig.ContainsKey("browser") ? browserConfig["browser"] : "Safari"; this.Reporter.Browser.BrowserVersion = browserConfig.ContainsKey("browser_version") ? browserConfig["browser_version"].Substring(0, 2) : ""; } // Does Seed having anything? if (this.Reporter.Chapter.Steps.Count == 0) { this.Reporter.Chapters.RemoveAt(0); } this.Reporter.StartTime = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")); ExecuteTestCase(); } catch (Exception ex) { this.Reporter.Chapter.Step.Action.IsSuccess = false; this.Reporter.Chapter.Step.Action.Extra = "Exception Message : " + ex.Message + "<br/>" + ex.InnerException + ex.StackTrace; if (!(ex.ToString().Contains("target window already closed") || ex.ToString().Contains("chrome not reachable") || ex.ToString().Contains("unexpected alert open") || (ex.ToString().Contains("timed out after 60 seconds.")))) { // If current iteration is a failure, get screenshot if (!Reporter.IsSuccess) { ITakesScreenshot iTakeScreenshot = Driver; this.Reporter.Screenshot = iTakeScreenshot.GetScreenshot().AsBase64EncodedString; } } } finally { this.Reporter.IsCompleted = true; // If current iteration is a failure, get screenshot this.Reporter.EndTime = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")); lock (reportEngine) { reportEngine.PublishIteration(this.Reporter); reportEngine.Summarize(false); } Driver.Quit(); } }