Ejemplo n.º 1
0
        /// <summary>
        ///  Gets the objects in the Excelfile
        /// </summary>
        /// <param name="fileName">File name</param>
        /// <returns>Array of data in the excell file</returns>
        public object[,] GetExcelFileObjects(string fileName)
        {
            var folderPath = _configHandler.ReadFolderPathFromConfigurationFile(SolutionSubFolder.TestData);
            var filePath   = Path.Combine(folderPath, fileName);

            Log.Info($"Trying to open the File: {fileName} in the path: {filePath}");
            // Get the file we are going to process
            if (!File.Exists(filePath))
            {
                var message = $"{fileName} could not found in {filePath}";
                Log.Error(message);
                throw new FileNotFoundException(message);
            }
            var existingFile = new FileInfo(filePath);

            // Open and read the XlSX file.
            Log.Info("Trying to load all abjedts from the file");
            using (var package = new ExcelPackage(existingFile))
            {
                object[,] allObjects = { };
                // Get the work book in the file
                var workBook = package.Workbook;
                if (workBook?.Worksheets.Count > 0)
                {
                    // Get the first worksheet
                    var currentWorksheet = workBook.Worksheets.First();
                    Log.Info($"Current Sheet: {currentWorksheet}");
                    // read some data
                    allObjects = (object[, ])currentWorksheet.Cells.Value;
                }
                return(allObjects);
            }
        }
Ejemplo n.º 2
0
        public void BuildReport(List <TestResult> testResultList, Stopwatch watch)
        {
            var table = new StringBuilder();

            table.AppendLine(_html);
            table.AppendLine("  <table class='table table-dark'>");
            table.AppendLine("  <thead>");
            table.AppendLine("<tr>");
            table.AppendLine("<th> Test Step </th>");
            table.AppendLine("<th> Comment </th>");
            table.AppendLine("<th> Test Status </th>");
            table.AppendLine("<th> Elapsed Time </ th>");
            table.AppendLine(" </tr>  ");
            table.AppendLine(" </thead>");
            table.AppendLine(" <tbody>");
            var passCount    = testResultList.Count(x => x.TestStatus == Status.Pass);
            var failCount    = testResultList.Count(x => x.TestStatus == Status.Fail);
            var pendingCount = testResultList.Count(x => x.TestStatus == Status.Pending);

            GetHtmlHead(passCount, failCount, pendingCount);
            foreach (var testresult in testResultList)
            {
                table.AppendLine("<tr>");
                table.AppendLine("<td>").Append(testresult.TestStep).Append("</td>");
                table.AppendLine("<td>").Append(testresult.Comment).Append("</td>");
                table.AppendLine("<td>").Append(testresult.TestStatus).Append("</td>");
                table.AppendLine("<td>").Append(testresult.ElapsedTime).Append("</td>");
                table.AppendLine("</tr>");
                Log.Info("Adding\r\n" + testresult);
            }

            table.AppendLine("</tbody>");
            table.AppendLine("</table>");
            double time = watch.ElapsedMilliseconds;

            time = time / 1000;
            table.AppendLine($"<p>Time Spent: {time}S</p>");
            var html = GetFooter(table.ToString(), passCount, failCount, pendingCount);

            html = _html + html;
            var appconfig  = new AppConfigHandler();
            var reportPath = appconfig.ReadFolderPathFromConfigurationFile(SolutionSubFolder.Reports);
            var dateTime   = DateTime.Now.ToString("MMMM dd  yyyy hh mm ss");

            try
            {
                reportPath = Path.Combine(reportPath, dateTime + ".html");
                File.WriteAllText(reportPath, html);
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw;
            }
        }
Ejemplo n.º 3
0
        public void firingDriver_TakeScreenshotOnException(object sender, WebDriverExceptionEventArgs e)
        {
            var timestamp = DateTime.Now.ToString("yyyy-MM-dd-hhmm-ss");

            var conf       = new AppConfigHandler();
            var folderPath = conf.ReadFolderPathFromConfigurationFile(SolutionSubFolder.Logs);
            var imagePath  = Path.Combine(folderPath, "ChromeException-" + timestamp + ".png");

            _driver.TakeScreenshot().SaveAsFile(imagePath, ScreenshotImageFormat.Bmp);
            var filePath = Path.Combine(folderPath, "ChromeException-" + timestamp + ".txt");

            File.WriteAllText(filePath, e.ThrownException.ToString());
        }