In addition to the Manual view, Katalon Studio allows expert users to programmatically write automation test in the Script view of test cases. Users with Groovy/Java background can easily modify the test script as needed.
This tutorial walks you through the steps needed to manually write a very basic automation test script using Katalon Studio. After going through this article, you will be able to understand and use import statements and pre-defined built-in keywords (https://docs.katalon.com/display/KD/Built-in+keywords) to compose test scripts. It’s recommended that you should have some basic scripting background, preferably using Groovy (http://groovy-lang.org/) language to use the scripting capability in Katalon Studio efficiently.
Given a sample test case with the steps as below:
– Open the browser
– Navigate to a website
– Click on certain control
– Validate if a control exists on the page
– Close the browser
Follow these steps to automate the above test scenario in Script view:
1. Select File > New > Test Case from the main menu. The New Test Case dialog will be displayed. Provide the name for the new test case, then click OK.
2. Once a new test case is created, you can switch to the Script view using the corresponding tab at the footer of the test case editor and observe how test steps of the Manual view are translated into Groovy script of Script view.
The import statement in a test script allows referencing to classes to be used. Expand the ‘import’ section to see all default imported classes by Katalon Studio. The name after ‘as’ in each import statement is an alias for the class. You can change the alias for each class. These classes are necessary for composing a test script.
Katalon Studio is an automation tool that supports keyword-driven testing. All keywords are grouped into WebUI (https://docs.katalon.com/display/KD/Web+UI), Mobile (https://docs.katalon.com/display/KD/Mobile) and WebService ( https://docs.katalon.com/display/KD/Web+Service) packages accordingly. Press ‘Ctrl + Space‘ to view these packages and functions from the imported classes.
3. In this scenario, you will create a Web application test script, so you can make use of the Web UI built-in keywords. To use a built-in WebUI keyword, enter the following syntax into the editor.
4. The Content Assist function will be invoked after users enter the dot Content Assist provides users with a context-sensitive suggestion for code completion. Therefore, all the built-in keywords for WebUI testing will be displayed as below:
5. Select the Open Browser. This keyword will open a browser and navigate to the specified URL if provided. Selected keywords will have their description displayed along for reference.
6. Enter the Navigate To Url (https://docs.katalon.com/display/KD/%5BWebUI%5D+Navigate+to+Url). This keyword will navigate to a specified URL. For now, enter the URL of Katalon Studio (katalon.com) as an input parameter.
7. Enter the Click (https://docs.katalon.com/display/KD/%5BWebUI%5D+Click). This keyword represents the click action on a given object. You need to specify an object for this action.
8. Use the following syntax to refer to an object in Object Repository (alternatively, you can drag and drop the object to test case editor to generate the syntax):
Where Object ID is the ID of that object in Katalon Studio.
9. You can find object ID from its Properties dialog. For example:
10. Enter the Verify Element Present (https://docs.katalon.com/display/KD/%5BWebUI%5D+Verify+Element+Present). This keyword validates if a certain object is displayed on the executing browser. Similar to the previous step, you need to specify the object to be used with this keyword.
11. Add the Close Browser (https://docs.katalon.com/display/KD/%5BWebUI%5D+Close+Browser) keyword and save your test case.
12. The following API docs may prove useful when working in Script view:
|List of common built-in keywords|
|WebUI Builtin Keywords|
|List of Web UI built-in keywords|
|Web Service Builtin Keywords|
|List of Web Service built-in keywords|
|Mobile Builtin Keywords|
|List of Mobile built-in keywords|
13. Congratulations! You have finished your first automation script in Groovy language. Click on Run in the main toolbar to execute the test case.
Katalon Studio should be able to execute all the steps of the sample test case and you can see the Test Execution result in Log Viewer. For example: