2012-06-11 96 views
2

我正嘗試使用Com4J API從我的Java代碼運行QC Test LAB測試用例。我能夠創建一個成功的運行,但是,在代碼下面添加附件時,會拋出「IAttachment attach = attachfac.addItem(null).queryInterface(IAttachment.class);」的無效參數。在這種情況下,additem需要Java項目對象。我也嘗試通過addItem(「」),但隨後attach.Type(1)失敗,原因: - 附件類型不能更改。任何人都可以請幫我這個:使用Com4j API向QC測試用例添加附件時出現問題

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();. 
+0

只是一個更新..我能解決這個問題。我已經使用附件存儲上傳附件 – user1449507

+0

可以請您發佈附件存儲的代碼示例 – Vivek

回答

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()); 
} 
相關問題