2016-05-20 124 views
0

我正在尋找UFT和TFS集成(從TFS運行測試,就像我們用HPQC那樣) 我在google上搜索但沒有任何幫助。如果有人知道如何做到這一點,請讓我知道步驟。UFT 12.02 QTP與TFS集成

感謝

回答

0
+0

嗨, 感謝您的回覆,但是這個博客帖子HP ALM和TFS集成解釋但我需要TFS和QTP集成。 –

+0

嗨,從TFS觸發UFT測試並將運行結果返回到TFS,由OpsHub集成管理器支持。 –

0

看看這個代碼:

進口QTObjectModelLib DLL從C:\ Program Files文件(x86)的\ HP \統一功能測試\ BIN位置,您的解決方案。

public void Fn_QTP() 
{ 
qtApp.Launch(); 
qtApp.Visible = true; 
qtApp.Options.Run.RunMode = "Fast"; 
qtApp.Options.Run.StepExecutionDelay = 0; 
qtApp.Options.Run.ViewResults = false; 
qtApp.Test.Settings.Run.OnError = "Stop"; 
//iterate for all test cases under selected module 
// oTestSuiteDict : this dictionary conatins all the testsuites from TFS which meant to be executed. 
//keys have their ID's 
foreach (var item in oTestSuiteDict.Keys) 
{ 
    foreach (var TestCase in oTestSuiteDict[item].Keys) 
    { 
     Console.WriteLine("Executing TestCase : {0}", TestCase); 
     //update the XML file and upload in QTP 
     //this XML file is used to provide the data to QTP as a environment variables. 
     Fn_UpdateXMLFile(item, TestCase); 

     //Open the test Case 
     string scriptPath = @"path of script that will be opened in QTP (Action)"; 
     qtApp.Open(scriptPath, true, false); 
     // Get a reference to the test object 
     qtTest = qtApp.Test; // Get reference to test object opened/created by application 
     qtTest.Settings.Run.OnError = "NextStep"; 
     //check if the library is already associated. 
     if (qtTest.Settings.Resources.Libraries.Find(@"library path") == 1) 
     { 
      qtTest.Settings.Resources.Libraries.RemoveAll(); 
     } 
     qtTest.Settings.Resources.Libraries.Add(@"Library Path"); 
     //Console.WriteLine("Library is associated with Test"); 

     // Get a reference to the Results Object for test results location 
     QTObjectModelLib.RunResultsOptions qtRRO = new QTObjectModelLib.RunResultsOptions(); 

     // Run the test 
     //creates and start the instance of Stopwatch just to track the time period of testcase execution. 
     Stopwatch stopwatch = Stopwatch.StartNew(); 
     qtTest.Run(qtRRO, true, null); // run the test 
     stopwatch.Stop(); 
     string oTime = stopwatch.Elapsed.ToString(); 
     oTestCaseTime.Add(TestCase, oTime); 
     string ostatus = qtTest.LastRunResults.Status; 
     oResults.Add(TestCase, ostatus); 
     qtTest.Close(); // Close the test 
    } 
} 

System.Runtime.InteropServices.Marshal.FinalReleaseComObject(qtTest); // Cleanly release COM object 
qtTest = null; // set object to null 
//break; 
//qtApp.Quit(); // Quit QTP 
GC.Collect(); // Garbage collect 
GC.WaitForPendingFinalizers(); // Wait for GC 
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(qtApp); // Cleanly release COM Object 
qtApp = null; // set to null 
} 

// Fn_UpdateXMLFile:功能更新環境變量QTP //模塊名稱:測試套件名(包含測試用例的列表); testcasename:在MODULENAME上市測試用例(測試套件)XML文件的

public void Fn_UpdateXMLFile(string modulename,string testcasename) 
{ 
    string oPath = @"path of xml file"; 
    XmlDocument xmlDoc = new XmlDocument(); 
    xmlDoc.Load(oPath); 
    XmlNodeList nodes = xmlDoc.SelectNodes("Environment/Variable/Value"); 
    nodes[0].InnerText = modulename; 
    nodes[1].InnerText = testcasename; 
    xmlDoc.Save(oPath); 
} 

//格式:

<Environment> 
    <Variable> 
    <Name>ModuleName</Name> 
    <Value>ToolsMenu</Value> 
    </Variable> 
    <Variable> 
    <Name>""</Name> 
    <Value>""</Value> 
    </Variable> 
</Environment>