Test Complete的性能记录方法
陈能技
2007-8-18
Test Complete主要是一个功能测试工具,利用其对GUI控件的识别、动作记录、回放等脚本技术实现替代部分的人工测试的执行。但是它同时还提供很多机制让我们在功能测试的同时记录性能。
MemUsage,CPUUsage
可利用TC(Test Complete)的sys对象的属性获得关于进程和操作系统的内存、CPU使用情况。
下面脚本记录当前所有进程和操作系统使用的内存:
log.Message(VarToStr(Sys.MemUsage)+'%');
下面脚本记录notepad进程的当前内存使用情况:
Log.Message(VarToStr(Sys.Process('notepad').MemUsage)+'K');
通过访问Sys对象,可以获取关于CPU的各种信息,例如,CPU处理器、处理器个数、CPU使用率(包括系统的和某个具体进程的)
//Information on the processor(s) installed on the current computer.
log.Message( Sys.CPU);
//Returns the number of processors installed on the current computer.
log.Message( Sys.CPUCount);
//Current percentage of CPU time used by the operating system and all running processes.
log.Message( VarToStr(Sys.CPUUsage)+'%');
//the current approximate percentage of the CPU time spent running the process.
log.Message( VarToStr(Sys.Process('notepad').CPUUsage)+'%');
注意:使用TC提供的VarToStr函数把Sys对象的各种属性变量值转换成String类型,否则log信息无法显示值。
与AQTime集成
上面说的方法是TC本身提供的,只能记录基本的性能参数,例如内存、CPU,TC还提供另外的途径记录性能,例如通过与AQTime集成的方式,AQTime是AutomatedQA公司出品的代码性能测试工具,它能在程序执行过程中记录每行代码的执行效率,内存使用情况、代码覆盖率等。
与AQTime集成有两种方式。一种是调用AQTime软件的方式,另外一种是直接使用AQTime提供的接口对象。
如果采用第一种方式,则首先应该把TC的TestedApps的执行模式改成 Profile 模式,可在TestedApps editor中设置,也可在脚本中设置,例如:
var
MyApp : OleVariant;
begin
// Obtains the tested application
MyApp := TestedApps.MyTestedApp;
// Specifies the run mode parameters
MyApp.Params.ProfileParams.AQtimeVersion := 5;
MyApp.Params.ProfileParams.ProfilerName := 'Coverage Profiler';
MyApp.Params.ProfileParams.RunMode := 'Normal';
MyApp.Params.ProfileParams.UseProject := False;
// Activates the Profile run mode
MyApp.Params.ProfileParams.Activate;
...
end;
第二种方式是采用访问提供的编程对象的方式,提供AQtimeIntegration 、AQtime、slAQtime对象来访问AQTime的各种功能。
例如,下面脚本使用AQtimeIntegration 和AQtime对象,首先通过AqtimeIntegration对象的IsSupportedVersionAvailable属性判断某版本的AQTime是否存在,如果存在,则指定CurrentVersion为某版本的AQTime,然后通过AQTime对象的CreateProjectFromModule方法创建一个新的AQTime项目,通过SelectProfiler方法指定Profile的类型,通过StartProfiling方法开始Profile,通过WaitAndExportResults输出结果。
procedure TestAQtime;
begin
// Checks AQtime version
if not AQtimeIntegration.IsSupportedVersionAvailable('4') then
begin
Log.Error('The required version of AQtime is not installed.');
Exit;
end;
// Specifies the desired AQtime version
AQtimeIntegration.CurrentVersion := 4;
// Creates a new project
if not AQtime.CreateProjectFromModule('C:/MyTestedApp/MyTestedApp.exe') then
begin
Log.Error('Cannot open the project.');
Exit;
end;
// Selects the desired profiler
if not AQtime.SelectProfiler('Performance Profiler') then
begin
Log.Error('Cannot select the specified profiler.');
Exit;
end;
// Starts profiling
if not AQtime.StartProfiling() then
begin
Log.Error('Cannot start profiling.');
Exit;
end;
// Waits until the profiling is over and
// exports profiling results
AQtime.WaitAndExportResults('C:/MyTestedApp/MySummaryResults.xml',
'C:/MyTestedApp/MyResults.xml');
// Closes AQtime
AQtime.Close();
end;
下面脚本则使用的是slAQtime对象来访问AQTime:
procedure TestAQtime;
var
p : array[0..2] of OleVariant;
i, FileName : OleVariant;
begin
p[0] := slAQtime.P4_AllocationProfiler; // Allocation Profiler
p[1] := slAQtime.P4_CoverageProfiler; // Coverage Profiler
p[2] := slAQtime.P4_PerformanceProfiler; // Performance Profiler
// Opens your application in AQtime
FileName := 'C:/MyProjects/MyApplication/MyApp_exe.aqt';
slAQtime.SetAQtimeProject(FileName);
for i := 0 to 2 do
begin
try
// Starts profiling in AQtime 4
slAQtime.RunAQtime4(p[i]);
{ To start profiling in other versions of AQtime,
use the following methods --
AQtime 3.x:
slAQtime.RunAQtime3(slAQtime.P3_VCLClassProfiler);
AQtime 2.x:
slAQtime.RunAQtime2(slAQtime.P2_VCLClassProfiler);
AQtime .NET Edition 1.2x:
slAQtime.RunAQtimeNET(slAQtime.PNET_StatisAnalysis); }
except
// Posts an exception message to the test log
Log.Error(ExceptionMessage);
end;
// Your code goes here...
// Wait until the profiling is over
// (we call RunAQtime4 method in a loop)
slAQtime.DoWaitFinish;
end;
end;
通过调用操作系统的Perfmon对各种性能参数进行监控
Perfmon是操作系统自带的性能监控工具,它能通过添加各种计数器,对各种性能参数进行记录。在TC中通过调用命令行的方式启动和停止Perfmon。具体方法如下:
首先在Perfmon中加名为perf_log的计数器日志,这里需要记录的是记事本的相关资源使用情况:
Process(NotePad): % Processor Time、Elapsed Time、Working Set
然后在TestComplete中调用命令行方式操作Perfmon(注意Perfmon的命令行工具叫logman),通过设定logman的命令行运行参数来启动(start perf_log)和停止(stop perf_log)Perfmon的计数器日志。
//开始记录
TestedApps.logman.Params.SimpleParams.CommandLineParameters:='start perf_log';
TestedApps.logman.Run();
//添加你的操作
//结束记录
TestedApps.logman.Params.SimpleParams.CommandLineParameters:='stop perf_log';
TestedApps.logman.Run();
通过TC提供的秒表对象记录时间
TC的log里面会对每个GUI动作的时间进行记录,但是记录的是时刻,要后期计算才能得到每个GUI操作的消耗时间,而且有些非GUI的操作时间无法记录,因此有必要寻找更精确、更方便的操作时间记录方式,而TC本身就提供一个叫StopWatch的秒表对象,可以方便地记录脚本的执行时间。
//Start开始计时
StopWatchObj := HISUtils.StopWatch;
StopWatchObj.Start();
//执行你的操作
// Stop结束计时,通过StopWatch的ToString方法直接获取到经过的时间
StopWatchObj.Stop();
Log.Message('TimerRoutine finished.');
Log.Message('Execution time: ' + StopWatchObj.ToString());
分享到:
相关推荐
把程序目录bin下:用TestComplete替换掉原有TestComplete 然后启动替换后的程序。 首次登陆按照如下设置: User Name: Eternal Shield Company Name: HOMEZ, Inc. Registration Code: 558B8FDC-6BF62C26-F83BF6FF
TestComplete主要是一个功能测试工具,利用其对GUI控件的识别、动作记录、回放等脚本技术实现替代部分的人工测试的执行。但是它同时还提供很多机制让我们在功能测试的同时记录性 TestComplete主要是一个功能测试...
TestComplete中文帮助手册 TestComplete中文帮助手册 TestComplete中文帮助手册 TestComplete中文帮助手册 TestComplete中文帮助手册
介绍TestComplete的基本使用方法,以及如何利用TestComplete的各种特性对.NET软件进行自动化的功能测试
TestComplete中文帮助手册,教你如何使用TestComplete
TestComplete5 KeyGen 可以生成TestComplete5的注册码,其中的keygen.exe杀毒软件可能会报是病毒,本人用是正常的,各位下载时自己衡量吧。提供一组我自己生成的注册码: KLP KLP SSG D8563359-9400D3D0-05000000
Testcomplete750ent的破解
TestComplete is an automated testing tool, designed for advanced and novice testers alike, to create, manage and run tests for any desktop, Web or rich client software. It does not depend on any ...
testcomplete7.2企业版注册机 记得使用的时候关闭杀毒软件
关于TestComplete7的学习说明
介绍TestComplete的关键字测试介绍TestComplete的关键字测试
TestComplete与QTP的简单比较, 如何选择,一对比便知道!
Test Complete自带帮助文档的中文版
TestComplete 入门教程(英文版),教你如何创建第一个TestComplete工程
原来链接不能用了,很多人问,重新上传,跟这个内容一致。 https://download.csdn.net/download/fvafuc/8239685
testcomplete7安装程序及激活码(part3)
这是一个TestComplete的中文帮助,主要包括内容: 1。TestComplete基础教程,大概讲了测试种类,创建一个自动化测试的基本过程,测试对象模型这些基础内容; 2。TestComplete数据驱动测试 3。如何测试.NET应用...
Testcomplete基础培训 PPT 软件测试 PPT教程
TestComplete 自动化测试 培训教材 中文帮助 中文教材 还可以,不错。
With TestComplete, you can test applications of three major types: desktop, web and mobile: • Desktop applications - these applications are executed on desktop computers running the Windows operating...