2012-09-26 40 views
0

我們使用Mercury Quality Center 9進行存儲測試和測試結果。
我需要從測試數據讀取測試計劃並將測試結果寫入測試實驗室通過java
我試圖找到關於谷歌,但我還沒有找到任何東西。從Mercury Quality center 9通過java讀取測試數據

UPDATE:

我試圖用qctools4j與MQC 9個工作用下面的代碼:

public void connect() { 
try{ 
    IQcConnection conn = QcConnectionFactory.createConnection("http://qc/qcbin");       
    conn.connect("login", "password", "DEFAULT","project");       
    TestClient tc = conn.getTestClient(); 
    System.out.println("Connection success!!!"); 
} 
catch (QcException e) { 
    System.out.println(e.getMessage()); 
    e.printStackTrace(); 
} 
} 

我得到了以下異常消息:

*org.qctools4j.exception.QcException: Can't co-create object 
    at org.qctools4j.clients.QcConnectionImpl.initConnection(Unknown Source) 
    at org.qctools4j.clients.QcConnectionImpl.<init>(Unknown Source) 
    at org.qctools4j.QcConnectionFactory.createConnection(Unknown Source) 
    at automation_framework1.automation_framework1.QCWorker.connect1(QCWorker.java:38) 
    at automation_framework1.automation_framework1.Main.main(Main.java:12) 
Caused by: com.jacob.com.ComFailException: Can't co-create object 
    at com.jacob.com.Dispatch.createInstanceNative(Native Method) 
    at com.jacob.com.Dispatch.<init>(Dispatch.java:99) 
    at com.jacob.activeX.ActiveXComponent.<init>(ActiveXComponent.java:58) 
    at org.qctools4j.clients.QcConnectionImpl.initConnection(Unknown Source)* 

什麼時我做錯了?

+0

關於你得到的異常,就這個一看:http://netheadaches.wordpress.com/2012/04/22/jacob-cant-co-create-object/ – aviad

+0

根據qctools4j,你有什麼版本的QC,它與9.2兼容,而不是9.0。 –

+0

9.0。現在我試圖使用groovy scriptiom –

回答

1

我參與開發QC 9,我不確定是否有Java API。但是,有一個COM接口或OTA API。你可以使用一些庫來幫助從Java調用COM API。

例如:

  1. Jacob它是開源和here是一些例子。
  2. Nevaobject - 它是商業但更穩定。

祝你好運!

編輯:

剛看到qctools4j(它是基於雅各布) - 從來沒有嘗試過。

0

我發現如何解決這個問題。我用常規scriptom用下面的代碼(可能是它會幫助別人):

def tdc; 
public QualityCenterController(){ 
static{ 
System.load("C:\\WINDOWS\\system32\\OTAClient.dll"); 
System.load("D:\\Work\\automation_framework\\libs\\lib\\jacob-1.16-M2-x86.dll"); 
} 

public void connect(){ 
    tdc = new ActiveXObject ("TDApiOle80.TDConnection"); 
    tdc.InitConnectionEx("http://qc/qcbin"); 
    tdc.Login("username", "password"); 
    tdc.Connect("DEFAULT","PROJECT"); 
    System.out.println("login is success"); 
} 

//ReqFactory Object 
public void getRequirements(){ 
    def requironmetns = tdc.ReqFactory(); 
    def listReq = requironmetns.NewList(""); 
    for (def iterReq : listReq) { 
     getRequirement(iterReq); 
    } 
    println listReq.count(); 
} 

//Req Object 
public void getRequirement(def itemReq){ 
    println 'ID: '+itemReq.ID(); 
    println 'Name:' + itemReq.Name(); 
    println 'Path:' + itemReq.Path(); 
    println 'Reviewed:' + itemReq.Reviewed(); 

    println 'Author:' + itemReq.Author(); 
    println 'Priority: ' + itemReq.Priority(); 
    println 'Comment: '+removeHtmlTag(itemReq.Comment()); 
    println 'Type: ' + itemReq.Type(); 



} 
public Test getTestsFromTestLab(String path){ 

    Test resultTest = new Test(); 
    def labFolder = tdc.TestSetTreeManager.NodeByPath(path); 
    def tsList = labFolder.FindTestInstances(""); 

    for (def iterable_element : tsList){ 

     Test test = getTestData(iterable_element); 
     def steps = iterable_element.Test().DesignStepFactory(); 
     TestStep testStep = getTest(steps); 
    } 
    return resultTest; 
} 

public TestStep getTest(def testData){ 
    TestStep testStep = new TestStep(); 
    def listSteps = testData.NewList(""); 
    for(def item1 : listSteps){ 
     testStep = getTestStepData(item1); 
     showTestStep(testStep); 
    } 
    return testStep; 
} 

private TestStep getTestStepData(def stepData){ 
    TestStep testStep = new TestStep(); 
    testStep.setId(stepData.ID()); 
    testStep.setName(stepData.StepName()); 
    testStep.setDescription(removeHtmlTag(stepData.StepDescription())); 
    testStep.setExpected(removeHtmlTag(stepData.StepExpectedResult())); 
    testStep.setStepOrder(stepData.Order()); 
    return testStep; 
} 

public Test getTestData(def testData){ 
    Test test = new Test(); 
    test.setId(Integer.parseInt(testData.Id())); 
    test.setName(testData.Name()); 
    test.setExecStatus(testData.Status()); 
    showTest(test); 
    return test; 
} 

private String removeHtmlTag(String html){ 
    String result = ""; 
    result = Jsoup.parse(html).text(); 
    return result; 
} 

public void showTestStep(TestStep testStep){ 
    println testStep.getId(); 
    println testStep.getName(); 
    println testStep.getDescription(); 
    println testStep.getExpected(); 
    println testStep.getStepOrder(); 
} 
public void showTest(Test test){ 
    println test.getId(); 
    println test.getName(); 
    println test.getExecStatus(); 
} 
相關問題