ALM提供了OTA接口,可以用来获取和上传测试数据到ALM。比如获取Test case的step信息。上传测试结果到test instance。

在ALM的Help中可以下载相关文档,这里以ALM11为例。可以下载alm_project_db.chm和OTA_API_Reference.chm。一个是数据库字段的介绍,一个是OTA API的介绍。通过参照这两个帮助文档就可以开发与ALM交互的脚本了。

一. 首先是怎么查看文档:

打开alm_project_db.chm,展开Project Data Tables,可以找到所有数据库字段的介绍。

打开OTA_API_Reference.chm,展开Objects,可以看到所有可以调用的Object

二. 配置准备环境

要通过OTA接口与ALM交互,就需要安装TDConnect.exe,这个可以从ALM的plug-ins页面下载安装。

其次不同的脚本语言还需要对应的方法库来与OTA接口交互,例如python需要安装pywin32的库。这个需要x86的python版本以及x86的pywin32版本。

三. 建立与ALM的连接

import win32com.client

url="http://alm.com/qcbin"
username="xxx.xxx"
password="Pass123word"
domain="DemoDomain"
project="DemoProject" testData={} # Store the data td = win32com.client.Dispatch("TDApiOle80.TDConnection")
td.InitConnection(url)
td.Login(username, password)
td.Connect(domain, project)
# td.ConnectProjectEx(usrname, password, domain, project) # same results with td.Login + td.Connect

通过pywin32的方法win32com.client.Dispatch建立与OTA通信的通道。初始化与服务器的连接,用有效的认证登录Project。

这里对于各个方法或属性的使用,可以参照OTA API文档中对TDConnection Object的介绍。

四. 从Test Plan中的test case中读取每个步骤的信息

要先找到case所在路径,获取实例,再找到test的实例,再得到step的实例,再得到具体的step数据信息。

# 首先需要与ALM建立连接,代码见上

pathToTestcase = "Subject\\path\\to\\test\\case"     # The path to test case in Test Plan
mg=td.TreeManager # The Test subject tree manager
npath=pathToTestcase
print npath
tsFolder = mg.NodeByPath(npath) # Gets the node at the specified tree path.
testFactory = tsFolder.TestFactory # Get a TestFactory object
testFilter = testFactory.Filter # The TDFilter object for the factory
testFilter["TS_NAME"] = TestCaseName # Get a test by name in a folder
testList = testFactory.NewList(testFilter.Text) # Creates a list of objects according to the specified filter.
test = testList.Item(1) # There should be only 1 item, The list index is 1-based.
print test.Name # The test name
stepFactory = test.DesignStepFactory # The design steps factory for the current test.
stepList = stepFactory.NewList("") # Creates a list of objects according to the specified filter, an empty string is passed, the returned list contains all the child items of the current factory object.
print("Total Steps : "+str(len(stepList))) # Get the count of the test steps.
print stepList.Item(1).Field("DS_USER_02") # Get the custom filed value of step 1, DS_USER_02 is data filed in ALM database.
print stepList.Item(1).Field("DS_USER_03")
print stepList.Item(1).Field("DS_USER_04")
print stepList.Item(1).Field("DS_USER_01") for step in stepList:
stepN = step.StepName.strip() # Get the step name
testDatas= step.Field("DS_USER_03").split(",")
if(len(testDatas)>1):
for data in testDatas:
d=data.split(":")
if(len(d)>1):
testData.setdefault(stepN,{})[d[0]]=d[1]
elif(len(testDatas)==1):
d1=testDatas[0].split(":")
if(len(d1)>1):
testData.setdefault(stepN,{})[d1[0]]=d1[1]
else:
testData[stepN]=testDatas[0]
print testData
s=td.logout # Terminates the user's session on this TDConnection
print(str(s))

五. 上传测试结果到Test Lab中

将测试结果上传到test lab,修改每一步的实际值,状态和上传附件。

# 首先需要与ALM建立连接,代码见上

