跟踪被测应用程序的事件和异常
上一篇 / 下一篇 2007-09-24 17:59:55 / 个人分类:TestComplete
g{RAIq.o0跟踪被测应用程序的事件和异常
uB~B vY7g-c051Testing软件测试网wj#[&h"b ~陈能技51Testing软件测试网5[,nbzn\2@9Z
2007-9-24
JR"w}D%^6}!}(XXx0在使用TestComplete测试一个应用程序的时候,你可以跟踪程序产生的各种事件并把它们记录到test log中。
7o8q4|3k(ekjlQ;q051Testing软件测试网o6|J0{x^"H总览
${$Jx+RIx*D0TC能把debug信息,异常信息,模块加载和卸载,线程创建等事件跟踪记录下来。见下表:
k8?d%])}8vZ0
Event | Type | Descrīption |
Create process | Message | The application under test created a new process. |
Create thread | Message | The application started a new thread. |
Exception | Error | An exception occurred in the application under test. If the application was compiled with debug information, the Remarks pane of the Test Log panel will display a call stack for the exception. The DbgServices plug-in includes several options that have effect when exception tracing (see below). |
Exit process | Message | The process ended. |
Exit thread | Message | The application finished a thread. |
Load DLL | Message | The application loaded a dynamic link library. |
Unload DLL | Message | The application unloaded a dll. |
Output debug string | Message | The application sent this string to the DbgServices object by calling the OutputDebugString function (Win32 API). |
IH&`k0mb051Testing软件测试网t8Zt5r RV:hA
-U r!l Y)v\nm0事件被作为信息输出到log,如下图:
)],OVh9E9Sd0x*[a YNPC0u051Testing软件测试网6U/G@+cG4{r%K#|a51Testing软件测试网 k#Ae'HClM
使用Debug运行模式
%~{}9gvj2JH0可以用两种方法设置Debug运行模式,一种是在TestdApps编辑窗口,设置Run Mode为Debug,Parameters输入命令行参数和工作目录。51Testing软件测试网6]/^8E_#u8}:px1|
另外一种方式是在脚本中设置,例如下面的脚本
5w'_8AI.s"`3FQeW0var
q%n'H8`5B+K0 MyApp : OleVariant;
.w9d+Q2Z0Ap*q0begin51Testing软件测试网rj8y?&M
// Obtains the tested application
a NWLhn[q\&U:z0 MyApp := TestedApps.MyTestedApp;51Testing软件测试网s+zoaH D
51Testing软件测试网:m5mFj tWS"L$z%U
// Specifies the run mode parameters
$h"g~"I4hIk X0 MyApp.Params.DebugParams.CommandLineParameters := '-t -e';
(bz#h%s3[0 MyApp.Params.DebugParams.WorkFolder := 'C:\MyFolder';51Testing软件测试网u
F%O6_w _T
D'A_!gIpT-D\,?F0 51Testing软件测试网W%J&[VH @)`
// Activates the Debug run mode51Testing软件测试网/p@RNFXx
MyApp.Params.DebugParams.Activate;51Testing软件测试网/nZnNo4ba
...
o:^~7d` }:b)z}Y0end;51Testing软件测试网 g;G_A
Fk[ D!Ih
使用DbgServices对象
9c
g#I%qkg*y0使用DbgServices对象的各种方法,例如LaunchTestedApplication、LaunchAllTestedApplications、LaunchApplication、AttachToProcess,可以让TC附加到被测应用程序的运行进程并把debug进程权限赋给TC,从而使你可以跟踪应用程序的事件和异常信息。51Testing软件测试网-mJQ`%RO"?s"QE
使用这种方式与使用Debug运行模式是类似的效果,但是提供了以下便利:
7[MC;FhL0支持任何运行模式的应用程序,而不仅仅是包括在项目的TestedApp里的应用程序。51Testing软件测试网UX*v~0v1m
M
它让你可以附加到一个运行在操作系统的进程并监视它所发生的事件。51Testing软件测试网*^)Kxf]Yu"C+s
如果你使用RunAs运行模式,然后使用LaunchTestedApplication或LaunchAllTestedApplications方法来运行程序,TC会用Debug模式在指定的用户账号下运行被测程序。(也就是说你可以在另外一个用户账号下debug程序)。
下面是个关于使用DbgServices的例子:51Testing软件测试网3G/tW)qz2dO+oy
p := DbgServices.LaunchTestedApplication[0];
E6`'B|-JM{s0l0 w := p.WaitWindow('TfrmDebugServices', 'Debug Services', 1, 10000);
Jb;|iH$dE0
fwM"zN y:o9p0 DbgServices.Options.EnableEvents := True;
^-V@-P.P~3V0 DbgServices.Options.ActiveExceptions := True;
;Kv^^OZ3Ss%x0 Log.Message('Exceptions are being traced.');
a6z*U e4c@1w0 w.Window('TButton', 'Test All').ClickButton;51Testing软件测试网2L VWW(hV
Delay(2000);