zoukankan      html  css  js  c++  java
  • HP ALM Open Test Architecture API 介绍

    从事测试工作的同学可能会用过HP ALM(以前叫QC),这是一款基于web的软件测试管理工具,功能非常强大。Test Case Design Test Case Execution Bug Tracking,这些想必大家都非常熟了,还有像Dashboard Management Requirements,这些可能不熟悉的。随着我们对ALM使用的逐渐深入,我们可能会有一些跟ALM相关的Idea,但是通过现有ALM功能不能手动解决,或者解决起来比较麻烦的,怎么办呢?

    接下来我将介绍ALM OTA API,向大家展示如何通过它来实现我们的想法,以抛砖引玉,期待引起有相同需求的同学,共同探讨。

    什么是ALM OTA API?

    如果你正在使用ALM,可以从 Help->Document Library-> 选择HP ALM Open Test Architecture API Reference 去获得。

    里面有详细的API介绍,并且包含丰富的例子。代码是用VB写的,不过我接下来的例子将用C#来诠释,以方便大家参考。

    简而言之,ALM OTA API 就是一个COM库,通过它我们就能用代码来与ALM交互

    口说无凭,有例子才有真相:

    案例一:老板想方便的知道本项目这周跑了多少case,开了多少bug,怎么办?

    分析:我们可以在ALM手动的一点点去查,然后整理成报告,发给老板。但是每次都得查,要是一不小心眼花了,还可能导致统计出错,要是被老板发现了那问题就可大可小了。此时我们想一想,如果我们能做个网站,提供相应的功能,让老板能够随时查询这样岂不很好?!

    网站我们可以选择我们擅长的语言来写,至于如何写,不是本篇文章讨论的重点,我们关心的是如何让我们的网站与ALM通信,以获得数据。

    这里以统计bug为例,上一段小代码为大家参考:

    首先我们要先建立ALM连接:

     1 public static TDConnection ConnectProject(string server, string user, string pass, string domain, string project)
     2         {
     3             TDConnection tdc = new TDConnection();
     4             try
     5             {
     6                 // Connect to ALM
     7                 tdc.InitConnectionEx(server);
     8                 tdc.Login(user, pass);
     9                 tdc.Connect(domain, project);
    10             }
    11             catch (Exception ex)
    12             {
    13                 // Report Exception
    14                 //Report.Failure("Failed to connect ALM! " + "Debug Trace: " + ex.ToString());
    15                 Console.WriteLine("Failed to connect to ALM! " + "Debug Trace: " + ex.Message.ToString());
    16             }
    17             return tdc;
    18         }

    然后我们就可以通过ALM全局连接tdc, 去获得bug的List集合。

            public int GetBugCount()
            {
                BugFactory bugFac = null;
                TDFilter bugFilter = null;
                TDAPIOLELib.List lst = null;
    
                bugFac = tdc.BugFactory;
                bugFilter = bugFac.Filter;
    
                //这里设置我们期望的条件
                //比如,期望统计是new或者open的bug,并且severity大于等于3
                bugFilter["BG_STATUS"] = "New Or Open";
                bugFilter["BG_SEVERITY"] = ">=3";
    
                //此时就可以获得我们期望的bug List了
                lst = bugFac.NewList(bugFilter.Text);
    
                //有了这个bug List,我们就可以遍历每个bug,做我们期望做的事情,当然也可以直接返回bug数量
                return lst.Count;
    
            }

    如果需要,我们甚至可以把每个bug的具体情况在网站上都罗列起来,相信用户体验一定比去ALM亲自去看要好。

    总之老板满意了,我们才踏实嘛。

    案例二:假设我们使用了一款自动化工具,写了一些自动化的case,这些case都会映射到ALM里的Manual case。于是我们就想,当我们跑完自动化的case时候,ALM里面的Manual Case也能根据我们自动化case跑的结果,去相应的改变状态,这样就不用我们手动去ALM更改这些Manual Case的状态,岂不很好?

    分析:有了ALM OTA API,这些都能实现。

            /// <summary>
            /// 
            /// </summary>
            /// <param name="tsName">Test Set Name</param>
            /// <param name="tcName">Test Instance Name</param>
            /// <param name="status">The status of test instance</param>
            /// <param name="path">Path to target the Test Set</param>
            internal static void ModifyTestInstanceStatus(string tsName, string tcName, string status, string path)
            {
                TestSet ts = null;
                TSTest tc = null;          
                TDFilter aFilter = null;
                TestSetFolder tsFolder = null;
                TSTestFactory tcFactory = null;            
                TestSetTreeManager tsTreeMgr = null;      
                TDAPIOLELib.List lst = null;
    
                // Create the connectuon to ALM
                TDConnection tdc = ALMUtility.getTDCInstance();
    
                tsTreeMgr = tdc.TestSetTreeManager;
                tsFolder = tsTreeMgr.get_NodeByPath(path);
    
                // Find the Test Set
                lst = tsFolder.FindTestSets(tsName);
    
                // There should be only one Test Set 
                if (lst.Count != 1)
                {
                    // Report Failure and Exit
                    Console.WriteLine("Failed to find the specific Test Set!");
                    return;
                }
                ts = lst[1];
    
                // Find the specific test in the Test Set
                tcFactory = ts.TSTestFactory;
                aFilter = tcFactory.Filter;
                aFilter["TS_NAME"] = tcName;
                lst = tcFactory.NewList(aFilter.Text);
    
                //There should be only one Test Instance
                if (lst.Count != 1)
                {
                    // Report Error
                    Console.WriteLine("Failed to find the specific Test Instance");
                    return;
                }
                tc = lst[1];
                tc.Status = status;
                tc.Post();
                Console.WriteLine("Update test case successfully!");
            }

    有了上面的方法,我们只要传入相应的参数,就可以实现自动改变test case状态了。

    总结:

    上面两个案例,是ALM OTA API 比较简单的使用,意在为大家发散思维,开拓思想。也许在实际工作中,可能会遇到有更好的案例,期待能共同讨论。

  • 相关阅读:
    ping 的零碎知识
    dhcp问题
    Apache相关知识与配置
    Android || IOS录制mp3语音文件方法
    Sheet can not be presented because the view is not in a window的解决办法,和window的简单使用
    测试题1 IOS面试基础题
    IOS 封装类的时候注释格式,使用的时候可以想官方库一样快捷显示
    IOS 用正则表达式解析HTML等文件,得到所有文本
    IOS源码封装成.bundle和.a文件时,使用单例作为出口的写法!任何封装都建议使用这种方法作为出口
    XMLParser解析xml--内容源自网络(在静态库中不能用GDATA来解析,因为静态库不能加动态库)
  • 原文地址:https://www.cnblogs.com/jinsdu/p/2718697.html
Copyright © 2011-2022 走看看