0

我在 vbscript 中创建了一段代码,通过它我可以通过 OTA 在 ALM 中创建测试脚本。现在我试图通过使用 JACOB 作为 Java 2 Com 桥的 Java 做同样的事情,我已经能够使用它创建一个空的测试脚本,但我不确定如何设置各种字段值。

VBScript 代码(完美运行):

           Set tdc = CreateObject("TDAPIOLE80.TDConnection")
           If (tdc Is Nothing) Then
             MSGBOX "Connection is not created"
           Else
            MSGBOX "Connection is created"
           End If
           tdc.InitConnectionEx connectionString
           tdc.Login userName, password
           tdc.Connect domain, project
           Set TreeMgr = tdc.TreeManager
           Set testFolder = TreeMgr.NodeByPath(uploadDirectoryPath)
           Set testFactory = testFolder.TestFactory
           Set testItem = testFactory.AddItem (NULL)
           testItem.Field("TS_DESCRIPTION")="Test script description"
           ...

Java 代码(只有这么多有效)

     ActiveXComponent almConnection=new ActiveXComponent("TDAPIOLE80.TDConnection");
    Dispatch.call(almConnection, "InitConnectionEx", "conn string");        
    Dispatch.call(almConnection, "login", "uname","pword");
    Dispatch.call(almConnection, "connect","project","domain");     
    Dispatch treeMgr=Dispatch.get(almConnection, "TreeManager").toDispatch();
    Dispatch testFolder=Dispatch.call(treeMgr,"NodeByPath", "project path").toDispatch();
    Dispatch testFactory=Dispatch.get(testFolder, "TestFactory").toDispatch();              
    Dispatch testItem=Dispatch.call(testFactory,"AddItem","TO_BE_DELETED_SCRIPT9").toDispatch();

现在问题是 VBScript 代码的最后一行,

            testItem.Field("TS_DESCRIPTION")="Test script description"

如何使用 JACOB 在 Java 中对此进行编码?请帮忙。我做了很多谷歌搜索,但没有找到任何实质性的东西。

4

1 回答 1

2

这对我有用:

Dispatch testItem=Dispatch.call(testFactory,"AddItem","TestName").toDispatch();
Dispatch.put(testItem, "Name", "newTestName");
Dispatch.call(testItem,"Post");

如何使用 JACOB 更改 HPQC 中的字段值:

http://sourceforge.net/projects/jacob-project/forums/forum/375946/topic/4830213

于 2012-10-30T21:16:59.663 回答