Compare 2 HTML Files



Why it is important?


While testing or developing framework we may have a requirement to compare text from within the HTML files. It becomes very difficult to do that manually reading as the file can contain 1000’s of word and pages.

That is why is very important to automate this and make our lives easy. There are many libraries that can perform this task for you but here we will use daisy-diff. It is an opensource library i.e. why we are interested in using this. 

How to compare text files?


Before starting the comparison, we need to have Java installed on our machine. To check whether you have Java on your machine run the following command.

java -version

Make sure you have the latest version installed, if not then install the latest version of Java.


Now we need to get the daisy-diff jar file.

Create a folder in your favourite location, copy the HTML files and jar file in the folder

First, we need to understand the options which daisy-diff provides.

Optional Arguments:


--file = [filename]: write output to user specific file

--output=[html/xml]: get output in html or xml format

--q=[quite]: limited console output

--css=[css1,css2,css3] : add external css files

Now to compare two HTML files run the following command


Java -jar daisy-diff.jar file1.html file2.html –file=output.html –output=html

Once the execution is complete you will see an output.html file in your folder.

Below is a sample output.




You can get the sample project at GIT.

Compare 2 HTML Files Compare 2 HTML Files Reviewed by Karan Sawhney on 12:20 PM Rating: 5

No comments:

Powered by Blogger.