Learn Along with
Experts
Hands on Exercise
Automating Excel, PDF and JSON files
using Tricentis Tosca
Exercise | Automating Excel, PDF and JSON files using Tricentis Tosca
Objective
By the end of the following exercises, you will be able to demonstrate how to:
a. Read and verify Excel data dynamically.
b. Read and verify pdf text and table.
c. Read and verify JSON data dynamically.
d. Perform a one-to-one comparison of the pdf file.
e. Perform a one-to-one comparison of the Excel file.
f. Comparing Excel files using baseline comparison.
Why is this Important?
Various types of files can be steered by Tricentis Tosca. The most used files are Excel and
PDF. Sometimes we need to perform many operations on files such as Read, Write, Verify,
Buffer, etc. If we perform the manual operation, it will take too much time. That’s why we use
Automation because it is more efficient with less effort.
Instructions
Read and verify Excel data dynamically
1. Log in to Tosca Commander
2. Create the workspace “File Automation” using the workspace template “Standard
Module Subset”.
3. Navigate to the TestCase Section and create a new TestCase in this folder and name
it Scenario 1. Under this create a new Testcase Read and Verify data in Excel file
4. Within this TestCase, create three TestStepFolders – ‘Precondition’, ‘Process’, and
‘Postcondition’
5. Add the Standard Module TBox Open Excel Workbook into the folder Precondition
and rename it as Open Employee Excel Workbook
6. Input Values as shared in the table below:
2
Exercise | Automating Excel, PDF and JSON files using Tricentis Tosca
7. Add the Standard Module TBox Define Excel Range into the folder Precondition and
rename it as Define Generic Excel Range
8. Input Values as shared in the table below:
9. Add the Standard Module TBox Excel Range Manipulation into the folder
Precondition and rename it as Calculate and save number of used data rows in
Excel
10. Input Values as shared in the table below:
11. Add the Standard Module TBox Define Excel Range into the folder Precondition and
rename it as Define Dynamic Excel Range
12. Input Values as shared in the table below:
13. Create the folder in Process folder and rename it as Read Exel Data. Open the
Property from the right side and add the value in Repetition field is
{MATH[{B[RowCount]}-1]}
14. Add the Standard Module TBox Excel Range Manipulation into the Read Excel Data
Folder and rename it as Read and verify Excel data
3
Exercise | Automating Excel, PDF and JSON files using Tricentis Tosca
15. Input Values as shared in the table below:
16. Add the Standard Module TBox Close Excel Workbook into the folder Postcondition
and rename it as Close Excel workbook
17. Input Values as shared in the table below:
18. Mark the TestCase Completed and run it in ScratchBook.
Result - The TestCase should be executed successfully, and the data in Excel file
would be buffered and verified.
Read and verify pdf text and table
1. Navigate to the Module Section and create a new Module folder in this folder and
name it PDF.
2. Start XScan. Select Scan->PDF from the context menu and select the file
Tricentis_USA_EmpDetails [Link]
3. Click Show Content Preview button on top or small upward arrow to display the
Content View on the right side of the PDF Scan window. The Content View shows
the content on the controls you can create
4. Select the Text option and use the mouse to create an area around the Country
name field's value “United States”. Edit the name of the control PDF AREA # to
Country
5. Select the Table option and highlight the area to include just the table contents.
Rename the control to Department Table and click Save. Then close the pdf scan
wizard
6. Rename this Module as Employee Department PDF file
4
Exercise | Automating Excel, PDF and JSON files using Tricentis Tosca
7. Navigate to Testcase Section and create a new TestCase folder and name it
Scenario 2. Under this create a new Testcase Read and Verify data in PDF file
8. Add the Employee Department PDF file Module to our TestCase Read and Verify
data in PDF file
9. Input Values as shared in the table below:
10. Mark this TestCase as Completed and run it in Scratchbook
Result - The TestCase would be executed successfully, and it will verify the pdf
content.
Read and verify JSON data dynamically
1. Navigate to the Module section and create a new Module Folder, rename it to JSON
Files
2. Right- click on the newly created Module Folder JSON Files, and from the context
menu, select the option Scan and then click on API
3. In the API Scan Wizard, on the Ribbon menu HOME, click on File to scan the JSON
file
4. The file explorer window opens, navigate to C:\Tosca_Projects\ and select the JSON
file [Link]
5. Click on API Test Case dropdown on the Ribbon menu and select XML/JSON Test
Case to export it into Tosca Commander
6. Close the API Scan Wizard without saving it
7. You can see that the Module and the TestCase are created in a Component Folder.
Cut the Module DepartmentDetails Request from the Component Folder and
paste it to the newly created Module Folder JSON Files
8. Delete the Component Folder created during the API scan import. (The Folder
named as ApiScan_Import)
5
Exercise | Automating Excel, PDF and JSON files using Tricentis Tosca
9. In the Module Folder JSON Files, rename the Module DepartmentDetails Request to
DepartmentDetails JSON
10. Now let’s make the TestCase dynamic. In the DepartmentDetails JSON delete all
the ModuleAttributes from item#2 to item#n, keeping only item#1
11. Open the Properties pane of the ModuleAttribute item#1 by clicking the expand
arrow on the right-hand pane
12. Rename the value of the parameter Name from item#1 to item*
13. On the Properties pane add the Configuration Parameter Explicit Name
14. Navigate to Testcase Section and create a new TestCase folder and name it
Scenario 03. Under this create a new Testcase Read and Verify data in JSON File
and Change the WorkState to IN_WORK
15. In the newly created TestCase, create two TestStepFolders and rename them to
Precondition and Process
16. Drag and drop the Standard Module Open/Create JSON file to the TestCaseFolder
Precondition.
17. Rename the created TestStep to Open JSON file and create a resource
18. Within the TestStep Open JSON file and create a resource, enter the
TestStepValues as mentioned below:
19. Drag and drop the Module DepartmentDetails JSON to the Precondition
TestStepFolder
20. Rename the TestStep DepartmentDetails JSON to Read and Buffer the Number
of Nodes in JSON File
21. Within the TestStep Buffer the count of DepartmentDetails nodes, enter the
TestStepValues as mentioned in the below table:
22. Now we will buffer the count of department nodes
6
Exercise | Automating Excel, PDF and JSON files using Tricentis Tosca
23. Create a new TestStepFolder within the TestStepFolder Process. Rename it to
Iterate and Store the department Details
24. Click on the newly created Iterate and Store the department Details and open
the Properties pane by clicking on the left arrow button in the working pane
25. Update the Property Repetition by entering {B[DepartmentCount]} in its value.
Observe that the icon of the TestStepFolder has changed, showing the repetition
icon
26. Drag and drop the Module DepartmentDetails JSON file to the TestStepFolder
Iterate and Store the department Details
27. Rename the TestStep to Read and buffer the Department Details
28. Set the TestStepValue Resource to DepartmentDetails
29. Update the Name of TestStepValue item#1 to #{REPETITION}
30. Within the TestStepFolder Iterate and Store the department Details, enter the
TestStep values as mentioned in the below table:
31. Mark the WorkState of the TestCase to COMPLETED
32. Execute the TestCase in ScratchBook
Result- The TestStepFolder repeated itself for the repetition set, and the details of the
nodes were buffered in accordance with the data in the JSON file.
7
Exercise | Automating Excel, PDF and JSON files using Tricentis Tosca
Perform a one-to-one comparison of the pdf file.
1. Place the PDF Compare FIle [Link] and PDF Compare FIle [Link] from the downloads
section of this course and store them in C:\Tosca_Projects
2. Navigate to Testcase Section and create a new TestCase folder and name it
Scenario 04. Under this create a new Testcase Compare Two PDF files and Change
the WorkState to IN_WORK
3. Add the Standard Module 1:1 Compare module to this TestCase and rename the
test step as Compare Product profiles PDF Files
4. Input Values as shared in the table below:
5. Mark this test case Completed and Run it in Scratchbook
Result - The TestCase would be executed successfully both times, and it will compare
two pdfs.
Perform a one-to-one comparison of the Excel file
1. Download the Excel files – Employee Data [Link] and Employee Data [Link]
from the downloads section of this lesson and move them to C:\Tosca_Projects in
your system
2. Navigate to Testcase Section and create a new TestCase folder and name it
Scenario 05. Under this create a new Testcase Compare Two Excel Files and
Change the WorkState to IN_WORK
3. Add the Standard Module TBox Excel 1:1 File Compare to the TestCase Compare
two excel files and rename it as Compare excel files
4. Input Values as shared in the table below:
8
Exercise | Automating Excel, PDF and JSON files using Tricentis Tosca
5. Mark the TestCase Completed and run it in ScratchBook.
Result - The TestCase should be executed successfully, and the cell values and
properties of the two Excel files would be compared successfully. A text file will be
created in the defined folder location containing the comparison result.
Comparing Excel files using baseline comparison
1. Navigate to Module Section. Create folder Excel UI Automation. Right click on the
folder and select scan from the context menu.
2. Select the Employee Data [Link] from Xscan window.
3. Select the Data Table sheet. Save and close the Xscan window
4. Navigate to Testcase Section and create a new TestCase folder and name it
Scenario 06. Under this create a new Testcase Excel Baseline Comparison and
Change the WorkState to IN_WORK
5. Add the scanned module to the TestCase Excel Baseline Comparison
6. Rename the TestStep as Employee Data Excel File
7. Click on the Data Table and then select Create Baseline from TestCase Ribbon
menu.
8. Input Values as shared in the table below:
9. Mark the TestCase Completed and run it in ScratchBook
Result - The TestCase should be executed successfully.