Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Generic Recommendations

In order to create the custom actions for Selenium Webdriver, you need to create the action in Java and then map this action into Qualitia Automation Studio. You can use any IDE tool like Eclipse.

The following are some rules that should be considered when creating custom actions:

  • The parameter data types supported by Qualitia are String and Array. If an array parameter is used in Qualitia for the custom action, then custom action parameter should be of the type Object in Custom Action function. The parameter can then be type-casted into the data type which is required in the action.
    For example, the object parameter can be type-casted into the array list.

  • Based on the standard Java coding rules, actions should not be created in the default package. For better maintenance, it is recommended to use user-defined packages for development.

  • It is recommended to put a prefix when defining a name for new custom actions for easy identification.

  • No two custom actions can have the same function name in the same class. Function overloading is not allowed. Duplicate function names in different classes are allowed (not recommended). 

  • Once the action is mapped into Qualitia and used in a test case, do not change the existing signature or other details of the actions or the classes created. The functionality of the action can be modified. Do not delete the custom actions or custom classes that are used in test cases.

  • If the custom action belongs to any object type (such as WebEdit, WebElement, and so forth), ensure you add the objectInfo data type parameter while developing the code of an action.

  • While mapping actions into Automation Studio, it is important to map the action using <package.class> hierarchy. 

  • Objects should be added under appropriate Qualitia classes while mapping custom actions into Qualitia Automation Studio

Table of Contents

Making a New Class for Recommendations

The user should create his own class consisting of his custom actions. The newly generated class can be added in the same package as that of the already supported actions. 

The user has to make sure that in the testcase, the ‘name’ and ‘qClass’ fields of action is set to the correct name of the action and class containing that action respectively. Qualitia 8.0.0 version uses the concept of java reflection through which the action mentioned in ‘name’ and class mentioned in ‘qClass’ is called directly for action execution. The below example demonstrates making new class for custom actions, 

Info

   package <QASpackagename>; 

import com.qualitia.execution.ActionResponse; 
  import com.qualitia.execution.ApplicationLogger; 
  import com.qualitia.models.testcase.ExecutionResult; 
  import com.webdriverfw.Wrappers.General; 

  <QASimportlist> 

  

  public class <QASclassname> extends General { 

  

  //Define your customs actions here 

  

  }

 Writing Custom Actions in the Accepted Format

The user must strictly follow the pattern for actions which is accepted by Qualitia. The format for actions as per the Qualitia 8.0.0 Version is : 

Info

         public ActionResponse <QASmethodname>(<QASparametername>) { 

     

     ActionResponse actionResponse = getActionResponse(); 

     ApplicationLogger applicationLogger = actionResponse.getApplicationLogger(); 

     actionResponse.setExecutionResult(ExecutionResult.FAILED); 

     try { 

               // Your code here... 

             

           applicationLogger.writeToInfoLog(""); 

           actionResponse.setMessage("Successful message"); 

           actionResponse.setExecutionResult(ExecutionResult.PASSED); 

        } catch (Exception ex) { 

           applicationLogger.writeToErrorLog("Exception message", ex); 

           actionResponse.setMessage(“Failed Message”, FailureCategory); 

           actionResponse.setExecutionResult(ExecutionResult.FAILED); 

        } 

        return actionResponse; 

}  

As per the previous Qualita versions before 8.0.0 , the actions used to return integer value i.e 0,1,2,-1  which were used to indicate PASSED, FAILED, DEFECT, NOT-EXECUTED respectively .The return value has been changed to ActionResponse. The actions return ActionResponse which contains 2 parameters Message and ExecutionResult. Before returning the actionResponse and after the execution of action, the required message and ExecutionResult must be set properly. The primitive datatypes allowed for action parameters are String and Array. 

ApplicationLooger

In the previous Qualitia version,  DataLogger.writeToDebugAndInfoLogs(“”) was used for setting messages. In Qualitia 8.0.0 version, this is replaced by actionResponse.setMessage(“”). The messages which the user wants to set related to execution can be set by actionResponse. 

Qualitia has also introduced ApplicationLogger. If the user wants to set message which is not related to execution, then ApplicationLogger can be used. In general, For action specific logging  the user can use ApplicationLogger.  

  • applicationLogger.writeToInfoLog(""); 

  • applicationLogger.writeToErrorLog(""); 

