有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我正在尝试使用com4japi将附件添加到从Java代码运行的QC测试实验室测试用例中。我能够创建一个成功的运行,但是在下面添加附件时,代码抛出了无效的参数“IAttachment attach=attachfac.addItem(null).queryInterface(IAttachment.class);”。在本例中,additem应为Java项对象。我还试图传递addItem(“”),但随后附加。类型(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();.

共 (1) 个答案

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