nodePath="Root\PI_Rampup"                                         # The path to test set in Test Lab
testSetName="sprint1" # Test Set Name
TestCaseNameInTestLab='TestCaseName' # Test case (Test instance) name in Test Set
ResultSet={1: u'Attached to Application||Passed', 2: u'The items in home page should have same font, contents, location, size and colors||Passed||C:\\Home.png', 3: u'The dropdown message should show at same location with same font, contents, size and color||Passed', 4: u'The dropdown message should show at same location with same font, contents, size and color||Passed', 5: u'The dropdown message should show at same location with same font, contents, size and color||Passed'}
# Test results for each step
finalTestCaseStatus=''
tsFolder = td.TestSetTreeManager.NodeByPath(nodePath) # Manages the test set tree and its related test set folders, Gets the test set tree node from the specified tree path.
tsList = tsFolder.FindTestSets(testSetName) # Gets the list of test sets contained in the folder that match the specified pattern
ts_object = tsList.Item(1) # There should be only one item, The list index is 1-based. print "Path: "+nodePath
print ts_object.Name
TSTestFact = ts_object.TSTestFactory # Manages test instances (TSTest objects) in a test set
TestSetTestsList = TSTestFact.NewList("") # Creates a list of objects according to the specified filter. an empty string is passed, the returned list contains all the child items of the current factory object
print len(TestSetTestsList) # The count of test instances in test set
counter=0
for testSet in TestSetTestsList: # Go through each test instances
counter=counter+1
if(testSet.Name == "[1]"+TestCaseNameInTestLab): # Find the expected test instance
ts_instance = testSet
newItem = ts_instance.LastRun # The Run object of the last run.
#print("LastRun Name: "+newItem.Name)
try:
newItem.Name # The run name.
time=datetime.datetime.now().strftime("%B %d, %Y")
newItem.Name = TestCaseName+' '+time # Define new name of last run
newItem.Post()
except:
newItem = ts_instance.RunFactory.AddItem(None) # The Run Factory for this test instance. Creates a new item object. Creating a virtual Run object with Null ensures that you cannot then Post until the run name and all other required fields are initialized
time=datetime.datetime.now().strftime("%B %d, %Y")
newItem.Name = TestCaseNameInTestLab+' '+time # Define the run name
print(newItem.Name)
newItem.Post() # Posts all changed values into database.
newItem.CopyDesignSteps() # Copies design steps into the test run of an executed test
newItem.Post() # Posts all changed values into database.
steps = newItem.StepFactory.NewList("") # Services for managing test steps for a Run object. Creates a list of objects according to the specified filter.
stepCount = len(steps) # The count of steps.
KeyCounter=0
FailCounter=0
keys=ResultSet.keys()
for key in keys:
KeyCounter=KeyCounter+1
print "Step Name:"+steps[key-1].Name
res=ResultSet[key].split('||')
print "Statement: "+res[0]
print "Status: "+res[1]
if(len(res)==3): # if there is attachment need to be uploaded. the len would be 3.
# tsFolder for test set folder attachment, ts_object for test set attachment, ts_instance for test instanse attachment.
# steps[key-1] for test step attachment
attachmentFactory = steps[key-1].Attachments # the list of step object is 0-based.
attachment=attachmentFactory.AddItem(None) # Passing NULL as the ItemData argument creates a virtual object, one that does not appear in the project database. After creating the item, use the relevant object properties to fill the object, then use the Post method to save the object in the database
steps[key-1].Status=res[1] # The run step status. Passed or Failed
steps[key-1].SetField("ST_ACTUAL", res[0]) # Update the value of Actual
attachment.Filename = res[2] # If a file, the file location. If a virtual file, the location for the attachment before it is uploaded to the server. If a URL, the link address.
attachment.Description = "" # The attachment description
attachment.Type=1 # The attachment type. Either File or URL. 1 is for File, 2 is for URL.
attachment.Post()
steps[key-1].post()
elif(len(res)==2):
steps[key-1].Status=res[1]
steps[key-1].SetField("ST_ACTUAL", res[0])
steps[key-1].post()
if(res[1]=='Failed'):
FailCounter=FailCounter+1
print("For Step"+steps[key-1].Name+" Test Step Status is: "+res[1])
finalTestCaseStatus=res[1]
elif(len(steps)==KeyCounter and FailCounter==0 ):
finalTestCaseStatus="Passed"
newItem.Status = finalTestCaseStatus # The run status
newItem.Post()
print("ALM Update for Test Case: "+TestCaseNameInTestLab+" has been successfully updated in TestSet "+testSetName)
break
elif(len(TestSetTestsList)==counter):
print("Test Case: "+TestCaseNameInTestLab+" Not Found in Test Set "+testSetName)
e=sys.exc_info()
s=td.logout
print(str(s))

