java - 使用 Com4j API 添加附件到 QC 测试用例时出现问题

标签 java hp-quality-center com4j

我正在尝试使用 Com4J API 将附件添加到从我的 Java 代码运行的 QC 测试实验室测试用例。我能够创建成功的运行,但是在代码下方添加附件时为“IAttachment attach = attachfac.addItem(null).queryInterface(IAttachment.class);”抛出无效参数。在这种情况下,additem 需要 Java Item 对象。我还尝试传递 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();.

最佳答案

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());
}

关于java - 使用 Com4j API 添加附件到 QC 测试用例时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10985161/

相关文章:

java - 无法从 Apache Camel 路由 XML 配置到 Java 方法获取单引号

java - 使用 Com4j 从 QC 获取测试用例列表

vba - Excel VBA 代码在 QC 测试用例中附加文件

java - Com4j 因 DirectByteBuffer、Cleaner、Finalizer、Variant 实例而泄漏

java - 使用 Java 和 COM4J 的 Quality Center V11 脚本统计

java - Spring Batch(java-config)在 jobExeuctionDecider 之后执行步骤

java - 缺少数据库连接 eclipse

java - 找不到能够从类型 [java.util.LinkedHashMap<?, ?>] 转换为类型的转换器

selenium - Mercury Test Director 与 Selenium : Compare and Contrast