添加需要比较的文件有以下3种方法:
//1.Add files from the Files editor
//2.Add files from the Project Explorer
//3.Add files from scrīpts
在TC里,封装了好几个文件比较的方法,主要有以下几种:
//4.Comparing files by bytes
//使用正则表达式比较文件(RegExpr)
//5.Comparing files with variable parts
具体使用如下:
procedure AddfileFromscrīpt;
begin
if not Files.Add('../../TestFile_old.txt', 'TestFile_old') then
Log.Message(Files.LastError);
if not Files.Add('../../TestFile_new.txt', 'TestFile_new') then
Log.Message(Files.LastError);
if not Files.Add('../../TestFile_new_space.txt', 'TestFile_new_space') then
Log.Message(Files.LastError);
end;
//获取文件方式
//FileNameByIndex、FileNameByName、NameByIndex 、NameByFileName 、FileNamesList、NamesList
procedure GetFile;
begin
showmessage(Files.FileNameByIndex(0));
end;
//常用比较文件方式
procedure ComparefileBytes;
begin
if not Files.Compare(files.FileNameByName('TestFile_old'), files.FileNameByName('TestFile_new')) then
showmessage(files.LastError);
end;
//通过Hash值比较文件
procedure ComparefileHash;
var Hash : OleVariant;//Hash记录两个文件的差异值
begin
Hash := Files.CalculateHashValue(files.FileNameByName('TestFile_old'), files.FileNameByName('TestFile_new_space'));
if not Files.Compare(files.FileNameByName('TestFile_old'), files.FileNameByName('TestFile_new_space'),Hash) then
showmessage(files.LastError)
else showmessage('The two files is equal!');
end;
procedure Test_Sample;
begin
Aliases.TCSampleForm.Drag(224, 17, 162, 0);
Aliases.TCSampleSys.Process('Explorer').Window('Shell_TrayWnd').Window('ReBarWindow32').Window('MSTaskSwWClass', '运行应用程序').Window('ToolbarWindow32', '运行应用程序').CheckItem('TestComplete - C:/Documents and Settings/temp/桌面/hzr-TechED/TCSamples/TCSamples', -1, false);
end;
因篇幅问题不能全部显示,请点此查看更多更全内容