【问题标题】:Issue while adding attachment to QC Test Case using Com4j API使用 Com4j API 向 QC 测试用例添加附件时出现问题
【发布时间】:2012-06-11 17:58:38
【问题描述】:

我正在尝试将附件添加到使用 Com4J API 从我的 Java 代码运行的 QC 测试实验室测试用例中。我能够成功运行,但是在下面的代码中添加附件时,会为“IAttachment attach = attachfac.addItem(null).queryInterface(IAttachment.class);”抛出无效参数。在这种情况下,additem 需要 Java 项目对象。我也尝试通过 addItem(""),但随后 attach.Type(1) 失败,原因是:- 无法更改附件类型。谁能帮我解决这个问题:

 IBaseFactory obj2 = testset.tsTestFactory().queryInterface(IBaseFactory.class);
 IList tstestlist = obj2.newList("");
  for(Com4jObject obj3:tstestlist){
   ITSTest tstest = obj3.queryInterface(ITSTest.class);
    if(tstest.name().contentEquals("[1]TC1")){
    System.out.println("TC found");
    IRunFactory runfactory = tstest.runFactory().queryInterface(IRunFactory.class);
    IRun run=runfactory.addItem("RunNew").queryInterface(IRun.class);
    run.status("Passed");
    IAttachmentFactory attachfac = run.attachments().queryInterface(IAttachmentFactory.class);
    IAttachment attach = attachfac.addItem("").queryInterface(IAttachment.class);
    attach.type(1);
    attach.fileName("Path to File TC1");
    attach.post();
    run.post();.

【问题讨论】:

  • 只是一个更新.. 我能够解决这个问题。我已经使用附件存储上传附件
  • 能否发个附件存储的代码示例

标签: java hp-quality-center com4j


【解决方案1】:
String fileName = new File(Attachment).getName();
String folderName = new File(Attachment).getParent();

try{
        IAttachmentFactory attachfac = tsteststeps.attachments().queryInterface(IAttachmentFactory.class);
    IAttachment attach = attachfac.addItem(fileName).queryInterface(IAttachment.class);
        IExtendedStorage extAttach = attach.attachmentStorage().queryInterface(IExtendedStorage.class);
    extAttach.clientPath(folderName);  
    extAttach.save(fileName, true);
    attach.description(Actual);
    attach.post();
    attach.refresh();                               
}catch(Exception e) {
    System.out.println("QC Exceptione : "+e.getMessage());
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-16
    • 2014-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    • 2017-03-17
    • 1970-01-01
    相关资源
    最近更新 更多