public static void OpenBrowser() { string browValue = Readdata.ProcessOnCollection(LoginCollection, "Browser"); SystemOsversion = System.Environment.OSVersion.ToString(); SystemMachineName = System.Environment.MachineName; if (browValue != null) { switch (browValue)//BrowserName, BrowserVersion, BrowserPlatForm, SystemMachineName { case "Chrome": webdriver = new ChromeDriver(Driverpath); ICapabilities Chcapabilities = ((RemoteWebDriver)webdriver).Capabilities; BrowserName = Chcapabilities.BrowserName; BrowserVersion = Chcapabilities.Version; BrowserPlatForm = Chcapabilities.Platform.ToString(); ExtentReport.test = ExtentReport.extent.StartTest("OHS Connect Login"); ExtentReport.PrintExtentReport(LogStatus.Pass, "\"Google Chrome Browser\" Opened", "Pass"); TakeScreenShot("Pass"); break; case "IE": var optionsIE = new InternetExplorerOptions(); optionsIE.IntroduceInstabilityByIgnoringProtectedModeSettings = true; webdriver = new InternetExplorerDriver(Driverpath, optionsIE); ICapabilities IEcapabilities = ((RemoteWebDriver)webdriver).Capabilities; BrowserName = IEcapabilities.BrowserName; BrowserVersion = IEcapabilities.Version; BrowserPlatForm = IEcapabilities.Platform.ToString(); ExtentReport.test = ExtentReport.extent.StartTest("OHS Connect Login"); ExtentReport.PrintExtentReport(LogStatus.Pass, "\"Internet Explorer Browser\" Opened", "Pass"); TestSuit.TakeScreenShot("Pass"); break; case "Firefox": FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(TestSuit.Driverpath); webdriver = new FirefoxDriver(service); ICapabilities FFcapabilities = ((RemoteWebDriver)webdriver).Capabilities; BrowserName = FFcapabilities.BrowserName; BrowserVersion = FFcapabilities.Version; BrowserPlatForm = FFcapabilities.Platform.ToString(); ExtentReport.test = ExtentReport.extent.StartTest("OHS Connect Login"); ExtentReport.PrintExtentReport(LogStatus.Pass, "\"Mozilla Firefox Browser\" Opened", "Pass"); TakeScreenShot("Pass"); break; } } }
public static bool email_send(string filepath, string ErrorFilePath, string SystemMachineName, string[] EmailCollection, string projectName) { ExcelReport.ReadData Readdata = new ExcelReport.ReadData(); try { //Console.WriteLine("In email_send method"); List <String> to = new List <string>(); List <String> cc = new List <string>(); List <String> bcc = new List <string>(); List <String> Attachment = new List <string>(); //Set Email To path, It will take path from App.config if available, otherwise default loction will be Input file path To = string.Concat((ConfigurationManager.AppSettings["ToEmail"].ToString() == "") ? Readdata.ProcessOnCollection(EmailCollection, "EmailTo") : ConfigurationManager.AppSettings["ToEmail"].ToString()); //Set Email CC path, It will take path from App.config if available, otherwise default loction will be Input file path Cc = string.Concat((ConfigurationManager.AppSettings["CcEmail"].ToString() == "") ? Readdata.ProcessOnCollection(EmailCollection, "EmailCc") : ConfigurationManager.AppSettings["CcEmail"].ToString()); //Set Email Subject path, It will take path from App.config if available, otherwise default loction will be Input file path Subj = string.Concat((ConfigurationManager.AppSettings["SubjectEmail"].ToString() == "") ? Readdata.ProcessOnCollection(EmailCollection, "EmailSubject") : ConfigurationManager.AppSettings["SubjectEmail"].ToString()); //string To = ConfigurationManager.AppSettings["EmailTo"].ToString(); //To = Readdata.ProcessOnCollection(EmailCollection, "EmailTo"); //string Cc = ConfigurationManager.AppSettings["EmailCc"]; // Cc = Readdata.ProcessOnCollection(EmailCollection, "EmailCC"); //string Subj = ConfigurationManager.AppSettings["EmailSubject"]; // Subj = Readdata.ProcessOnCollection(EmailCollection, "EmailSubject"); string Message = string.Empty; //= "Hello," + Environment.NewLine + "Please find attached excel sheet to view automation test results. " + Environment.NewLine // + Environment.NewLine + "You can find more details - " + SystemMachineName + " in " + Environment.CurrentDirectory // + Environment.NewLine + Environment.NewLine + "Thanks." + Environment.NewLine + "ProCare Transportation and Language Services"; System.Text.StringBuilder body = new System.Text.StringBuilder(); body.Clear(); body.Length = 0; string bodyText = PopulateBody(projectName, TestSuit.pass.ToString(), TestSuit.fail.ToString(), TestSuit.skip.ToString(), TestSuit.error.ToString(), (TestSuit.pass + TestSuit.fail + TestSuit.skip + TestSuit.error).ToString()); body.Append(bodyText); //body.Append("<table><tr><td colspan='3' class='Content'> <h3 align='center' id='reportHeader'> ${ReportHeader} </h3></td></tr>"); // body.Append(""); /*body.Append("<table border='0' class='subtable' cellpadding='0' cellspacing='0' style='background-color: White; font-family:Calibri;'>"); * body.Append("<tr><td colspan='12'>Hello,</td></tr>" + "\r\n"); * body.Append("<tr style='height: 6px'><td colspan='12'><br></td></tr>" + "\r\n"); * body.Append("<tr><td colspan='12'>Please find attached excel sheet to view automation test results.</td></tr>" + "\r\n"); * body.Append("<tr><td colspan='12'>You can find more details - " + SystemMachineName + " in " + Environment.CurrentDirectory + "</td></tr>" + "\r\n"); * body.Append("<tr style='height: 6px'><td colspan='12'><br></td></tr>" + "\r\n"); * body.Append("<tr><td colspan='12'>Thanks, </td></tr>" + "\r\n"); * body.Append("<tr style='height: 6px'><td colspan='12'><br></td></tr>" + "\r\n"); * body.Append("<tr><td colspan='12' style='color:#D50000; font-size:14px; font-style:italic; font-family: Times New Roman;'>\"Tailors Mark\"</td></tr></table>" + "\r\n");*/ Message = body.ToString(); if (!string.IsNullOrEmpty(To)) { string[] ToMuliId = To.Split(';'); foreach (string ToEMailId in ToMuliId) { if (ToEMailId != "") { to.Add(ToEMailId); } } } if (!string.IsNullOrEmpty(Cc)) { string[] CCId = Cc.Split(';'); foreach (string CCEmail in CCId) { if (CCEmail != "") { cc.Add(CCEmail); } } } if (!string.IsNullOrEmpty(filepath)) { string[] mailAttachments = filepath.Split(';'); foreach (string mailAttach in mailAttachments) { if (mailAttach != "") { Attachment.Add(mailAttach); } } } if (!string.IsNullOrEmpty(ErrorFilePath)) { string[] mailAttachments = ErrorFilePath.Split(';'); foreach (string mailAttach in mailAttachments) { if (mailAttach != "") { Attachment.Add(mailAttach); } } } bool success; string ErrMsg = ""; try { MailMessage mailMessage = new MailMessage(); mailMessage = SetMailParameters(to, ConfigurationManager.AppSettings["FromEmail"].ToString(), Subj, Message, mailMessage); mailMessage = SetCopyParameters(cc, bcc, mailMessage); mailMessage = SetAttachmentPath(Attachment, mailMessage); mailMessage.IsBodyHtml = true; SmtpClient client = new SmtpClient(); string UserName = ConfigurationManager.AppSettings["Username"]; string Host = ConfigurationManager.AppSettings["EmailHost"]; bool Ssl = Convert.ToBoolean(ConfigurationManager.AppSettings["EmailSsl"]); string pwd = ConfigurationManager.AppSettings["EmailPwd"]; string Port = ConfigurationManager.AppSettings["EmailPort"]; client = AuthenticateCredentials(Host, Convert.ToInt16(Port), Ssl, UserName, pwd, client); // Console.WriteLine("About to send"); client.Send(mailMessage); success = true; Console.WriteLine("Sent"); } catch (Exception Ex) { TestSuit.TakeScreenShot("Fail"); logger.WriteLog(Ex); success = false; ErrMsg = Ex.Message; } return(success); } catch (Exception Ex) { TestSuit.TakeScreenShot("Fail"); logger.WriteLog(Ex); return(false); } }