Comparing Two Files - WinRunner

WinRunner enables you to compare any two files during a test run and to view any differences between them using the file_compare function.

While creating a test, you insert a file_compare statement into your test script, indicating the files you want to check. When you run the test, WinRunner opens both files and compares them. If the files are notidentical, or if they could not be opened, this is indicated in the test report. In the case of a file mismatch, you can view both of the files directly from the report and see the lines in the file that are different.

Suppose, for example, your application enables you to save files under a new name (Save As...). You could use file comparison to check whether the correct files are saved or whether particularly long files are truncated.

To compare two files during a test run, you program a file_compare statement at the appropriate location in the test script. This function has the following syntax:

file_compare ( file_1, file_2 [ ,save_file ] );

The file_1 and file_2 parameters indicate the names of the files to be compared. If a file is not in the current test folder, then the full path must be given. The optional save_file parameter saves the name of a third file, which contains the differences between the first two files.

In the following example, WinRunner tests the Save As capabilities of the Notepad application. The test opens the win.ini file in Notepad and saves it under the name win1.ini. The file_compare function is then used to check whether one file is identical to the other and to store the differences file in the test directory.

# Open win.ini using WordPad.
system("write.exe c:winwin.ini");
set_window("win.ini - WordPad",1); # Save win.ini as win1.ini
menu_select_item("File;Save As...");
set_window("Save As");
edit_set("File Name:_0","c:Winwin1.ini");
set_window("Save As", 10);
button_press("Save"); # Compare win.ini to win1.ini and save both files to "save".

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

WinRunner Topics