Scriptworks Logo

Extending Scriptworks with Raw Code Function Blocks

9 Jan 2019


The available Scriptworks block categories aim to provide a rich breadth of functionality for working with Web and Mobile apps, as well as APIs. There are of course situations where custom code is required to meet specific project requirements.

Scriptworks provides the flexibility to do this through the Raw Code Function Block feature to enable users proficient in Javascript to create custom blocks containing their own code which can be shared across a project and used in tests just like any other block. These blocks can be connected to other blocks by passing input values and providing output values.


Creating a Raw Code Function Block

Raw Code Function blocks are created in the same way as standard Function blocks. There is a setting in the Info panel for the block that switches the type to Raw Code:

Clicking on this will provide a confirmation prompt:


Note: Any Function content created using blocks will be lost when switching to Raw Code. 


The function editor will then change from a Block workspace to a code editor:


The Function prototype is create automatically based on the items in the Function Info panel, e.g. If we type a Function name, the Prototype is updated automatically:



Note: The Function prototype is not editable directly.

An Example Function

Here is a simple function that provides a browser alert for our example:


Using in a Test

Raw Code Function blocks appear in the Function block list alongside other Function blocks. A preview of the Function content and its description can be shown by hovering over the Function in the list. Raw Function blocks can then be added by dragging into a Test or other function, these can be seen in the example test below:



Note how the Function is used in the Code, opening the Code View and clicking on the function block in the test to highlight it will show the corresponding code entry:

This is implemented in Code as a standard function call.


Passing Inputs

Inputs can be passed from other blocks, e.g. the content of a variable or content from an Excel datasource, simply add an Input in the same way as a normal Function:


Note the change to the function prototype, the new parameter is added automatically:

This can then be used in the Raw Function code, as per our alert example:



When used in the test we can pass values into the function from other blocks:



Note also how this is implemented in the Generated Code:



Providing Outputs

Raw Code functions can also be used to provide an output for use within other areas of a test. For example to extract a value from some text. Enabling an output will change the shape of a block so that it has an output connector and can then be attached to other blocks.


First let's create a new Function which strips a value from a text input and passes that value as its output, e.g.:


Note that the use of return to return a value from the function:



Using this Raw function block in our test, we can pass the value returned into other blocks for example as input to the ShowAlert block we created earlier:


This results in an alert showing with the ID extracted from the text:


Scriptworks logo
© Copyright 2024 | Scriptworks is part of Odin Technology Ltd, a company registered in England no. 03735083