Block Functions in Scriptworks are used in a project to provide an area of common functionality which is easy to re-use throughout a project without duplication of block-based workflow.
Location of Functions
When a Test workspace has been opened up the Function list can be accessed by clicking on the Function Button (Fx) as seen below
Creating a Function Block
To create a Function the Plus (+) button can be clicked in the Function list to open up the Function workspace.
After pressing the Plus (+) button the following workspace will appear:
A Function requires a unique name as well as a description which should be meaningful so other users can track the function’s purpose.
When the Name and Description has been added the Workspace will update to use the Function’s name in both the block and the Workspace title. At this stage it is best practice to Save the Function.
At this stage the Function code will only show the base Function declaration which can be seen as below.
The Function is now set up to be populated with Blocks.
To create a Function sequence Blocks can be dragged into the function wrapper in the same way a Test is created.
An Example Function
Here is an example function that clicks on a browser alert and validates the text in the alert for an example:
Using in a Test
Function blocks appear in the Function block list. They can be added by dragging into a Test or other function:
Inputs can be passed from other blocks, e.g. the content of a variable or content from an Excel datasource, simply add an Input:
When used in the test we can pass values into the function from other blocks:
Functions can also be used to provide an output for use within another area of a test or another test within a project. For example, to save a variable in the test from text which is taken from an Element in the application.
Enabling the output toggle will change the type and shape of the Function block so that it becomes an output connector which can then be attached to other blocks in a test or function.
First let’s create a new Function which saves a variable which is to be used in a future test in the suite which then saves the value as an output variable:
Using this Function block in our test, we use the value that has been returned into other blocks for example as input to the DemoFunction function block:
As seen in the below image this test now successfully passes with the passed values.