The Rational Tester was visiting a client who had recently purchased Rational Functional Tester. During the meeting, a question came up as to what would be the best approach to comparing two files in a Rational Functional Tester script. It was fun to get back to my geeky roots, and with Rational Functional Tester being built upon Java, we had lots of easy options.
For this particular situation, all that was required was a simple “Yes / No” answer. Either the files were the same or they were not. In this situation, probably the simplest approach is to leverage the apache commons i/o libraries. In this library, you’ll find one line file compare function called contentEquals.
To use this library from Rational Functional Tester, download the library (currently the latest version is “commons-io-1.4-bin.zip”, expand the zip and copy the “commons-io-1.4.jar” to the RFT customization directory which by default is C:\Documents and Settings\All Users\Application Data\IBM\RFT\customization. This process, by the way, is documented in the Rational Functional Tester Help.
From there, you’ll need to add two import statements. First you need java.io to gain access to the File object type that is required by the contentEquals function. Of course, you’ll also need the contentEquals function which is in the org.apache.commons.io.FileUtils package.
With the imports in place, create two file objects, one for each file, and then use a vpManual to compare the results of the comparison. Here is a screenshot of a simple test I wrote. Unfortunately, the blog limits the types of files I can share, so I can’t share the actual script with you.
In the above, two verification points are created. The first compares the first file to itself, which will always pass. The second compares two different files, which results in a fail.
A logical next step would be to log the actual differences. We’ll save that for a subsequent post, but for a quick fix, here is an article which shows some sample code that would get you started.