0

任何人都可以帮助我解决以下问题我想通过 Java 在 QC 中传递测试用例,我使用了 con4j 并达到了测试集,但我无法获取相应测试集下的测试用例。任何人都可以帮助我如何通过 com4j 在 QC 中通过测试用例

import com.qc.ClassFactory;
import com.qc.ITDConnection;
import com.qc.ITestLabFolder;
import com.qc.ITestSetFactory;
import com.qc.ITestSetTreeManager;
import com.qc.ITestSetFolder;
import com.qc.IList;
import com.qc.ITSTest;
import com.qc.ITestSet;
import com.qc.ITestFactory;
import com4j.*;
import com4j.stdole.*;
import com4j.tlbimp.*;
import com4j.tlbimp.def.*;
import com4j.tlbimp.driver.*;
import com4j.util.*;
import com4j.COM4J;
import java.util.*;
import com.qc.IRun;
import com.qc.IRunFactory;


public class Qc_Connect {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String url="http://abc/qcbin/";
        String domain="abc";
        String project="xyz";
        String username="132222";
        String password="Xyz";
        String strTestLabPath = "Root\\Test\\"; 
        String strTestSetName = "TestQC";   


                try{
            ITDConnection itd=ClassFactory.createTDConnection();
            itd.initConnectionEx(url);
            System.out.println("COnnected To QC:"+ itd.connected());

            itd.connectProjectEx(domain,project,username,password);

            System.out.println("Logged into QC");

            //System.out.println("Project_Connected:"+ itd.connected());


            ITestSetFactory objTestSetFactory = (itd.testSetFactory()).queryInterface(ITestSetFactory.class);
            ITestSetTreeManager objTestSetTreeManager = (itd.testSetTreeManager()).queryInterface(ITestSetTreeManager.class);

           ITestSetFolder objTestSetFolder =(objTestSetTreeManager.nodeByPath(strTestLabPath)).queryInterface(ITestSetFolder.class);

           IList its1 = objTestSetFolder.findTestSets(strTestSetName, true, null);
          //IList ls= objTestSetFolder.findTestSets(strTestSetName, true, null);
          System.out.println("No. of Test Set:" + its1.count());
          ITestSet tst= (ITestSet) objTestSetFolder.findTestSets(strTestSetName, true, null).queryInterface(ITSTest.class);
          System.out.println(tst.name());
          //System.out.println( its1.queryInterface(ITestSet.class).name());

          /* foreach (ITestSet testSet : its1.queryInterface(ITestSet.class)){  
           ITestSetFolder tsFolder = (ITestSetFolder)testSet.TestSetFolder;    
           ITSTestFactory tsTestFactory = (ITSTestFactory)testSet.TSTestFactory;   
           List tsTestList = tsTestFactory.NewList("");
           }*/





          /* Com4jObject comObj = (Com4jObject) its1.item(0);
           ITestSet tst = comObj.queryInterface(ITestSet.class); 
           System.out.println("Test Set Name : " + tst.name());
           System.out.println("Test Set ID : " + tst.id());
           System.out.println("Test Set ID : " + tst.status());
           System.out.println("Test Set ID : " );*/


                System.out.println(its1.count());
           System.out.println("TestSet Present");

           Iterator itr = its1.iterator();
           System.out.println(itr.hasNext());
           while (itr.hasNext())
           {
               Com4jObject  comObj = (Com4jObject) itr.next();
           ITestSet sTestSet = comObj.queryInterface(ITestSet.class);
           System.out.println(sTestSet.name());
           Com4jObject comObj2 = sTestSet.tsTestFactory();
           ITestSetFactory test = comObj2.queryInterface(ITestSetFactory.class);
           }

          // ITSTest tsTest=null;
          // tsTest.
           //its1.
          /* comObj = (Com4jObject) its1.item(1);
           ITSTest tst2=comObj.queryInterface(ITSTest.class);*/
        //  System.out.println( tst2.name());
       /*    foreach (ITSTest tsTest : tst2)
        {
         IRun lastRun = (IRun)tsTest.lastRun();
         if (lastRun == null)
         {
            IRunFactory runFactory = (IRunFactory)tsTest.runFactory;
                        String date = "20160203";
                   IRun run = (IRun)runFactory.addItem( date);
                   run.status("Pass");
                   run.autoPost();
         }

        }*/
                }
        catch(Exception e){

            e.printStackTrace();
        }
    }

}
4

