51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1519|回复: 2
打印 上一主题 下一主题

[原创] 使用SharedStore的Python实现方法

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2011-12-28 16:40:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 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实现的

以下是具体的代码,供有同样想法的同行参考:

  1. import win32com.client  
  2.   
  3. class SharedStore():  
  4.   
  5.     def __init__(self):  
  6.         self.SSName = 'HTMLReporting'  
  7.         self.StoreName = 'HTMLReporting'  
  8.         self.SS = win32com.client.Dispatch("KnowledgeInbox.SharedStore")  
  9.       
  10.     def SharedStore_add(self, contents):  
  11.         if self.SS.Exists(self.SSName):  
  12.             oStore = self.SS.GetStore(self.SSName)  
  13.         else:  
  14.             oStore = self.SS.AddStore(self.SSName)  
  15.         li = []  
  16.         if oStore.Exists(self.StoreName):  
  17.             tempTuple = oStore.GetItem(self.StoreName)  
  18.             for tu in tempTuple:  
  19.                 if '' != tu:  
  20.                     li.append(tu)  
  21.             li.append(contents)  
  22.             oStore.SetItem (self.StoreName, li)  
  23.         else:  
  24.             li.append(contents)  
  25.             oStore.AddItem (self.StoreName, li)  
  26.   
  27.         self.SS.PersistInMemory = True  
  28.   
  29.     def SharedStore_Get(self):  
  30.         oStore = self.SS.GetStore(self.SSName)  
  31.         oDict = oStore.GetItem (self.StoreName)  
  32.         return oDict  
  33.   
  34.     def SharedStore_Kill(self):  
  35.         if self.SS.Exists(self.SSName):  
  36.             oStore = self.SS.GetStore(self.SSName)  
  37.             oStore.RemoveAll  
  38.             oStore.SetItem(self.StoreName, '')  
  39.         self.SS.PersistInMemory = False  
  40.   
  41. if __name__ == '__main__':  
  42.     test = SharedStore()  
  43.     test.SharedStore_add('hello1')  
  44.     test.SharedStore_add('hello2')  
  45.     test.SharedStore_add('hello3')  
  46.     test.SharedStore_add('hello4')  
  47.     test.SharedStore_add('hello5')  
  48.     print test.SharedStore_Get()  
  49.     test.SharedStore_Kill()  
  50.     test.SharedStore_add('hello1')  
  51.     print test.SharedStore_Get()  
复制代码
以上是基本调用,后来为了自己的框架需要,改成了:

  1. import win32com.client
  2. class SharedStore():

  3.     def __init__(self):
  4.         self.SSName = 'HTMLReporting'
  5.         self.StoreName = 'HTMLReporting'
  6.         self.StoreNameTC = 'TC'
  7.         self.SS = win32com.client.Dispatch("KnowledgeInbox.SharedStore")
  8.         
  9.     def __addTC(self, contents):
  10.         if self.SS.Exists(self.SSName):  
  11.             oStore = self.SS.GetStore(self.SSName)  
  12.         else:  
  13.             oStore = self.SS.AddStore(self.SSName)  
  14.         if oStore.Exists(self.StoreNameTC):  
  15.             oStore.SetItem (self.StoreNameTC, contents)  
  16.         else:   
  17.             oStore.AddItem (self.StoreNameTC, contents)  
  18.         self.SS.PersistInMemory = True

  19.     def __getTC(self):  
  20.         try:
  21.             oStore = self.SS.GetStore(self.SSName)
  22.             oDict = oStore.GetItem (self.StoreNameTC)
  23.             return oDict
  24.         except:
  25.             return ''
  26.         
  27.     def SharedStore_add(self, TCName, actionName, contents, passFail):
  28.         # add TC
  29.         if '' == self.__getTC():
  30.             self.__addTC(TCName)
  31.         else:
  32.             if self.__getTC() != TCName:
  33.                 self.SharedStore_Kill()
  34.                 self.__addTC(TCName)
  35.                
  36.         if self.SS.Exists(self.SSName):
  37.             oStore = self.SS.GetStore(self.SSName)
  38.         else:
  39.             oStore = self.SS.AddStore(self.SSName)
  40.         li = []
  41.         if oStore.Exists(self.StoreName):
  42.             tempTuple = oStore.GetItem(self.StoreName)
  43.             for tu in tempTuple:
  44.                 if '' != tu:
  45.                     li.append(tu)
  46.             li.append(actionName + '@@@' + contents + '@@@' + passFail)
  47.             oStore.SetItem (self.StoreName, li)
  48.         else:
  49.             li.append(actionName + '@@@' + contents + '@@@' + passFail)
  50.             oStore.AddItem (self.StoreName, li)

  51.         self.SS.PersistInMemory = True

  52.     def SharedStore_Get(self):
  53.         self.SS = win32com.client.Dispatch("KnowledgeInbox.SharedStore")
  54.         oStore = self.SS.GetStore(self.SSName)
  55.         oDict = oStore.GetItem (self.StoreName)
  56.         ret = []
  57.         currentAction = ''
  58.         stepNumber = 1
  59.         for i in range (len(oDict)):
  60.             record = oDict[i]
  61.             tempRecord = record.split('@@@')
  62.             tempContent = tempRecord[1].split('\n')
  63.             for j in range (len(tempContent)):
  64.                 if currentAction != tempRecord[0]:
  65.                     currentAction = tempRecord[0]
  66.                     ret.append(currentAction+': \n')
  67.                 insertion = str(stepNumber) + '. '+space(4) + tempContent[j] + ' -'+tempRecord[2] + '\n'
  68.                 ret.append(insertion)
  69.                 stepNumber = stepNumber + 1
  70.                
  71.         ret.append('@@@\n')
  72.         return ret

  73.     def SharedStore_Kill(self):
  74.         self.SS = win32com.client.Dispatch("KnowledgeInbox.SharedStore")
  75.         if self.SS.Exists(self.SSName):
  76.             oStore = self.SS.GetStore(self.SSName)
  77.             oStore.RemoveAll
  78.             oStore.SetItem(self.StoreName, '')
  79.         self.SS.PersistInMemory = False
复制代码
http://blog.csdn.net/quicktest/article/details/7105748
围脖:http://weibo.com/quicktest

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?(注-册)加入51Testing

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
 楼主| 发表于 2011-12-28 16:48:20 | 只看该作者
二楼诚征广告位
回复 支持 反对

使用道具 举报

该用户从未签到

3#
发表于 2011-12-29 17:03:50 | 只看该作者
good job!!
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-5-9 08:33 , Processed in 0.073297 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表