使用SharedStore的Python实现方法

本文详细介绍了如何在QTPframework中通过SharedStore工具来增强HTMLreporting功能,提供了从初始化到实现的完整Python代码示例,包括如何添加、获取和销毁SharedStore数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

打算在我的QTP framework中的HTML reporting里面加入detailed steps,想到了早期翻译的Tarun的文章中提到的一个工具:Shared Store

由于是COM组件,所以可以在python中实现 (我的HTML reporting也是用python实现的)

以下是具体的代码:

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):
        self.SS = win32com.client.Dispatch("KnowledgeInbox.SharedStore")
        oStore = self.SS.GetStore(self.SSName)
        oDict = oStore.GetItem (self.StoreName)
        return oDict

    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

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()
    

关于SharedStore的下载请见:http://knowledgeinbox.com/downloads/general/shared-store/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值