3 回答 3

1

我知道这篇文章很老了。我不得不在使用 Java 的 OTA 中苦苦挣扎,并且无法获得完整的帖子来解决这个问题。经过太多研究,现在我已经运行了代码。所以想到分享我的代码,以防有人寻求帮助。这是完整的解决方案。`

    ITestFactory sTestFactory = (connection.testFactory())
            .queryInterface(ITestFactory.class);
    ITest iTest1 = (sTestFactory.item(12081)).queryInterface(ITest.class);
    System.out.println(iTest1.execDate());
    System.out.println(iTest1.name());

    ITestSetFactory sTestSetFactory = (connection.testSetFactory())
            .queryInterface(ITestSetFactory.class);

    ITestSet sTestSet = (sTestSetFactory.item(1402))
            .queryInterface(ITestSet.class);

    System.out.println(sTestSet.name() + "\n Test Set ID" + sTestSet.id());

    IBaseFactory testFactory1 = sTestSet.tsTestFactory().queryInterface(
            IBaseFactory.class);
    testFactory1.addItem(iTest1);
    System.out.println("Test case has been Added");
    System.out.println(testFactory1.newList("").count());
    IList tsTestlist = testFactory1.newList("");
    ITSTest tsTest;
    for (int tsTestIndex = 1; tsTestIndex <= tsTestlist.count(); tsTestIndex++) {
        Com4jObject comObj = (Com4jObject) tsTestlist.item(tsTestIndex);
        tsTest = comObj.queryInterface(ITSTest.class);

        if (tsTest.name().equalsIgnoreCase("[3]TC_OTA_API_Test")) {
            System.out.println("Hostname" + tsTest.hostName() + "\n"
                    + tsTest.name() + "\n" + tsTest.status());
            IRun lastRun = (IRun) tsTest.lastRun();
            // IRun lastRun = comObjRun.queryInterface(IRun.class);

            // don't update test if it may have been modified by someone
            // else
            if (lastRun == null) {
                System.out.println("I am here last Run = Null");
                runFactory = tsTest.runFactory().queryInterface(
                        IRunFactory.class);
                System.out.println(runFactory.newList("").count());
                String runName = "TestRun_Automated";

                Com4jObject comObjRunForThisTS = runFactory
                        .addItem(runName);
                IRun runObjectForThisTS = comObjRunForThisTS
                        .queryInterface(IRun.class);
                runObjectForThisTS.status("Passed");
                runObjectForThisTS.post();
                runObjectForThisTS.refresh();
            }
        }
    }



`
于 2019-08-29T07:40:21.547 回答
0

如果你使用 c#/vb.net 这很容易完成。但是你正在使用java,我建议在dlls之上提供接口来处理操作。这将比使用 com4j 容易得多。

类似的查询,可能以下可能会对您有所帮助。我建议放弃使用 com4j 的想法,并使用下面线程中提供的解决方案,该解决方案已被证明、故障安全且可自动恢复。

QC API JAR 使用 java 连接

专门为 HPQC/ALM 使用 com4j 一直很困难。由于 QC 的 dll 有问题,并且存在内存泄漏/分配问题,导致某些平台上的 dll 执行频繁崩溃。

于 2016-06-27T09:25:05.747 回答
0

为什么不构建一个客户端来访问 REST API 而不是通过 OTA 接口?

一旦你构建了一个基本的客户端,你就可以很容易地发布运行并更新它们的状态。

于 2016-10-24T15:05:32.497 回答