ImportSheet in QTP Data Table from QC

本文介绍了一种使用QTP结合QualityCenter进行自动化测试的方法。通过QualityCenter API下载Excel文件到本地,并利用QTP的DataTable.ImportSheet方法导入数据表。此方案解决了测试数据集中管理和维护的问题。

How to import and export sheets from Quality Center using DataTable of QTP ?

I came across this problem recently when we decided to store our excel files in test plan module of Quality Center(Version 10.0.).

Joining the automation team while the project is already ON keeps you limited in your approaches. If Automation is being carried out using QTP and Quality Center with a framework, which is not flexible It limits the approaches further.

In my project, There were loads of reusable Actions , in which data was being pulled from excel sheets and we were using "DataTable.ImportSheet" for the task. Excel files were on client filesystem BUT now we wanted to keep our data at a central location so that it is created, managed and maintained better. QC was on everybody's mind as It was already being used by other testing teams as central repository. Till Date QC does not have any mechanism which can be used to take care of test data in easier and better ways. Atleast to me it is not better. I am not a very big fan of QTP and QC.

We wanted to reflect minimum changes, for data needs, in our scripts. I wish QTP could support over-ridingImportSheet method of DataTable using RegisterUserFunc. Which could solve the problem without going inside scripts and replacing DataTable.ImportSheet with search and replace option. However, We do not have that option.

I am posting the approach taken by me (May not be the best one) so that it helps you if you are also stuck on the same problem.

Importing Data tables inside QTP is quite simple using the following line of code.

DataTable.ImportSheet "C:\Full\File\path\FileName.xls" _
,"SourceSheetName","DestinationSheetName"

'OR
'Add C:\Full\File\path to folder options in QTP Options.

DataTable.ImportSheet pathfinder.locate("FileName.xls") _
,"SourceSheetName","DestinationSheetName"

If you refer the documentation provided in QTP,you will find that the Ist parameter to ImportSheet method can be a filesystem path or Quality Center Path.

Following the docs In File-->Settings-->resources if you would choose a path for importing data table using the file explorer and point it to the file stored in attachments of a test stored in Quality Center the path would be something like

[Quality Center] \Subject\path\to\yourtest\FileName.xls

  1. What was digged to solve the problem ?

    1. Pathfinder.Locate("FileName.xls") by adding my QC Folder in options.

      I tried using this approach, however it did not work, and I kept getting error Path not found

    2. Can I play with Environment("TestDir") or Envrionment("SystemTempDir") ??

      If you explore the %Temp%TD_80 you would see the following path to the attachments of your test!!

      "C:\Users\[UserName]\AppData\Local\Temp\TD_80\ _6f4df540\Attach\TEST\[TestID]\TEST_[TestID]_[FileName].xls"

      How to ensure that Temp%\TD_80 is not cleared on every round of execution. And the solution should mandatorily download the excel file so that we can keep our standard approach of using DataTable.ImportSheet.

  2. Solution

We decided to go for OTA API and felt relieved that it could be accessed using set QCConn = QCUtil.QCConnection inside QTP's IDE.

Following is the algorithm, which we used.

  1. Get hold of a Test Stored in Quality Center and reach the attachment object associated with a test.
  2. Download the excel file(stored as attachment) to client's filesystem using the Attachment Object.
  3. Use DataTable.ImportSheet method to import data.
  4. replce DataTable.ImportSheet call with a custom function and Leave rest of the scripts as intact as it was.

I am posting the code below for your use and review.

Public Function DataTableImportSheetFromQC(QTPTest,sFileName,SheetSource,SheetDest)
        Dim attachFact,attachList,attachObj,bResult

        On Error Resume Next

        'Assingments
        bResult=False
        Set attachFact = QTPTest.Attachments
        Set attachList = attachFact.NewList("")

        For each attachObj in attachlist
        'Ensuring Excel File is stored as attachment to the test
        'Naming Convention used by QC is TEST_[TESTID]_[FileName]
                If Instr(attachObj.Name,sFileName)>0 And _
                        Instr(attachObj.Name,TestObject.ID)>0 Then
                        'Download the attachment to client  filesystem
                        'Import Sheet Method was not working to QCPaths,
                        'Or We can say that QCPath is the temp path of downloaded file
                        attachObj.Load True, "" 'the second param is not required in vbscript
                        'FilName Property of attachObj gives full file path
                        DataTable.ImportSheet  attachObj.FileName,SheetSource,SheetDest
                        bResult = True
                        Exit For ' Dont waste time in searching for others
                End If
        Next

        If Err.Number <> 0 Or Not  bResult Then
                bResult = False
                Err.Clear
                On Error goto 0
        End If

        DataTableImportSheetFromQC = bResult
        'release the objects
        Set attachList = Nothing
        Set attachFact = Nothing

End Function

After designing this function we replaced all lines, which used DataTable.ImportSheet statement with a call to this function. Hope it is of some help to you and please post replies if there is any other approach, which you have adopted.



本文转自hcy's workbench博客园博客,原文链接:http://www.cnblogs.com/alterhu/archive/2011/12/31/2308792.html,如需转载请自行联系原作者。

内容概要:本文系统介绍了算术优化算法(AOA)的基本原理、核心思想及Python实现方法,并通过图像分割的实际案例展示了其应用价值。AOA是一种基于种群的元启发式算法,其核心思想来源于四则运算,利用乘除运算进行全局勘探,加减运算进行局部开发,通过数学优化器加速函数(MOA)和数学优化概率(MOP)动态控制搜索过程,在全局探索与局部开发之间实现平衡。文章详细解析了算法的初始化、勘探与开发阶段的更新策略,并提供了完整的Python代码实现,结合Rastrigin函数进行测试验证。进一步地,以Flask框架搭建前后端分离系统,将AOA应用于图像分割任务,展示了其在实际工程中的可行性与高效性。最后,通过收敛速度、寻优精度等指标评估算法性能,并提出自适应参数调整、模型优化和并行计算等改进策略。; 适合人群:具备一定Python编程基础和优化算法基础知识的高校学生、科研人员及工程技术人员,尤其适合从事人工智能、图像处理、智能优化等领域的从业者;; 使用场景及目标:①理解元启发式算法的设计思想与实现机制;②掌握AOA在函数优化、图像分割等实际问题中的建模与求解方法;③学习如何将优化算法集成到Web系统中实现工程化应用;④为算法性能评估与改进提供实践参考; 阅读建议:建议读者结合代码逐行调试,深入理解算法流程中MOA与MOP的作用机制,尝试在不同测试函数上运行算法以观察性能差异,并可进一步扩展图像分割模块,引入更复杂的预处理或后处理技术以提升分割效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值