Skip to content

Store Actions

storeResponseBodyInDataSheet

Description: This function is used to store the response body of SOAP/REST request, into a respective column of a given datasheet.

Input Format : @Expected DatasheetName:ColumnName

ObjectName Action Input Condition Reference
Webservice 🟢 storeResponseBodyInDataSheet Sheet:Column ⬅ Datasheet where value is supposed to be stored

Note: Ensure that your data sheet doesn't contain column names with spaces.

@Action(object = ObjectType.WEBSERVICE, desc = "Store Response Message In DataSheet ", input = InputType.YES)
    public void storeResponseBodyInDataSheet() {
        try {
            String strObj = Input;
            if (strObj.matches(".*:.*")) {
                try {
                    System.out.println("Updating value in SubIteration " + userData.getSubIteration());
                    String sheetName = strObj.split(":", 2)[0];
                    String columnName = strObj.split(":", 2)[1];
                    userData.putData(sheetName, columnName, responsebodies.get(key));
                    Report.updateTestLog(Action, "Response body is stored in " + strObj, Status.DONE);
                } catch (Exception ex) {
                    Logger.getLogger(this.getClass().getName()).log(Level.OFF, ex.getMessage(), ex);
                    Report.updateTestLog(Action, "Error Storing text in datasheet :" + ex.getMessage(), Status.DEBUG);
                }
            } else {
                Report.updateTestLog(Action,
                        "Given input [" + Input + "] format is invalid. It should be [sheetName:ColumnName]",Status.DEBUG);
            }
        } catch (Exception ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
            Report.updateTestLog(Action, "Error Storing response body in datasheet :" + "\n" + ex.getMessage(),Status.DEBUG);
        }
    }

storeXMLelement

Description: This function is used to store a certain XML tag value inside the response body of SOAP request, into a variable.

Input Format : @XPath of the tag

Condition Format: %variable%

ObjectName Action Input Condition Reference
Webservice 🟢 storeXMLelement @XPath %var% ⬅ Hardcoded Input
Webservice 🟢 storeXMLelement Sheet:Column containing XPath %var% ⬅ Input from Datasheet
Webservice 🟢 storeXMLelement %Var% containing XPath %var% ⬅ Input from variable
@Action(object = ObjectType.WEBSERVICE, desc = "Store XML Element", input = InputType.YES, condition = InputType.YES)
    public void storeXMLelement() {
        try {
            String variableName = Condition;
            String expression = Data;
            if (variableName.matches("%.*%")) {
                DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
                DocumentBuilder dBuilder;
                InputSource inputSource = new InputSource();
                inputSource.setCharacterStream(new StringReader(responsebodies.get(key)));
                dBuilder = dbFactory.newDocumentBuilder();
                Document doc = dBuilder.parse(inputSource);
                doc.getDocumentElement().normalize();
                XPath xPath = XPathFactory.newInstance().newXPath();
                NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(doc, XPathConstants.NODESET);
                Node nNode = nodeList.item(0);
                String value = nNode.getNodeValue();
                addVar(variableName, value);
                Report.updateTestLog(Action, "XML element value stored", Status.DONE);
            } else {
                Report.updateTestLog(Action, "Variable format is not correct", Status.DEBUG);
            }
        } catch (IOException | ParserConfigurationException | XPathExpressionException | DOMException
                | SAXException ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
            Report.updateTestLog(Action, "Error Storing XML element :" + "\n" + ex.getMessage(), Status.DEBUG);
        }
    }

storeXMLelementInDataSheet

Description: This function is used to store a certain XML tag value inside the response body of SOAP request, into a respective column of a given datasheet.

Input Format : @Expected datasheet name:column name

Condition Format: XPath of the tag

