API Testing Actions
addHeader
Description: This function is used to add a header for a Rest/SOAP API request.
Input Format : @HeaderName
=HeaderValue
ObjectName | Action | Input | Condition | Reference | |
---|---|---|---|---|---|
Webservice | addHeader |
@HeaderName =HeaderValue |
|||
Webservice | addHeader |
Sheet:Column containing HeaderName =HeaderValue |
|||
Webservice | addHeader |
%dynamicVar% containing HeaderName =HeaderValue |
|||
Webservice | addHeader |
@HeaderName ={SheetName:ColumnName} |
|||
Webservice | addHeader |
@HeaderName =%dynamicVar% |
This function adds all the Headers into a HashMap headerlist
. Then those are applied to the request as :
@Action(object = ObjectType.WEBSERVICE, desc = "Add Header ", input = InputType.YES)
public void addHeader() {
try {
List<String> sheetlist = Control.getCurrentProject().getTestData().getTestDataFor(Control.exe.runEnv())
.getTestDataNames();
for (int sheet = 0; sheet < sheetlist.size(); sheet++) {
if (Data.contains("{" + sheetlist.get(sheet) + ":")) {
com.ing.datalib.testdata.model.TestDataModel tdModel = Control.getCurrentProject().getTestData()
.getTestDataByName(sheetlist.get(sheet));
List<String> columns = tdModel.getColumns();
for (int col = 0; col < columns.size(); col++) {
if (Data.contains("{" + sheetlist.get(sheet) + ":" + columns.get(col) + "}")) {
Data = Data.replace("{" + sheetlist.get(sheet) + ":" + columns.get(col) + "}",
userData.getData(sheetlist.get(sheet), columns.get(col)));
}
}
}
}
Collection<Object> valuelist = Control.getCurrentProject().getProjectSettings().getUserDefinedSettings()
.values();
for (Object prop : valuelist) {
if (Data.contains("{" + prop + "}")) {
Data = Data.replace("{" + prop + "}", prop.toString());
}
}
if (headers.containsKey(key)) {
headers.get(key).add(Data);
} else {
ArrayList<String> toBeAdded = new ArrayList<String>();
toBeAdded.add(Data);
headers.put(key, toBeAdded);
}
Report.updateTestLog(Action, "Header added " + Data, Status.DONE);
} catch (Exception ex) {
Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
Report.updateTestLog(Action, "Error adding Header :" + "\n" + ex.getMessage(), Status.DEBUG);
}
}
addURLParam
Description: This function is used to add the parameters in your URL in a key value pair (as query strings or URL query parameters)
ObjectName | Action | Input | Condition | Reference |
---|---|---|---|---|
Webservice | addURLParam |
@key=value |
@Action(object = ObjectType.WEBSERVICE, desc = "Add Parameters ", input = InputType.YES)
public void addURLParam() {
try {
if (urlParams.containsKey(key)) {
urlParams.get(key).add(Data);
} else {
ArrayList<String> toBeAdded = new ArrayList<String>();
toBeAdded.add(Data);
urlParams.put(key, toBeAdded);
}
Report.updateTestLog(Action, "URl Param added " + Data, Status.DONE);
} catch (Exception ex) {
Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
Report.updateTestLog(Action, "Error adding Header :" + "\n" + ex.getMessage(), Status.DEBUG);
}
}
setEndPoint
Description: This function is used to set the End Point for a Rest/SOAP API.
Input Format : @EndPoint
ObjectName | Action | Input | Condition | Reference | |
---|---|---|---|---|---|
Webservice | setEndPoint |
@Endpoint (from Editor) | #apiConfigAlias (optional) | ||
Webservice | setEndPoint |
Sheet:Column | #apiConfigAlias (optional) | ||
Webservice | setEndPoint |
%dynamicVar% | #apiConfigAlias (optional) |
Inputs in the Input column can be either hardcoded
, passed inside the Endpoint editor which is capable of parameterising the Endpoint (Press ctrl+space to see the list of variables available ), passed from the data sheet (datasheet name : column name
) or passed from a variable value (%variable name%
), as given in the above example.
Performs opening of URL Connection
@Action(object = ObjectType.WEBSERVICE, desc = "Set End Point ", input = InputType.YES, condition = InputType.OPTIONAL)
public void setEndPoint() {
try {
String apiConfigName = Condition;
DriverProperties driverProperties = Control.getCurrentProject().getProjectSettings().getDriverSettings();
if (apiConfigName.startsWith("#")) {
apiConfigName = apiConfigName.replace("#", "");
} else {
apiConfigName = ""; //This means that the Condtion is not an API Config Alias
}
String configToLoad = driverProperties.doesAPIconfigExist(apiConfigName) ? apiConfigName : "default";
driverProperties.setCurrLoadedAPIConfig(configToLoad);
String resource = handlePayloadorEndpoint(Data);
endPoints.put(key, resource);
httpAgentCheck();
OpenURLconnection();
Report.updateTestLog(Action, "End point set : " + resource, Status.DONE);
} catch (FileNotFoundException ex) {
Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
Report.updateTestLog(Action, "Error setting the end point :" + "\n" + ex.getMessage(), Status.DEBUG);
}
}
closeConnection
Description: This function is used to close a connection for a Rest/SOAP API request.
ObjectName | Action | Input | Condition | Reference |
---|---|---|---|---|
Webservice | closeConnection |
Performs disconnection of the URL connection
@Action(object = ObjectType.WEBSERVICE, desc = "Close the connection ", input = InputType.NO)
public void closeConnection() {
try {
// httpConnections.get(key).disconnect();
headers.remove(key);
responsebodies.remove(key);
basicAuthorization = "";
responsecodes.remove(key);
responsemessages.remove(key);
endPoints.remove(key);
Report.updateTestLog(Action, "Connection is closed", Status.DONE);
} catch (Exception ex) {
Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
Report.updateTestLog(Action, "Error closing connection :" + "\n" + ex.getMessage(), Status.DEBUG);
}
}
postSoapRequest
Description: This function is used to perform POST action on a SOAP API.
Input Format : @Expected Payload
ObjectName | Action | Input | Condition | Reference | |
---|---|---|---|---|---|
Webservice | postSoapRequest |
@Payload (from Editor) | |||
Webservice | postSoapRequest |
Sheet:Column | |||
Webservice | postSoapRequest |
%dynamicVar% |
Inputs in the Input column can be either hardcoded
, passed inside the XML editor which is capable of parameterising the Payload (Press ctrl+space to see the list of variables available ), passed from the data sheet (datasheet name : column name
) or passed from a variable value (%variable name%
), as given in the above example.
postRestRequest
Description: This function is used to perform POST action on a Rest API.
Input Format : @Expected Payload
ObjectName | Action | Input | Condition | Reference | |
---|---|---|---|---|---|
Webservice | postRestRequest |
@Payload (from Editor) | |||
Webservice | postRestRequest |
Sheet:Column | |||
Webservice | postRestRequest |
%dynamicVar% |
Inputs in the Input column can be either hardcoded
, passed inside the JSON editor which is capable of parameterising the Payload (Press ctrl+space to see the list of variables available ), passed from the data sheet (datasheet name : column name
) or passed from a variable value (%variable name%
), as given in the above example.
putRestRequest
Description: This function is used to perform PUT action on a Rest API.
Input Format : @Expected Payload
ObjectName | Action | Input | Condition | Reference | |
---|---|---|---|---|---|
Webservice | putRestRequest |
@Payload (from Editor) | |||
Webservice | putRestRequest |
Sheet:Column | |||
Webservice | putRestRequest |
%dynamicVar% |
Inputs in the Input column can be either hardcoded
, passed inside the JSON editor which is capable of parameterising the Payload (Press ctrl+space to see the list of variables available ), passed from the data sheet (datasheet name : column name
) or passed from a variable value (%variable name%
), as given in the above example.
patchRestRequest
Description: This function is used to perform PATCH action on a Rest API.
Input Format : @Expected Payload
ObjectName | Action | Input | Condition | Reference | |
---|---|---|---|---|---|
Webservice | patchRestRequest |
@Payload (from Editor) | |||
Webservice | patchRestRequest |
Sheet:Column | |||
Webservice | patchRestRequest |
%dynamicVar% |
Inputs in the Input column can be either hardcoded
, passed inside the XML editor which is capable of parameterising the Payload (Press ctrl+space to see the list of variables available ), passed from the data sheet (datasheet name : column name
) or passed from a variable value (%variable name%
), as given in the above example.
getRestRequest
Description: This function is used to perform GET action on a Rest API.
ObjectName | Action | Input | Condition | Reference |
---|---|---|---|---|
Webservice | getRestRequest |
deleteRestRequest
Description: This function is used to perform DELETE action on a Rest API.
ObjectName | Action | Input | Condition | Reference |
---|---|---|---|---|
Webservice | deleteRestRequest |
deleteWithPayload
Description: This function is used to perform DELETE action on a Rest API with payload.
ObjectName | Action | Input | Condition | Reference | |
---|---|---|---|---|---|
Webservice | deleteWithPayload |
@Payload (from Editor) | |||
Webservice | deleteWithPayload |
Sheet:Column | |||
Webservice | deleteWithPayload |
%dynamicVar% |
Inputs in the Input column can be either `hardcoded`, passed inside the **XML editor** which is capable of parameterising the Payload (Press ctrl+space to see the list of variables available ), passed from the data sheet (`datasheet name : column name`) or passed from a variable value (`%variable name%`), as given in the above example. | |