使用SharedStore的Python实现方法
本帖最后由 yuandjing 于 2011-12-28 16:47 编辑这几天米国人过圣诞去了,闲着无聊打算在我的QTP framework中的HTML reporting里面在截屏(screenshot)旁边加入detailed steps link(目前的repoting system会把fail或waring的test case截取屏幕)
好处就是一旦有fail或者warning
1. BA可以根据提示的steps自己去重现,为automation team 省事
2. Automation team在分析错误的时候只需要照着这个steps去重现即可,节省大量时间
关于实现方法,想到了早期翻译的Tarun的文章中提到的一个工具:Shared Store
Shared Store 的早期翻译文档也垦出来了,见附件,供免费下载
由于是COM组件,所以可以在python中实现 (我的HTML reporting也是用python实现的:lol)
以下是具体的代码,供有同样想法的同行参考:
import win32com.client
class SharedStore():
def __init__(self):
self.SSName = 'HTMLReporting'
self.StoreName = 'HTMLReporting'
self.SS = win32com.client.Dispatch("KnowledgeInbox.SharedStore")
def SharedStore_add(self, contents):
if self.SS.Exists(self.SSName):
oStore = self.SS.GetStore(self.SSName)
else:
oStore = self.SS.AddStore(self.SSName)
li = []
if oStore.Exists(self.StoreName):
tempTuple = oStore.GetItem(self.StoreName)
for tu in tempTuple:
if '' != tu:
li.append(tu)
li.append(contents)
oStore.SetItem (self.StoreName, li)
else:
li.append(contents)
oStore.AddItem (self.StoreName, li)
self.SS.PersistInMemory = True
def SharedStore_Get(self):
oStore = self.SS.GetStore(self.SSName)
oDict = oStore.GetItem (self.StoreName)
return oDict
def SharedStore_Kill(self):
if self.SS.Exists(self.SSName):
oStore = self.SS.GetStore(self.SSName)
oStore.RemoveAll
oStore.SetItem(self.StoreName, '')
self.SS.PersistInMemory = False
if __name__ == '__main__':
test = SharedStore()
test.SharedStore_add('hello1')
test.SharedStore_add('hello2')
test.SharedStore_add('hello3')
test.SharedStore_add('hello4')
test.SharedStore_add('hello5')
print test.SharedStore_Get()
test.SharedStore_Kill()
test.SharedStore_add('hello1')
print test.SharedStore_Get()
以上是基本调用,后来为了自己的框架需要,改成了:
import win32com.client
class SharedStore():
def __init__(self):
self.SSName = 'HTMLReporting'
self.StoreName = 'HTMLReporting'
self.StoreNameTC = 'TC'
self.SS = win32com.client.Dispatch("KnowledgeInbox.SharedStore")
def __addTC(self, contents):
if self.SS.Exists(self.SSName):
oStore = self.SS.GetStore(self.SSName)
else:
oStore = self.SS.AddStore(self.SSName)
if oStore.Exists(self.StoreNameTC):
oStore.SetItem (self.StoreNameTC, contents)
else:
oStore.AddItem (self.StoreNameTC, contents)
self.SS.PersistInMemory = True
def __getTC(self):
try:
oStore = self.SS.GetStore(self.SSName)
oDict = oStore.GetItem (self.StoreNameTC)
return oDict
except:
return ''
def SharedStore_add(self, TCName, actionName, contents, passFail):
# add TC
if '' == self.__getTC():
self.__addTC(TCName)
else:
if self.__getTC() != TCName:
self.SharedStore_Kill()
self.__addTC(TCName)
if self.SS.Exists(self.SSName):
oStore = self.SS.GetStore(self.SSName)
else:
oStore = self.SS.AddStore(self.SSName)
li = []
if oStore.Exists(self.StoreName):
tempTuple = oStore.GetItem(self.StoreName)
for tu in tempTuple:
if '' != tu:
li.append(tu)
li.append(actionName + '@@@' + contents + '@@@' + passFail)
oStore.SetItem (self.StoreName, li)
else:
li.append(actionName + '@@@' + contents + '@@@' + passFail)
oStore.AddItem (self.StoreName, li)
self.SS.PersistInMemory = True
def SharedStore_Get(self):
self.SS = win32com.client.Dispatch("KnowledgeInbox.SharedStore")
oStore = self.SS.GetStore(self.SSName)
oDict = oStore.GetItem (self.StoreName)
ret = []
currentAction = ''
stepNumber = 1
for i in range (len(oDict)):
record = oDict
tempRecord = record.split('@@@')
tempContent = tempRecord.split('\n')
for j in range (len(tempContent)):
if currentAction != tempRecord:
currentAction = tempRecord
ret.append(currentAction+': \n')
insertion = str(stepNumber) + '. '+space(4) + tempContent + ' -'+tempRecord + '\n'
ret.append(insertion)
stepNumber = stepNumber + 1
ret.append('@@@\n')
return ret
def SharedStore_Kill(self):
self.SS = win32com.client.Dispatch("KnowledgeInbox.SharedStore")
if self.SS.Exists(self.SSName):
oStore = self.SS.GetStore(self.SSName)
oStore.RemoveAll
oStore.SetItem(self.StoreName, '')
self.SS.PersistInMemory = False
http://blog.csdn.net/quicktest/article/details/7105748
围脖:http://weibo.com/quicktest 二楼诚征广告位:victory: good job!!
页:
[1]