The main purpose of ApplicationLogger is to create logs to understand the flow of execution. There are 2 types of logs supported for Qualitia: 

  • Info Log

  • Error Log

 

Show Link of

file

File in Info Log

section

Section 

Some custom actions may write file during its execution. User can view that file inside Info Log of that custom action. If user wants to view that file contents, then he can click on the Link to report in the Message section of Info   Info. 

Below function needs to be called before retuning Action Response to show link of file inside log section. 

  

showLinkOfFileInLogsSection(String sourceFilePath, ActionResponse actionResponse) 

  

sourceFilePath: Path of the file you write during custom action execution. 

actionResponse: Action Response object 

 

1.)
  • Info 

2.)
  • Error  
    The user can use these logs according to the requirement. The Error logs must be in catch block of Action. These logs can be seen in Qualitia report which is generated after the execution of suite. 

ExecutionResult

Setting an Execution Result

While setting ExecutionResult, user can make use of ExecutionResult enum where the required results are available. 

ExecutionResult.PASSED , set this when action is passed. 

ExecutionResult.FAILED , set this when action is failed. 

ExecutionResult.DEFECT , set this when the action has defect. 

ExecutionResult.NOT_EXECUTED , set this when execution halts.  

The message and ExecutionResult that has been set will appear in the final Qualitia report. After writing custom actions in the correct format user needs to make following changes in DirectActionCall class: 

Aftercreating new class for Custom Actions, he has to create a new method in DirectActionCall class as “executeYour_Class_Name”. The format of the method should be , 

Info

    private ActionResponse executeYour_Class_Name(String actionName, 

  List<Object> paramValues, Your_Class_Name yourClassObject) throws Exception {  

  

    ActionResponse response;  

    switch (actionName) {  

      case "Your_Custom_Action1":     

        response = yourClassObject.Your_Custom_Action2(Parameters....);    

        break;  

  

       case "Your_Custom_Action2":  

        response = yourClassObject.Your_Custom_Action2(Parameters....);  

        break;  

  

        //Remaining custom Actions  

  

       default:  

       response = executeWebObject(action ,parameter ,yourClassObject, datalogger); 

 

      OR 

 

      response = executeMobileObject(action ,parameter ,yourClassObject,                                                 datalogger);       

       // ...Depending on the class which is extended by Custom Class       

 

       }  

  

        return response;  

  

    } 

 

  The user can define the Strings “Your_Custom_Action1” and “Your_Custom_Action2” in Actions class as constants. After that the user can use those constants instead of Strings. However, it is not mandatory. It is achieved by editing the Actions class as follows, 

Info

     public static final String YOUR_CUSTOM_ACTION1 = “Your_Custom_Action1"; 

     public static final String YOUR_CUSTOM_ACTION2 = “Your_Custom_Action2"; 

   

After adding the method in the required format , edit the switch block of ‘invoke’ method in the format given below, 

    

Info

  case "Your_Class_Name":  

        Your_Class_Name yourClassObject = new                                                                                Your_Class_Name();                     ... //create an instance of newly created class.  

        response = executeYour_Class_Name(executionContext, actionName, 

                               paramValues, yourClassObject, reportContext, response);   

                                                                   … //Calling the newly created method   

        break;  

 

 

Example:- 

Here is one brief example on writing custom Actions, showcasing how it was done in old version and how it is done in Qualitia 8.0.0 version. 

If a user wants to write a custom action for checking two strings are equal, he can do it as:  

Info

 

    In Older Versions before 8.0.0 :  

    public int EqualStrings(String a, String b)  

    {  

    if(a.equals(b))  

    {  

    DataLogger.writeToDebugAndInfoLogs("they are equal");  

    return 0;  

    }  

    else  

    {  

    DataLogger.writeToDebugAndInfoLogs("they are not equal");  

    return 1;  

    }  

    }  

  

    In Qualitia 8.0.0 Version :  

    public AcionResponse EqualStrings(String a, String b)  

    {  

    ActionResponse actionResponse = getActionResponse();  

    if(a.equals(b))  

    {  

    actionResponse.setMessage("they are equal");  

    actionResponse.setExecutionResult(ExecutionResult.PASSED);  

    return actionResponse;  

    }  

    else  

    {  

    actionResponse.setMessage("they are not                                                                                equal”,FailureCategories.Category.INVALID_DATA);  

    actionResponse.setExecutionResult(ExecutionResult.FAILED);  

    return actionResponse;  

    }  

    }