0

我有一个用 C# 开发的应用程序测试框架,它在每个步骤之后将结果存储在 Excel 文件中。在解决方案中执行时,一切正常。但是,当我将解决方案与 Fitnesse 集成并调用该方法时,会引发错误。我在下面的 Fitness 添加了堆栈跟踪。

代码段在这里:

public class ExcelReports : IReporter
{
    private Excel.Application xlReport;
    public ExcelReports()
    {
        xlReport = new Excel.Application();
        Excel.Workbook xlWorkbook = xlReport.Workbooks.Add();
        ***xlWorkbook.SaveAs(ExecutionContext.RESULTFILE);***
    }
  }

报错在 xlWorkbook.SaveAs(ExecutionContext.RESULTFILE)

我正在为 .NET 4.0 版本使用 fit 和 fitsharp dll。

    System.Reflection.TargetInvocationException: Exception has been thrown by the
    target of an invocation. ---> System.Reflection.TargetInvocationException:
    Exception has been thrown by the target of an invocation. --->
    System.Runtime.InteropServices.COMException: Microsoft Excel cannot access the file
   'C:\0452CB00'. There are several possible reasons:
    • The file name or path does not exist.
    • The file is being used by another program.
    • The workbook you are trying to save has the same name as a currently open 
    workbook.
    at Microsoft.Office.Interop.Excel._Workbook.SaveAs(Object Filename, Object    
    FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, 
    Object CreateBackup, XlSaveAsAccessMode AccessMode, Object ConflictResolution, 
    Object AddToMru, Object TextCodepage, Object TextVisualLayout, Object Local)
    at EF.UIAutomation.Commons.ExcelReports..ctor() in
           C:\EF.Automation\EF.UIAutomation.PageLibrary\Libraries\EF.UIAutomation.Commons.Reports.cs:l ine 25

    at EF.UIAutomation.Launcher.Program.Test() in
    C:\EF.Automation\EF.Automation\Program.cs:line 26

     --- End of inner exception stack trace ---
     at fitSharp.Machine.Model.TypedValue.ThrowExceptionIfNotValid()
     at fitSharp.Fit.Operators.CompareDefault.Compare(TypedValue actualValue, Tree`1
     expected)
     at fitSharp.Machine.Engine.ProcessorBase`2.<>c__DisplayClass3.
     <>c__DisplayClass5.b__2(CompareOperator`1 o)

     at fitSharp.Machine.Engine.Operators`2.Do[O](CanDoOperation`1 canDoOperation, 
     DoOperation`1 doOperation)
     at fitSharp.Machine.Engine.ProcessorBase`2.
     <>c__DisplayClass3.b__0(OperationLogging logging)
     at fitSharp.Machine.Engine.ProcessorBase`2.DoLoggedOperation[R](String
     startMessage, Func`2 operation)
     at fitSharp.Machine.Engine.ProcessorBase`2.Compare(TypedValue instance, Tree`1
     parameters)
     at fitSharp.Fit.Operators.CheckDefault.Check(CellOperationValue actualValue, 
     Tree`1 expectedCell)
     --- End of inner exception stack trace ---
     at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, 
     Signature sig, Boolean constructor)
     at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[]
     parameters, Object[] arguments)
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, 
     Binder binder, Object[] parameters, CultureInfo culture)
     at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder
     binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers,
     CultureInfo culture, String[] namedParams)
     at fitSharp.Machine.Engine.MethodMember.TryInvoke(Object[] parameters)
     at fitSharp.Machine.Engine.ReflectionMember.Invoke(Object[] parameters)
     at fitSharp.Machine.Engine.ProcessorBase`2.Operate[O](Object[] parameters)
     at fitSharp.Fit.Engine.CellProcessorExtension.Check(CellProcessor processor, 
     Object systemUnderTest, Tree`1 memberName, Tree`1 parameters, Tree`1 expectedCell)
     at fitSharp.Fit.Service.CheckBinding.Do(Tree`1 cell)
     at fitSharp.Fit.Service.Binding.Do(Tree`1 cell)
     at fit.ColumnFixture.DoCell(Parse cell, Int32 column)
4

0 回答 0