The original was posted Apr’21. I have revised this at Oct,23.
I have published a GitHub project:
Web testers often want to compare 2 text files. The files could be in various format: CSV, JSON, XML, etc. They sometimes just want to check if 2 texts are identical or not. And they may want to see the detail differences. Katalon Studio does not offer any texts-diff feature; I want it.
Utilize java-diff-utils in Katalon Studio.
Drivers directory of your Katalon project, you NEED to install 2 external jar files.
java-diff-utils-x.x.x is an OpenSource library in Java for performing the comparison operations between texts. This enables us to generate diff information.
I developed the
katalon-studio-texts-diff-x.x.x library which wraps the
java-diff-utils-x.x.x to utilize it in your Katalon Studio project. With it, you get a diff report in Markdown format with side-by-side view.
You want to start Katalon Studio GUI and open your project.
You want to create a new Test Case
ex01 (… any name you can choose in fact), of which code looks as follows. You can just copy and paste this:
import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths /** * ex01 diff 2 strings and write the report into file */ String text1 = """<doc> <body> <section> <p>Hello, John!</p> </section> <p></p> </body> </doc> """ String text2 = """<doc> <body> <section id="main"> <p>Hello, Paul!</p> <p>Have a break!</p> </section> </body> </doc> """ String outpath = "build/tmp/testoutput/ex01-output.md" // take diff of 2 Strings, write the diff CustomKeywords.'com.kazurayam.ks.TextsDiffer.diffStrings'(text1, text2, outpath) Path out = Paths.get(outpath) assert Files.exists(out) assert out.toFile().length() > 0
Now you can run it as a usual Katalon Test Case by clicking the green button .
Once done, the script will create a diff report and save it into a file
build/tmp/testOutput/ex01-output.md. The output will be formatted in Markdown. The file will like this:
**DIFFERENT** - inserted rows: 1 - deleted rows : 1 - changed rows : 2 - equal rows: : 5 |line#|S|original|revised| |-----|-|--------|-------| |1| |<doc>|<doc>| |2| |<body>|<body>| |3|C|<span style="color:red; font-weight:bold; background-color:#ffeef0"><section></span>|<span style="color:green; font-weight:bold; background-color:#e6ffec"><section id="main"></span>| |4|C|<p>Hello, <span style="color:red; font-weight:bold; background-color:#ffeef0">John!<</span>/p>|<p>Hello, <span style="color:green; font-weight:bold; background-color:#e6ffec">Paul!<</span>/p>| |5|I||<span style="color:green; font-weight:bold; background-color:#e6ffec"><p>Have a break!</p></span>| |6| |</section>|</section>| |7|D|<span style="color:red; font-weight:bold; background-color:#ffeef0"><p></p></span>|| |8| |</body>|</body>| |9| |</doc>|</doc>|
The raw Markdown text is hard to read in a plain text editor. So you want to view it using some Markdown viewer. For example, I personally use Visual Studio Code, Markdown preview. You can preview the report in VSCode as follows.
This looks nice, doesn’t it?
The sample Test Case
com.kazurayam.ks.TextsDiffer.diffStrings() method that takes 2 Strings as input. The
TextsDiffer class implements more methods that can take various types: Files, URLs etc.
Examples document for more use cases.
You can have a look at the API documentation of
TextsDiffer class at