Prerequisite: Familiarity with Java Selenium APIs is expected to create Custom Functions.

Note: Our Support Team can help you in creating Custom Functions in the shortest time subject to requirement feasibility and availability of Test Automation Experts.


In the next section, we will see how to clone the Testsigma Sample Custom Function Repository to your IDE for viewing some sample Custom Functions and to create Custom Functions easily with IDE-based suggestions.


Cloning the repository

1. Clone the following repository and import to any of your favorite IDE (Recommended: Eclipse IDE)

git clone https://bitbucket.org/testsigma/testsigma-custom-functions.git


2. Add all dependencies and resolve compilation errors in the IDE.


3. Refer to one of the existing custom function class in the com.testsigma.customfunc package or refer to Code Example section below in this article to write your custom 

function.


4. Now, copy the entire code to the Create Custom Functions page in Testsigma and click on Compile and Save.


Check the following article for more details on creating Custom Functions - How to create and use Custom Functions in Testsigma?

Note: Though there is no limitation in Custom Function Lines of Code, it is suggested to split the Custom Functions to keep the size of a Class less than 100 lines of code.


Code Usage Guidelines

The Custom Functions code should adhere to the following guidelines for successful compilation and execution:


DOs:

1. Import Mandatory packages/classes(lines 1-4 in above sample code).

  • com.testsigma.customfunc.common.TestsigmaCustomFunctions
  • com.testsigma.customfunc.common.CustomTestStep
  • com.testsigma.customfunc.result.ResultConstants
  • com.testsigma.customfunc.result.TestStepResult


2. Create a Class with the name of the Custom Function and extend TestsigmaCustomFunctions(line 7).


3. Create at least one method and declare the annotation @CustomTestStep for the Custom Function method(line 10).


4. Declare TestStepResult as return type for each Custom Function method(line 12).


5. Create TestStepResult instance(step 18) and use the available methods setStatus() and setMessage() (step 19-20) for each Custom Function method.

  • Use setStatus(ResultConstants.SUCCESS) or setStatus(0) to set Custom Test Step Success.
  • Use setStatus(ResultConstants.FAILURE) or setStatus(1) to set Custom Test Step Failure.
  • Use setMessage("User specific message") for debugging purposes.


6. Return the instance of TestStepResult after setting the status and message.


DONTs:

1. There shouldn't be any package declarations. Remove if there are any.


2. Do not declare the WebDriver Interface or its implementations. An instance of WebDriver Implementation has been initialized implicitly for variable 'driver'.

For example, the following line of code would work without any additional code changes within the Custom Function class:

driver.get("https://www.google.com")


You can find more examples for Custom Functions in the above provided public repository.