private void recorder_CommandRecording(object sender, Recorder.CommandRecorderEventArgs e) { var testCase = this.GetActiveWorkbookContext().GetActiveTestCase(); Excel.ListObject listObject = testCase.ListObject; Excel.ListRow listRow = ListObjectHelper.GetEmptyRow(listObject); ListRowHelper.Set(listRow, ListRowHelper.ColumnIndex.Command, e.Command); ListRowHelper.Set(listRow, ListRowHelper.ColumnIndex.Target, e.Target); ListRowHelper.Set(listRow, ListRowHelper.ColumnIndex.Value, e.Value); }
/// <summary> /// /// </summary> /// <param name="workbook"></param> /// <param name="worksheet"></param> /// <param name="listObject"></param> /// <param name="listRow"></param> /// <param name="data"></param> /// <returns></returns> public TestStep CompileFromListRow( Excel.Workbook workbook, Excel.Worksheet worksheet, Excel.ListObject listObject, Excel.ListRow listRow, Dictionary <string, string> data) { if (null == listObject) { throw new ArgumentNullException("listObject"); } if (null == listRow) { throw new ArgumentNullException("listRow"); } ExcelHelper.SetColor(listRow.Range, Constants.ColorNone); ListRowHelper.Set(listRow, ListRowHelper.ColumnIndex.Error, string.Empty); string name = ListRowHelper.Get(listRow, ListRowHelper.ColumnIndex.Command); if (string.IsNullOrWhiteSpace(name)) { return(null); } try { var command = TestCommandFactory.CreateCommand(name); var target = this.GetValue(data, ListRowHelper.Get(listRow, ListRowHelper.ColumnIndex.Target)); var value = this.GetValue(data, ListRowHelper.Get(listRow, ListRowHelper.ColumnIndex.Value)); this.SyntaxCheck(command, target, value); var step = new TestStep( workbook, worksheet, listRow, command, target, value); return(step); } catch (Exception ex) { Log.Logger.Warn(ex); ExcelHelper.SetColor(listRow.Range, Constants.ColorPink); Excel.Range range = ListRowHelper.Set(listRow, ListRowHelper.ColumnIndex.Error, ex.Message); //ExcelHelper.AddComment(range, ex.Message); throw; } }
private void CreateEvidence(TestContextImpl context, TestStep step) { ITakesScreenshot takesScreenshot = context.Driver as ITakesScreenshot; if (null == takesScreenshot) { return; } bool isAlertPresent = false; try { IAlert alert = context.Driver.SwitchTo().Alert(); isAlertPresent = true; } catch (OpenQA.Selenium.NoAlertPresentException) { isAlertPresent = false; } if (isAlertPresent) { return; } Excel.Workbook workbook = context.WorkbookContext.Workbook; Excel.Worksheet evidenceWorksheet = context.WorkbookContext.AddEvidence(); Excel.Range range = ListRowHelper.Set(step.ListRow, ListRowHelper.ColumnIndex.Evidence, evidenceWorksheet.Name); ExcelHelper.SetText(evidenceWorksheet, 1, 1, Properties.Resources.Evidence_Scenario, false).ColumnWidth = 20; ExcelHelper.AddHyperLink( step.Worksheet, range, evidenceWorksheet, evidenceWorksheet.Cells[1, 1]); ExcelHelper.AddHyperLink( evidenceWorksheet, evidenceWorksheet.Cells[1, 2], step.Worksheet, range); ExcelHelper.SetText(evidenceWorksheet, 2, 1, Properties.Resources.Evidence_Command, false); ExcelHelper.SetText(evidenceWorksheet, 2, 2, step.ToString(), false); ExcelHelper.SetText(evidenceWorksheet, 3, 1, Properties.Resources.Evidence_ErrorMessage, false); ExcelHelper.SetText(evidenceWorksheet, 3, 2, step.ErrorMessage, false); ExcelHelper.SetText(evidenceWorksheet, 4, 1, Properties.Resources.Evidence_Browser, false); ExcelHelper.SetText(evidenceWorksheet, 4, 2, App.Context.Settings.WebDriverType.ToString(), false); ExcelHelper.SetText(evidenceWorksheet, 5, 1, Properties.Resources.Evidence_Title, false); ExcelHelper.SetText(evidenceWorksheet, 5, 2, context.Driver.Title, false); ExcelHelper.SetText(evidenceWorksheet, 6, 1, Properties.Resources.Evidence_Url, false); ExcelHelper.SetText(evidenceWorksheet, 6, 2, context.Driver.Url, false); ExcelHelper.SetText(evidenceWorksheet, 7, 1, Properties.Resources.Evidence_Time, false); ExcelHelper.SetText(evidenceWorksheet, 7, 2, DateTime.Now.ToString(), false); string path = Path.Combine(App.TempDir, Guid.NewGuid().ToString()) + ".jpg"; try { Screenshot screenshot = takesScreenshot.GetScreenshot(); screenshot.SaveAsFile(path, ImageFormat.Jpeg); Excel.Shape shape = evidenceWorksheet.Shapes.AddPicture( path, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 0, 150, 0, 0); shape.ScaleWidth(1, Microsoft.Office.Core.MsoTriState.msoTrue); shape.ScaleHeight(1, Microsoft.Office.Core.MsoTriState.msoTrue); } finally { File.Delete(path); } }