The Custom Functions written in Testsigma should adhere to a specific format for it to be recognized by Testsigma compiler.
Below given are the guidelines to be followed while writing the code for Custom Functions:
- There are a set of prerequisite import statements that are to be included. We need to import the WebDriver Class, CustomTestStep Class and TestStepResult Class.
- There should be at least one Class and a constructor present inside the class.
- Before each method/procedure in the Custom Function class, we need to provide the @CustomTestStep annotation for the compiler to recognize it.
- Each of the methods/procedures should have TestStepResult Class as its return type.
- We need to create an Instance of TestStepResult in each of the methods.
- We need to set the 2 required properties(result message and result status) with the TestStepResult Instance using the methods setStatus and setMessage.
- We will set the status as 'SUCCESS' using the setStatus() method with argument '0'.
- We can set a useful Message for debugging using the setMessage() method.
An Example of the Custom Function following all the above guidelines is given below:
It is a simple function that navigates to the Testsigma website.
We can use Custom Function program codes essentially of unlimited length. We just need to keep one Class limited to 5000 lines of code(LOC) which is huge compared to the usual requirement of about 100 lines of code.