I have made a demo project on GitHub:
----
In the ‘UsingMaterialsInKatalonStudio’ project, I will show you, step by step, how to write test scripts in Katalon Studio making use of the ‘Materials’ library.
The Groovydoc of the Materials
is published here.
===
Problem to solve
What is a material? By the term Material I mean any file created by test scripts on the fly. A typical example of a Material is a PNG file as screenshot of web page taken by WebDriver API. Other examples of Material would include:
- PDF files downloaded from web site
- Excel/CSV files created by test script
- JSON/XML responses from RESTful API call
- HTTP Response Header in plain *.txt format
Selenium WebDriver and Katalon Studio provide sound support for interacting with web. But their support falls short of the following problem: which path to save a file as?
Specifying a one-off path is trivial. Say, C:\Users\myname\tmp\sample_screenshot.png
would be fine. However if we are to make dozens of materials repeatedly and if we are to reuse the files after interating with web, then it becomes an itchy problem how to resolve paths for all materials appropriately.
How do I want to reuse materials? For example, I want to perform Visual Testing in Katalon Studio. I would take 30 screenshots of my web app in both of the production environment and the development environment. After taking screenshots, I want to compare pairs of images to find out if any differences are found.
Another usecase of materials is just for logging purpose. When I test RESTful API, it is likely I want to save HTTP Respose and Body into files just for logging.
My problem is that I have to design the paths for those files. I want a reusable solution for resolving material paths: a class library which implements a designed repository for the files (materials) with intuitive access methods.
===
Solution
The Materials
library implements the com.kazurayam.materials.MaterialRepository
object. A test script in Katalon Studio can ask the MaterialRepository
object to resolve path for a material for you. The path would be in the format as follows:
${projectDir}/Materials/${testSuiteName}/${testSuiteTimestamp}/${testCaseName}/${subdirs}/${fileName}
For example,
./Materials/TS07_visit_a_web_site/20180919_132138/TC07_visit_a_web_site/1 CURA_Homepage.png
An example of file tree created is like this:
Also the com.kazurayam.materials.MaterialRepository
object can make ./Materials/index.html
file. This HTML file is a viewer, provides easy access to the files contained in the repository. The following picture shows an example of the ./Materials/index
.
===
How to set up
This project depends on the jar provided by the Materials project on GitHub. The jar files are downloadable from the Releases
page. You can import the jar file into your Katalon Studio project as an External library.
However ${projectDir}/Drivers/Materials-0.17.jar
is already bundled in this demo project.
Description of codes
I will describe all test scripts one by one. Please retrieve each pages by clicking the links.
Test Cases
TC01_starter
TC02_MaterialRepository
TC03_subdirectories_under_testCaseName
TC04_URL-based_filename
TC05_GlobalVariable.CURRENT_TESTCASE_ID
Test Suites
Test Suite Collections
===
Possible usecases
Not only for screen shots but other types of files
The resolveMaterialPath
method of MaterialRepository
returns a java.nio.file.Path
object = the location of a file. It does not read or write java.io.File
object. This means that the Materials
library does not restrict the types of files to be stored in the MaterialRepository.
This demo project describes how to store screen shots into the <projectDir>/Materials
folder. Of course, it is a typical usecase. However you can store other types of files there: PDF files downloaded from web, Excel files createdy by test scripts on the fly, XML and JSON responded Web API services, etc.