通过ALM OTA API获取test case的信息,并上传测试结果到test set中的更多相关文章

  1. 如何将RobotFramework中case的执行结果上传到TestLink中。

    公司的需求是: 用RobotFrameworjk框架执行case,用Testlink管理case和测试任务.需要持续统计每个版本的测试结果. 我觉得用Jenkins+Robot也行,Testlink+ ...

  2. 初识html5 File API实现带有进度提示的文件上传

    Html5终于解决了上传文件的同时显示文件上传进度的老问题.现在大部分的网站用Flash去实现这一功能,还有一些网站继续采用Html <form>with enctype=multipar ...

  3. 淘宝(新浪)API获取IP地址位置信息

    package com.parse; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IO ...

  4. 调用手机在线API获取手机号码归属地信息

    手机在线(www.showji.com)始创于2001年,发展至今已拥有国内最准确.号段容量最大的手机号码归属地数据库系统, 目前号段容量将近33万条,每月保持两次以上规模数据更新,合作伙伴包括:百度 ...

  5. C++ 通过WIN32 API 获取逻辑磁盘详细信息

    众所周知,在微软的操作系统下编写应用程序,最主要的还是通过windows所提供的api函数来实现各种操作的,这些函数通常是可以直接使用的,只要包含windows.h这个头文件, 下载源文件 今天我们主 ...

  6. C++通过WIN32 API获取逻辑磁盘详细信息

      众所周知,在微软的操作系统下编写应用程序,最主要的还是通过windows所提供的api函数来实现各种操作的,这些函数通常是可以直接使用的,只要包含windows.h这个头文件. 今天我们主要介绍的 ...

  7. Python 操作Zabbix API 获取ERROR级别告警信息并打印

    1.需求:有一个语音合成播报项目,要实时获取zabbix的ERROR级别以上告警信息,将该信息合成语音播报出去.(合成语音及播报已经完成) 2.现实:整理zabbix告警级别,将不太重要的告警放到ER ...

  8. 使用pcs api往免费的百度网盘上传下载文件

    百度个人云盘空间大,完全免费,而且提供了pcs api供调用操作文件,在平时的项目里往里面保存一些文件是很实用的. 环境准备: 开通读写网盘的权限及获取access_token:http://blog ...

  9. 安卓获取软硬件信息并上传给server(Socket实现)

    首先,项目结构如图--A:分为client部分CheckInfo和server端CheckInfo_Server.CheckInfo获取手机信息(Mac,Cpu,内存,已安装软件信息等)并上传到ser ...

随机推荐

  1. CAP原理、一致性模型、BASE理论和ACID特性

    CAP原理 在理论计算机科学中,CAP定理(CAP theorem),又被称作布鲁尔定理(Brewer's theorem),它指出对于一个分布式计算系统来说,不可能同时满足以下三点: 一致性(Con ...

  2. spark 2.1.0 集群安装

    jdk安装 http://www.cnblogs.com/xiaojf/p/6568426.html scala2.11 安装 http://www.cnblogs.com/xiaojf/p/6568 ...

  3. java基础之数组常用操作

    常用的对数组进行的操作 1.求数组中最大值,最小值 思路:假设下标为0的元素是最大值,遍历数组,依次跟max进行比较,如果有元素比这个max还大,则把这个值赋给max.最小值同样 public cla ...

  4. 微信小程序开发《二》:http请求的session管理

    作为一个开发JavaWeb应用的程序猿,都喜欢将用户登录后的用户信息(比如说用户id,用户名称)放入session中保存,之后在业务逻辑的开发中需要用到用户信息的时候就可以轻松又方便的从session ...

  5. js 排序:sort()方法、冒泡排序、二分法排序。

    js中的排序,这里介绍三种,sort()方法.冒泡排序.二分法排序. 1.sort方法 写法:  数组.sort(); 返回排好序的数组,如果数组里是数字,则由小到大,如果是字符串,就按照第一个字符的 ...

  6. java(5)循坏结构

    一. while循环 1.循环的优点? 减少重复代码的编写:程序会更加的简洁 2.语法 while(表达式){ // 1.表达式是[循环条件],结果必须是boolean类型 //2.{}中的代码,即[ ...

  7. javacpp-opencv图像处理3:使用opencv原生方法遍历摄像头设备及调用(增加实时帧率计算方法)

    javaCV图像处理系列: javaCV图像处理之1:实时视频添加文字水印并截取视频图像保存成图片,实现文字水印的字体.位置.大小.粗度.翻转.平滑等操作 javaCV图像处理之2:实时视频添加图片水 ...

  8. ubuntu下配置Apache+mod_wsgi+Django项目(个人测试)

    经过了一个星期的摸索,查找资料以及实验,我搭建的环境基本能用(还有就是Django后台的静态文件加载的问题) 这里面只是介绍一下我的过程,因为对应Apache还不是很熟练,特别是配置文件.只能供大家参 ...

  9. js事件循环

    之前有看过一些事件循环的博客,不过一阵子没看就发现自己忘光了,所以决定来自己写一个博客总结下! 首先,我们来解释下事件循环是个什么东西: 就我们所知,浏览器的js是单线程的,也就是说,在同一时刻,最多 ...

  10. orcle :Could not initialize "D:\app\Administrator\product\11.2.0\dbhome_1\bin\oci.dll" Make sure you have the 32 bits Oracle Client installed.

    服务器重启后,数据库登录信息为空 错误信息: ---------------------------(Not logged on) - PL/SQL Developer---------------- ...