Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Script Editors are similar to IDEs that you generally use to code. It provides a workspace to jot down your script, edit it and customize it according to your need. This blog will teach you how to work with these editors and their types. 💫💫💫💫
Script Editors
Script Editors provides the scripting interface to us. We can use them to write our groovy scripts in ReadyAPI. These are available at multiple places throughout ReadyAPI. Script Editors are generally available in the lower sections of the dialogue box. A sample script editor is shown in the image below.
Script editors have various objects which decide the behaviour of our script. These are usually present at the top of the script editors.
Types of Editors
Script editors are available at many places across ReadyAPI. They facilitate the editing of different types of scripts.
Groovy Script Test Step Editor
This script editor allows you to run your groovy scripts as a part of the test case. Unlike other editors, it provides a debugging feature. All the regular features are similar to other editors, such as property expansion, code validations and templates.
Script Objects
Let's see what all script objects are available in ReadyAPI.
Object
Description
log
It gives a scripting interface for logs.
context
It gives a scripting interface to the context object.
testRunner
It gives an interface to the test runner object.
You can get it from the documentation if you want to learn more about any object. Invoke the getClass() method that every object in ReadyAPI has:
Setup and Teardown Script Editors
These editors work at the project, suite, and case level. All the features, such as property expansion, code validation, and templates, are also available. These scripts can run before and after the execution of the step.
⭐Test Case Level
⭐Suite Level
⭐Project Level
Script Objects
Let's go through the objects available in setup and teardown script editors.
Object
Description
log
This object helps to put messages in the script log.
context
It gives a scripting interface to context objects at a project, suite or test case level.
testRunner
It handles the running of tests.
virtRunner
For running virtual services and virtServer.
testSuite
It provides a scripting interface for suites.
testCase
It provides a scripting interface for test cases.
project
It provides a scripting interface for projects.
Report Script Editor
Report Script Editor gives us the interface to write the script to execute post-execution commands. It is available at the suite and test case level. This editor has all major features such as property expansion, code validation and templates.
⭐Test Suite Level
⭐Test Case Level
Script Objects
Let's go through the objects available in the report script editor.
Object
Description
log
This object helps to put messages in the script log.
report
This object helps to fill the report template by saving all the data it needs.
params
It contains all the report parameters and values.
testSuite
It provides a scripting interface for suites.
testCase
It provides a scripting interface for test cases.
Data Source and Data Sink Script Editors
If you want to generate values for a data source or save existing data to a data sink, you can write those scripts for these editors. All you need to do is to run the groovy scripts. All the features such as property expansion, code validation, and templates are also available.
⭐Data Source
⭐Data Sink
Script Objects
Below is a list of all the default objects available in these editors.
Object
Description
log
This object helps to put messages in the script log. You can view messages from here.
testRunner
It provides a scripting interface to the runner object currently executing test cases and steps.
Context
Gives interface to properties to currently running tests.
result
An array containing keys matching those of data sources properties.
properties
An array containing keys matching those of data sink properties.
Virtual Service Script Editors
ReadyAPI has the virtual service script editor, which can edit our groovy script for running, editing and customizing virtual services. We can even form and dispatch virtual services, assert incoming requests and much more.
Script Objects
Below is a list of all the default objects in this editor.
Object
Description
log
This object helps to put messages in the script log. You can view messages from here.
context
It gives a scripting interface to virtual services, responses and runners.
message
This object gives a scripting interface for the JMS body and headers.
mockOperation
It relates to virtual operation. It gives a scripting interface to virtual responses, assertions, and dispatch settings.
mockRequest
It provides an interface for incoming requests.
mockResponse
It provides an interface for virtual responses.
mockResult
Provides an interface to the message exchange procedure.
mockRunner
It provides an interface to virtual service runners.
requestContext
Provides an interface to request context.
Event Script Editors
This editor allows for editing event scripts. Event scripts are fired for a specific event before a test case is executed. This editor has all major features such as property expansion, code validation and templates.
Script Objects
Below is a list of all the default objects in this editor.
Object
Description
log
This object helps to put messages in the script log. You can view messages from here.
context
It provides scripting UI to properties available in this event handler.
Editor Options
Usually, the editors have a play button and an edit button. Either both will be present or one of them.
Option
Description
It runs the script.
Edit
This button opens the editor dialogue box.
Note: Instead of using the 'edit' button, we can right-click on the space to bring up the editing options. All the standard operations, such as undo, cut, copy, paste, delete, find and replace, etc., are available here.
Using Property Expansions
Property expansion opens the properties dialogue box to access all the script editing features ReadyAPI provides.
✅To perform property expansion, click on the ‘Get Data’ option, as shown in the image below.
✅Next step is to browse the dialogue to box and choose the desired property.
✅Give a name to the newly created variable.
✅Click OK.
ReadyAPI will create the variable and use property expansion to fill it using the following groovy script.
def searchString = context.expand( '${string to be searched}' )
Code Completion
Code completion is a convenient feature available in ReadyAPI script editors. It is similar to how it works in any general IDE, such as visual studio or Intellij. As you start typing the groovy script, automatic suggestions are shown corresponding to methods and parameters available. It speeds up the scripting process. The code completion feature also suggests custom java libraries and JAR libraries located in the /bin/ext/ and /lib directories.
Code Validation and Templates
ReadyAPI actively checks for syntax and other errors and warns the developer in real time. It can sometimes lead to performance issues. Thus we have the option to disable auto syntax checking. Use the following to disable auto syntax checking:
-Dgroovy.disable.syntax.checking=false
ReadyAPI also supports a pre-written boilerplate code template for setting up the initial script structure. Type the template ID in the editor and press these buttons together CTRL+SPACE+SHIFT to use it.
Frequently Asked Questions
What is an Editor?
An editor is a workspace UI intended for writing code/script. It supports all the essential editing functions a code needs, such as copying, pasting, deleting, auto-complete etc.
What is Groovy?
It is a java syntax following object-oriented language intended to be run on the java platform. It has features of both static and dynamic typed languages. Groovy is mainly used for script writing.
What is a Script?
It is a computer language containing several commands in a file capable of running without the need for compilation.
Conclusion
In this blog, you learned about scripting for Script Editors in ReadyAPI. All the important topics related to Script Editors in ReadyAPI were covered in detail.
Also, refer to other API testing-related articles: