Araxis Merge automation API in JavaScript

Araxis Merge is a file comparison tool that supports many file formats, even formats such as MSWord and PDF. That makes this tool ideal for regression testing of application output in the form of, for instance, generated PDF files. Araxis Merge comes with an automation API which helps us speeding up the file comparison process easily.

Several programming and scripting languages are supported from which you can control Araxis Merge, such as VBA, c#, C++ and Windows Scripting host (VBScript, JavaScript).

Recently I needed to call the automation API from within AutoIt in order to compare two pdf files and to generate the comparison report. As AutoIt is not in the list of supported scripting/programming languages, I wrote a script with JavaScript to perform this action. Following script can be run from command line, so it can be called from any other scripting language, such as AutoIt.

The comparison JavaScript


I have foreseen three different input parameters for the script:

  • baseFile: the complete path + filename of the first file. This is the base line file which the newly generated file will be compared with
  • newFile: the complete path + filename of the second file to compare against the base line file
  • report: the complete path + filename of the comparison report to generate

If all mandatory arguments were specified, the file comparison starts; otherwise directions on how to call the compare script are shown.

if (WScript.Arguments.length != 3) {
directions();
}
else {
compare();
}
Create an Araxis Merge application object and retrieve the command line parameters. Perform the comparison between the base file and new file. Create a merge report only if there is at least 1 difference between the two files. Note that I wrote down > 1 as a value of 1 of property NumberOfChanges means that there are no differences.

function compare() {

var app = WScript.CreateObject("Merge70.Application");
var tc = app.TextComparison;

baseFile = WScript.Arguments.Item(0);
newFile = WScript.Arguments.Item(1);
report = WScript.Arguments.Item(2);

tc.Compare(baseFile, newFile)

if ( tc.NumberOfChanges > 1) {
tc.Report("html", 0/*lesCRLF*/, report); //report
}

}
This function displays the correct comment line syntax to use when calling the compare script.

function directions() {
WScript.Echo("Command line syntax:\ncompare.js baseFile newFile report");
}
Put above code all together in one JavaScript file, for instance "compare.js". From the command prompt window, navigate to the script folder location and run the script by typing the command below. Don't forget to replace normal "\" by "\\" in each of the three arguments.
compare.js baseFileLocation newFileLocation reportCompleteLocation

When running this command Araxis Merge should start comparing the two input files, and to write down the report to the location of your choice if any changes exist.

I chose not to implement any error handling in the script, to make it as simple as possible. Any error handling and validation is handled by the caller script in AutoIt in my case.

Related Posts by Categories

Comments

Recent Articles

Top Commenters

Recent Comments