ObjectName Action Input Condition Reference
Webservice 🟢 `storeXMLelementInDataSheet' Sheet:Column XPath << Datasheet to where value is supposed br stored

Note: Ensure that your data sheet doesn't contain column names with spaces.

@Action(object = ObjectType.WEBSERVICE, desc = "Store XML Element In DataSheet ", input = InputType.YES, condition = InputType.YES)
    public void storeXMLelementInDataSheet() {

        try {
            String strObj = Input;
            if (strObj.matches(".*:.*")) {
                try {
                    String expression = "";
                    System.out.println("Updating value in SubIteration " + userData.getSubIteration());
                    String sheetName = strObj.split(":", 2)[0];
                    String columnName = strObj.split(":", 2)[1];
                    String xmlText = responsebodies.get(key);
                    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
                    DocumentBuilder dBuilder;
                    InputSource inputSource = new InputSource();
                    inputSource.setCharacterStream(new StringReader(xmlText));
                    dBuilder = dbFactory.newDocumentBuilder();
                    Document doc = dBuilder.parse(inputSource);
                    doc.getDocumentElement().normalize();
                    XPath xPath = XPathFactory.newInstance().newXPath();
                    if (Condition.matches("%.*%"))
                        expression = getVar(Condition);
                    else
                        expression = Condition;
                    NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(doc, XPathConstants.NODESET);
                    Node nNode = nodeList.item(0);
                    String value = nNode.getNodeValue();
                    userData.putData(sheetName, columnName, value);
                    Report.updateTestLog(Action, "Element text [" + value + "] is stored in " + strObj, Status.DONE);
                } catch (IOException | ParserConfigurationException | XPathExpressionException | DOMException| SAXException ex) {
                    Logger.getLogger(this.getClass().getName()).log(Level.OFF, ex.getMessage(), ex);
                    Report.updateTestLog(Action, "Error Storing XML element in datasheet :" + "\n" + ex.getMessage(),Status.DEBUG);
                }
            } else {
                Report.updateTestLog(Action,
                        "Given input [" + Input + "] format is invalid. It should be [sheetName:ColumnName]",Status.DEBUG);
            }
        } catch (Exception ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
            Report.updateTestLog(Action, "Error Storing XML element in datasheet :" + "\n" + ex.getMessage(),Status.DEBUG);
        }

    }

storeJSONelement

Description: This function is used to store a certain JSON tag value from the response body of REST request, into a variable.

Input Format : @JSONPath of the tag

Condition Format: %variable%

ObjectName Action Input Condition Reference
Webservice 🟢 storeJSONelement @JSONPath %var% ⬅ Hardcoded Input
Webservice 🟢 storeJSONelement Sheet:Column containing JSONPath %var% ⬅ Input from Datasheet
Webservice 🟢 storeJSONelement %Var% containing JSONPath %var% ⬅ Input from variable
@Action(object = ObjectType.WEBSERVICE, desc = "Store JSON Element", input = InputType.YES, condition = InputType.YES)
    public void storeJSONelement() {
        try {
            String variableName = Condition;
            String jsonpath = Data;
            if (variableName.matches("%.*%")) {
                addVar(variableName, JsonPath.read(responsebodies.get(key), jsonpath).toString());
                Report.updateTestLog(Action, "JSON element value stored", Status.DONE);
            } else {
                Report.updateTestLog(Action, "Variable format is not correct", Status.DEBUG);
            }
        } catch (Exception ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
            Report.updateTestLog(Action, "Error Storing JSON element :" + "\n" + ex.getMessage(), Status.DEBUG);
        }
    }

storeJSONelementInDataSheet

Description: This function is used to store a certain JSON tag value inside the response body of REST request, into a respective column of a given datasheet.

Input Format : @Expected datasheet name:column name

Condition Format: JSONPath of the tag

ObjectName Action Input Condition Reference
Webservice 🟢 storeJSONelementInDataSheet Sheet:Column JSONPath << Datasheet to where value is supposed br stored

Note: Ensure that your data sheet doesn't contain column names with spaces.

@Action(object = ObjectType.WEBSERVICE, desc = "Store JSON Element In DataSheet ", input = InputType.YES, condition = InputType.YES)
    public void storeJSONelementInDataSheet() {

        try {
            String strObj = Input;
            if (strObj.matches(".*:.*")) {
                try {
                    System.out.println("Updating value in SubIteration " + userData.getSubIteration());
                    String sheetName = strObj.split(":", 2)[0];
                    String columnName = strObj.split(":", 2)[1];
                    String response = responsebodies.get(key);
                    String jsonpath = Condition;
                    String value = JsonPath.read(response, jsonpath).toString();
                    userData.putData(sheetName, columnName, value);
                    Report.updateTestLog(Action, "Element text [" + value + "] is stored in " + strObj, Status.DONE);
                } catch (Exception ex) {
                    Logger.getLogger(this.getClass().getName()).log(Level.OFF, ex.getMessage(), ex);
                    Report.updateTestLog(Action, "Error Storing JSON element in datasheet :" + "\n" + ex.getMessage(),
                            Status.DEBUG);
                }
            } else {
                Report.updateTestLog(Action,
                        "Given input [" + Input + "] format is invalid. It should be [sheetName:ColumnName]",
                        Status.DEBUG);
            }
        } catch (Exception ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
            Report.updateTestLog(Action, "Error Storing JSON element in datasheet :" + "\n" + ex.getMessage(),
                    Status.DEBUG);
        }
    }

storeJsonElementCount

Description: This function is used to store the count of JSON elements for a given JSON Path of REST request, into a variable.

Input Format : @JSONPath of the tag

Condition Format: %variable%

ObjectName Action Input Condition Reference
Webservice 🟢 storeJsonElementCount @JSONPath %var% ⬅ Hardcoded Input
Webservice 🟢 storeJsonElementCount Sheet:Column containing JSONPath %var% ⬅ Input from Datasheet
Webservice 🟢 storeJsonElementCount %Var% containing JSONPath %var% ⬅ Input from variable
@Action(object = ObjectType.WEBSERVICE, desc = "Store JSON Element count in variable ", input = InputType.YES, condition = InputType.YES)
    public void storeJsonElementCount() {

        try {
            String variableName = Condition;
            Condition = Data;

            if (variableName.matches("%.*%")) {
                try {
                    System.out.println("Updating value in SubIteration " + userData.getSubIteration());
                    int actualObjectCountInteger = 1;                                                       //getJsonElementCount();
                    String actualObjectCount = Integer.toString(actualObjectCountInteger);
                    addVar(variableName, actualObjectCount);
                    Report.updateTestLog(Action, "Element count [" + actualObjectCount + "] is stored in " + variableName,
                            Status.DONE);
                } catch (Exception ex) {
                    Logger.getLogger(this.getClass().getName()).log(Level.OFF, ex.getMessage(), ex);
                    Report.updateTestLog(Action, "Error Storing JSON element in Variable :" + "\n" + ex.getMessage(),
                            Status.DEBUG);
                }
            } else {
                Report.updateTestLog(Action,
                        "Given condition [" + Condition + "] format is invalid. It should be [%Var%]",
                        Status.DEBUG);
            }
        } catch (Exception ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
            Report.updateTestLog(Action, "Error Storing JSON element in Variable :" + "\n" + ex.getMessage(),
                    Status.DEBUG);
        }

    }

storeJsonElementCountInDataSheet

Description: This function is used to store in a datasheet the count of JSON elements for a given JSON Path of REST request.

Input Format : @Expected datasheet name:column name

Condition Format : JSON Path of the tag

ObjectName Action Input Condition Reference
Webservice 🟢 storeJsonElementCountInDataSheet Sheet:Column JSONPath ⬅ Datasheet where value is to be stored

Note: Ensure that your data sheet doesn't contain column names with spaces.

@Action(object = ObjectType.WEBSERVICE, desc = "Store JSON Element count in Datasheet ", input = InputType.YES, condition = InputType.YES)
    public void storeJsonElementCountInDataSheet() {

        try {
            String strObj = Input;
            if (strObj.matches(".*:.*")) {
                try {
                    System.out.println("Updating value in SubIteration " + userData.getSubIteration());
                    String sheetName = strObj.split(":", 2)[0];
                    String columnName = strObj.split(":", 2)[1];
                    int actualObjectCountInteger = 1;                                                                         //getJsonElementCount();
                    String actualObjectCount = Integer.toString(actualObjectCountInteger);
                    userData.putData(sheetName, columnName, actualObjectCount);
                    Report.updateTestLog(Action, "Element count [" + actualObjectCount + "] is stored in " + strObj,
                            Status.DONE);
                } catch (Exception ex) {
                    Logger.getLogger(this.getClass().getName()).log(Level.OFF, ex.getMessage(), ex);
                    Report.updateTestLog(Action, "Error Storing JSON element in datasheet :" + "\n" + ex.getMessage(),
                            Status.DEBUG);
                }
            } else {
                Report.updateTestLog(Action,
                        "Given input [" + Input + "] format is invalid. It should be [sheetName:ColumnName]",
                        Status.DEBUG);
            }
        } catch (Exception ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
            Report.updateTestLog(Action, "Error Storing JSON element in datasheet :" + "\n" + ex.getMessage(),
                    Status.DEBUG);
        }

    }

storeResponseCookiesInVariable

Description: This function is used to extract a specific cookie value from the HTTP response headers and store it in a variable.

Input Format: @Expected CookieName

Condition Format: %VariableName%

ObjectName Action Input Condition Reference
Webservice 🟢 storeResponseCookiesInVariable @CookieName %VariableName% ⬅ Store cookie value in variable
    @Action(object = ObjectType.WEBSERVICE, desc = "Store Cookies In Variable ", input = InputType.YES, condition = InputType.YES)
    public void storeResponseCookiesInVariable() {
        try {
            String cookieKey = Data;
            String variableName = Condition;

            if (!variableName.matches("%.*%")) {
                Report.updateTestLog(Action, "Variable format is not correct. Should be %variableName%", Status.DEBUG);
                return;
            }

            variableName = variableName.substring(1, variableName.length() - 1);

            if (!response.containsKey(key) && response.get(key) == null) {
                Report.updateTestLog(Action, "Response did not contain a valid HttpResponse for key [" + key + "]", Status.FAIL);
                return;
            }

            HttpResponse<?> httpResponse = response.get(key);
            HttpHeaders responseHeaders = httpResponse.headers();

            List<String> cookieHeaders = !responseHeaders.allValues("set-cookie").isEmpty() ? responseHeaders.allValues("set-cookie") : responseHeaders.allValues("Set-Cookie");

            if (cookieHeaders.isEmpty()) {
                Report.updateTestLog(Action, "No cookies were retrieved from the endpoint", Status.FAIL);
                return;
            }

            for (String cookieHeader : cookieHeaders) {
                if (cookieHeader == null || cookieHeader.isEmpty()) continue;

                String[] cookieParts = cookieHeader.split(";");
                if (cookieParts.length == 0) continue;

                String[] keyValue = cookieParts[0].trim().split("=", 2);
                if (keyValue.length != 2) continue;

                String cookieName  = keyValue[0].trim();
                String cookieValue = keyValue[1].trim();

                if (cookieName.equals(cookieKey)) {
                    addVar(variableName, cookieValue);
                    Report.updateTestLog(
                        Action,
                        "Cookies with name [" + cookieKey + "] has been added in variable [" 
                            + variableName + "] with value [" + cookieValue + "] ",
                        Status.DONE
                    );
                    return; // early exit on success
                }
            }
        } catch (Exception ex) {
            Report.updateTestLog(Action, "Error in storing cookies with name in variable :"+ex.getMessage(), Status.FAIL);
            ex.printStackTrace();
        }
    }

storeHeaderByNameInVariable

Description: This function is used to store a specific header value from the REST/SOAP response, into a variable.

Input Format : @Header Name

Condition Format: %variable%

ObjectName Action Input Condition Reference
Webservice 🟢 storeHeaderByNameInVariable @Header Name %var% ⬅ Hardcoded Input
@Action(object = ObjectType.WEBSERVICE, desc = "Store Header Element in Variable", input = InputType.YES, condition = InputType.YES)
public void storeHeaderByNameInVariable() {
    try {
        String variableName = Condition; // e.g., %Variable Name%
        String headerName = Data;        // e.g., "Content-Type"

        // storeAllHeadersInMap() will populate headerKeyValueMap with headers for the current scenario/test case (key)
        storeAllHeadersInMap();

        // Check if headers exist for this key
        if (!headerKeyValueMap.containsKey(key) || headerKeyValueMap.get(key).isEmpty()) {
            Report.updateTestLog(Action, "No headers found for scenario: [" + userData.getScenario() + "] and test case: [" + userData.getTestCase() + "]", Status.DEBUG);
            return;
        }

        // Get headers for this scenario
        Map<String, String> currentHeaders = headerKeyValueMap.get(key);

        // Check if requested header exists
        if (!currentHeaders.containsKey(headerName)) {
            Report.updateTestLog(Action, "Header '" + headerName + "' does not exist in available headers for scenario: [" + userData.getScenario() + "] and test case: [" + userData.getTestCase() + "]", Status.DEBUG);
            return;
        }

        // Validate variable format
        if (variableName.matches("%.*%")) {
            String headerValue = currentHeaders.get(headerName);
            addVar(variableName, headerValue);
            Report.updateTestLog(Action, "Header '" + headerName + "' stored in variable '" + variableName + "' with value: " + headerValue, Status.DONE);
        } else {
            Report.updateTestLog(Action, "Variable format is not correct", Status.DEBUG);
        }

    } catch (Exception ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        Report.updateTestLog(Action, "Error storing header value: " + ex.getMessage(), Status.DEBUG);
    }
}

storeHeaderByNameInDatasheet

Description: This function is used to store a specific header value from the REST/SOAP response, into a respective column of a given datasheet.

Input Format : @Expected datasheet name:column name

Condition Format : Header Name

ObjectName Action Input Condition Reference
Webservice 🟢 storeHeaderByNameInDatasheet Sheet:Column Header Name ⬅ Datasheet where value is to be stored

Note: Ensure that your data sheet doesn't contain column names with spaces.

@Action(object = ObjectType.WEBSERVICE, desc = "Store Header value in Datasheet", input = InputType.YES, condition = InputType.YES)
public void storeHeaderByNameInDatasheet() {
    try {
        String headerName = Condition; // e.g., "Content-Type"

        // First, populate maps for this scenario/test case
        storeAllHeadersInMap();

        // Check if headers exist for this key
        if (!headerKeyValueMap.containsKey(key) || headerKeyValueMap.get(key).isEmpty()) {
            Report.updateTestLog(Action, "No headers found for scenario: [" + userData.getScenario() + "] and test case: [" + userData.getTestCase() + "]", Status.DEBUG);
            return;
        }

        // Get headers for this scenario
        Map<String, String> currentHeaders = headerKeyValueMap.get(key);

        // Check if requested header exists
        if (!currentHeaders.containsKey(headerName)) {
            Report.updateTestLog(Action, "Header '" + headerName + "' does not exist in available headers for scenario: [" + userData.getScenario() + "] and test case: [" + userData.getTestCase() + "]", Status.DEBUG);
            return;
        }

        // Early return if input format is invalid
        if (!Input.matches(".*:.*")) {
            Report.updateTestLog(Action, "Invalid input format [" + Input + "]. Expected format: sheetName:ColumnName", Status.DEBUG);
            return;
        }

        try {
            String sheetName = Input.split(":", 2)[0];
            String columnName = Input.split(":", 2)[1];
            String headerValue = currentHeaders.get(headerName);

            // Store header value in datasheet
            userData.putData(sheetName, columnName, headerValue);

            Report.updateTestLog(Action, "Header value [" + headerValue + "] stored in datasheet [" + sheetName + ":" + columnName + "]", Status.DONE);
        } catch (Exception ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, ex.getMessage(), ex);
            Report.updateTestLog(Action, "Error storing header value in datasheet: " + ex.getMessage(), Status.DEBUG);
        }

    } catch (Exception ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        Report.updateTestLog(Action, "Error storing header value in datasheet: " + ex.getMessage(), Status.DEBUG);
    }
}