Structured Data Object Actions
assertJsonPathResultContains
Since: 3.0
Description: This function is used to validate that the value extracted from the JSON response contains the specified text.
Input Format : @Expected Text
| ObjectName | Action | Input | Condition | Reference | |
|---|---|---|---|---|---|
| structuredData Object | assertJsonPathResultContains |
@value | PageName | ||
| structuredData Object | assertJsonPathResultContains |
Sheet:Column | PageName | ||
| structuredData Object | assertJsonPathResultContains |
%dynamicVar% | PageName |
Inputs in the Input column can be either hardcoded (in this case the data is preceded by a "@"), passed from the datasheet (datasheet name : column name) or passed from a variable value (%variable name%), as given in the above example.
@Action(object = ObjectType.STRUCTUREDDATA, desc = "Assert JsonPath Result Contains ", input = InputType.YES)
public void assertJsonPathResultContains() {
try {
String response = responsebodies.get(key);
String jsonpath = Data;
String value = JsonPath.read(response, jsonpath).toString();
String strObj = getInputValue(Input);
if (value.contains(strObj)) {
Report.updateTestLog(Action, "Element text contains [" + strObj + "] is as expected", Status.PASSNS);
} else {
Report.updateTestLog(Action, "Element text [" + value + "] does not contain [" + strObj + "]",
Status.FAILNS);
}
} catch (Exception ex) {
Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
Report.updateTestLog(Action, "Error in validating JSON element :" + "\n" + ex.getMessage(), Status.DEBUG);
}
}
assertJsonPathResultNotContains
Since: 3.0
Description: This function is used to validate that the value extracted from the JSON does not contain the specified text.
Input Format : @Text that should NOT be present
| ObjectName | Action | Input | Condition | Reference | |
|---|---|---|---|---|---|
| structuredData Object | assertJsonPathResultNotContains |
@value | PageName | ||
| structuredData Object | assertJsonPathResultNotContains |
Sheet:Column | PageName | ||
| structuredData Object | assertJsonPathResultNotContains |
%dynamicVar% | PageName |
Inputs in the Input column can be either hardcoded (in this case the data is preceded by a "@"), passed from the datasheet (datasheet name : column name) or passed from a variable value (%variable name%), as given in the above example.
@Action(object = ObjectType.STRUCTUREDDATA, desc = "Assert JsonPath Result Not Contains ", input = InputType.YES)
public void assertJsonPathResultNotContains() {
try {
String response = responsebodies.get(key);
String jsonpath = Data;
String value = JsonPath.read(response, jsonpath).toString();
String strObj = getInputValue(Input);
if (!value.contains(strObj)) {
Report.updateTestLog(Action, "Element text [" + value + "] does not contain [" + strObj + "] as expected", Status.PASSNS);
} else {
Report.updateTestLog(Action, "Element text [" + value + "] contains [" + strObj + "] but should not",
Status.FAILNS);
}
} catch (Exception ex) {
Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
Report.updateTestLog(Action, "Error in validating JSON element :" + "\n" + ex.getMessage(), Status.DEBUG);
}
}
assertJsonPathResultEquals
Since: 3.0
Description: This function is used to validate that the value extracted from the JSON response exactly matches the expected text.
Input Format : @Expected Text
| ObjectName | Action | Input | Condition | Reference | |
|---|---|---|---|---|---|
| structuredData Object | assertJsonPathResultEquals |
@value | PageName | ||
| structuredData Object | assertJsonPathResultEquals |
Sheet:Column | PageName | ||
| structuredData Object | assertJsonPathResultEquals |
%dynamicVar% | PageName |
Inputs in the Input column can be either hardcoded (in this case the data is preceded by a "@"), passed from the datasheet (datasheet name : column name) or passed from a variable value (%variable name%), as given in the above example.
@Action(object = ObjectType.STRUCTUREDDATA, desc = "Assert JsonPath Result Equals ", input = InputType.YES)
public void assertJsonPathResultEquals() {
try {
String response = responsebodies.get(key);
String jsonpath = Data;
String value = JsonPath.read(response, jsonpath).toString();
String strObj = getInputValue(Input);
if (value.equals(strObj)) {
Report.updateTestLog(Action, "Element text [" + value + "] is as expected", Status.PASSNS);
} else {
Report.updateTestLog(Action, "Element text is [" + value + "] but is expected to be [" + strObj + "]",
Status.FAILNS);
}
} catch (Exception ex) {
Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
Report.updateTestLog(Action, "Error in validating JSON element :" + "\n" + ex.getMessage(), Status.DEBUG);
}
}
assertJsonPathResultNotEquals
Since: 3.0
Description: This function is used to validate that the value extracted from the JSON response does not exactly match the specified expected text.
Input Format : @Text that should NOT be present
| ObjectName | Action | Input | Condition | Reference | |
|---|---|---|---|---|---|
| structuredData Object | assertJsonPathResultNotEquals |
@value | PageName | ||
| structuredData Object | assertJsonPathResultNotEquals |
Sheet:Column | PageName | ||
| structuredData Object | assertJsonPathResultNotEquals |
%dynamicVar% | PageName |
Inputs in the Input column can be either hardcoded (in this case the data is preceded by a "@"), passed from the datasheet (datasheet name : column name) or passed from a variable value (%variable name%), as given in the above example.
@Action(object = ObjectType.STRUCTUREDDATA, desc = "Assert JsonPath Result Not Equals ", input = InputType.YES)
public void assertJsonPathResultNotEquals() {
try {
String response = responsebodies.get(key);
String jsonpath = Data;
String value = JsonPath.read(response, jsonpath).toString();
String strObj = getInputValue(Input);
if (!value.equals(strObj)) {
Report.updateTestLog(Action, "Element text [" + value + "] is not equal to [" + strObj + "] as expected", Status.PASSNS);
} else {
Report.updateTestLog(Action, "Element text is [" + value + "] but should not be equal to [" + strObj + "]",
Status.FAILNS);
}
} catch (Exception ex) {
Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
Report.updateTestLog(Action, "Error in validating JSON element :" + "\n" + ex.getMessage(), Status.DEBUG);
}
}
assertJsonPathResultCount
Since: 3.0
Description: This function is used to validate that the number of elements selected from JSON response matches the expected count. Supports both arrays and objects.
Input Format : @Expected Count
| ObjectName | Action | Input | Condition | Reference | |
|---|---|---|---|---|---|
| structuredData Object | assertJsonPathResultCount |
@value | PageName | ||
| structuredData Object | assertJsonPathResultCount |
Sheet:Column | PageName | ||
| structuredData Object | assertJsonPathResultCount |
%dynamicVar% | PageName |
Inputs in the Input column can be either hardcoded (in this case the data is preceded by a "@"), passed from the datasheet (datasheet name : column name) or passed from a variable value (%variable name%), as given in the above example.
@Action(object = ObjectType.STRUCTUREDDATA, desc = "Assert JsonPath Result Count ", input = InputType.YES)
public void assertJsonPathResultCount() {
try {
String response = responsebodies.get(key);
int actualObjectCount = 0;
JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(response);
String strObj = getInputValue(Input);
try {
Map<String, String> objectMap = JsonPath.read(json, Data);
actualObjectCount = objectMap.keySet().size();
} catch (Exception ex) {
try {
JSONArray objectMap = JsonPath.read(json, Data);
actualObjectCount = objectMap.size();
} catch (Exception ex1) {
try {
net.minidev.json.JSONArray objectMap = JsonPath.read(json, Data);
actualObjectCount = objectMap.size();
} catch (Exception ex2) {
String objectMap = JsonPath.read(json, Data);
actualObjectCount = 1;
}
}
}
int expectedObjectCount = Integer.parseInt(strObj);
if (actualObjectCount == expectedObjectCount) {
Report.updateTestLog(Action, "Element count [" + expectedObjectCount + "] is as expected", Status.PASSNS);
} else {
Report.updateTestLog(Action, "Element count is [" + actualObjectCount + "] but is expected to be [" + expectedObjectCount + "]", Status.FAILNS);
}
} catch (Exception ex) {
Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
Report.updateTestLog(Action, "Error in validating JSON element :" + "\n" + ex.getMessage(), Status.DEBUG);
}
}
storeJsonPathResultInVariable
Since: 3.0
Description: This function is used to extract a value from the JSON response and store it in a variable.
Input Format : %variableName%
| ObjectName | Action | Input | Condition | Reference | |
|---|---|---|---|---|---|
| structuredData Object | storeJsonPathResultInVariable |
%dynamicVar% | PageName |
@Action(object = ObjectType.STRUCTUREDDATA, desc = "Store JsonPath Result", input = InputType.YES)
public void storeJsonPathResultInVariable() {
try {
String variableName = Input;
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);
}
}
storeJsonPathResultInDataSheet
Since: 3.0
Description: This function is used to extract a value from the JSON response and store it in a datasheet.
Input Format : Sheet:Column
| ObjectName | Action | Input | Condition | Reference | |
|---|---|---|---|---|---|
| structuredData Object | storeJsonPathResultInDataSheet |
Sheet:Column | PageName |
@Action(object = ObjectType.STRUCTUREDDATA, desc = "Store JsonPath Result In DataSheet ", input = InputType.YES)
public void storeJsonPathResultInDataSheet() {
try {
String dataSheetReference = Input;
if (dataSheetReference.matches(".*:.*")) {
try {
System.out.println("Updating value in SubIteration " + userData.getSubIteration());
String sheetName = dataSheetReference.split(":", 2)[0];
String columnName = dataSheetReference.split(":", 2)[1];
String response = responsebodies.get(key);
String jsonpath = Data;
String value = JsonPath.read(response, jsonpath).toString();
userData.putData(sheetName, columnName, value);
Report.updateTestLog(Action, "Element text [" + value + "] is stored in " + dataSheetReference, 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);
}
}
storeJsonPathResultCountInVariable
Since: 3.0
Description: This function is used to select elements from the JSON response, count them, and store the resulting count in a variable.
Input Format : %variableName%
| ObjectName | Action | Input | Condition | Reference | |
|---|---|---|---|---|---|
| structuredData Object | storeJsonPathResultCountInVariable |
%dynamicVar% | PageName |
@Action(object = ObjectType.STRUCTUREDDATA, desc = "Store JsonPath Result count in variable ", input = InputType.YES)
public void storeJsonPathResultCountInVariable() {
try {
String varName = Input;
if (varName.matches("%.*%")) {
try {
System.out.println("Updating value in SubIteration " + userData.getSubIteration());
String actualObjectCount = Integer.toString(getJsonElementCount());
addVar(varName, actualObjectCount);
Report.updateTestLog(Action, "Element count [" + actualObjectCount + "] is stored in " + varName,
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);
}
}
storeJsonPathResultCountInDataSheet
Since: 3.0
Description: This function is used to select elements from the JSON response, count them, and store the resulting count in a datasheet.
Input Format : Sheet:Column
| ObjectName | Action | Input | Condition | Reference | |
|---|---|---|---|---|---|
| structuredData Object | storeJsonPathResultCountInDataSheet |
Sheet:Column | PageName |
@Action(object = ObjectType.STRUCTUREDDATA, desc = "Store JsonPath Result count in Datasheet ", input = InputType.YES)
public void storeJsonPathResultCountInDataSheet() {
try {
String dataSheetReference = Input;
if (dataSheetReference.matches(".*:.*")) {
try {
System.out.println("Updating value in SubIteration " + userData.getSubIteration());
String sheetName = dataSheetReference.split(":", 2)[0];
String columnName = dataSheetReference.split(":", 2)[1];
String actualObjectCount = Integer.toString(getJsonElementCount());
userData.putData(sheetName, columnName, actualObjectCount);
Report.updateTestLog(Action, "Element count [" + actualObjectCount + "] is stored in " + dataSheetReference,
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);
}
}
assertXmlPathResultContains
Since: 3.0
Description: This function is used to validate that the value extracted from the XML response contains the specified text.
Input Format : @Expected Text
| ObjectName | Action | Input | Condition | Reference | |
|---|---|---|---|---|---|
| structuredData Object | assertXmlPathResultContains |
@value | PageName | ||
| structuredData Object | assertXmlPathResultContains |
Sheet:Column | PageName | ||
| structuredData Object | assertXmlPathResultContains |
%dynamicVar% | PageName |
Inputs in the Input column can be either hardcoded (in this case the data is preceded by a "@"), passed from the datasheet (datasheet name : column name) or passed from a variable value (%variable name%), as given in the above example.
@Action(object = ObjectType.STRUCTUREDDATA, desc = "Assert XmlPath Result Contains ", input = InputType.YES)
public void assertXmlPathResultContains() {
try {
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();
String expression = Data;
NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(doc, XPathConstants.NODESET);
Node nNode = nodeList.item(0);
String value = nNode.getNodeValue();
String inputValue = getInputValue(Input);
if (value.contains(inputValue)) {
Report.updateTestLog(Action, "Element text contains [" + inputValue + "] is as expected", Status.PASSNS);
} else {
Report.updateTestLog(Action, "Element text [" + value + "] does not contain [" + inputValue + "]",
Status.FAILNS);
}
} catch (IOException | ParserConfigurationException | XPathExpressionException | DOMException
| SAXException ex) {
Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
Report.updateTestLog(Action, "Error validating XML element :" + "\n" + ex.getMessage(), Status.DEBUG);
}
}
assertXmlPathResultNotContains
Since: 3.0
Description: This function is used to validate that the value extracted from the XML does not contain the specified text.
Input Format : @Text that should NOT be present
| ObjectName | Action | Input | Condition | Reference | |
|---|---|---|---|---|---|
| structuredData Object | assertXmlPathResultNotContains |
@value | PageName | ||
| structuredData Object | assertXmlPathResultNotContains |
Sheet:Column | PageName | ||
| structuredData Object | assertXmlPathResultNotContains |
%dynamicVar% | PageName |
Inputs in the Input column can be either hardcoded (in this case the data is preceded by a "@"), passed from the datasheet (datasheet name : column name) or passed from a variable value (%variable name%), as given in the above example.
@Action(object = ObjectType.STRUCTUREDDATA, desc = "Assert XmlPath Result Not Contains ", input = InputType.YES)
public void assertXmlPathResultNotContains() {
try {
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();
String expression = Data;
NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(doc, XPathConstants.NODESET);
Node nNode = nodeList.item(0);
String value = nNode.getNodeValue();
if (!value.contains(Input)) {
Report.updateTestLog(Action, "Element text [" + value + "] does not contain [" + Input + "] as expected", Status.PASSNS);
} else {
Report.updateTestLog(Action, "Element text [" + value + "] contains [" + Input + "] but should not",
Status.FAILNS);
}
} catch (IOException | ParserConfigurationException | XPathExpressionException | DOMException
| SAXException ex) {
Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
Report.updateTestLog(Action, "Error validating XML element :" + "\n" + ex.getMessage(), Status.DEBUG);
}
}
assertXmlPathResultEquals
Since: 3.0
Description: This function is used to validate that the value extracted from the XML response exactly matches the expected text.
Input Format : @Expected Text
| ObjectName | Action | Input | Condition | Reference | |
|---|---|---|---|---|---|
| structuredData Object | assertXmlPathResultEquals |
@value | PageName | ||
| structuredData Object | assertXmlPathResultEquals |
Sheet:Column | PageName | ||
| structuredData Object | assertXmlPathResultEquals |
%dynamicVar% | PageName |
Inputs in the Input column can be either hardcoded (in this case the data is preceded by a "@"), passed from the datasheet (datasheet name : column name) or passed from a variable value (%variable name%), as given in the above example.
@Action(object = ObjectType.STRUCTUREDDATA, desc = "Assert XmlPath Result Equals ", input = InputType.YES)
public void assertXmlPathResultEquals() {
try {
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();
String expression = Data;
NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(doc, XPathConstants.NODESET);
Node nNode = nodeList.item(0);
String value = nNode.getNodeValue();
String inputValue = getInputValue(Input);
if (value.equals(inputValue)) {
Report.updateTestLog(Action, "Element text [" + value + "] is as expected", Status.PASSNS);
} else {
Report.updateTestLog(Action, "Element text [" + value + "] is not as expected. " + Data, Status.FAILNS);
}
} catch (IOException | ParserConfigurationException | XPathExpressionException | DOMException
| SAXException ex) {
Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
Report.updateTestLog(Action, "Error validating XML element :" + "\n" + ex.getMessage(), Status.DEBUG);
}
}
assertXmlPathResultNotEquals
Since: 3.0
Description: This function is used to validate that the value extracted from the XML response does not exactly match the specified expected text.
Input Format : @Text that should NOT be present
| ObjectName | Action | Input | Condition | Reference | |
|---|---|---|---|---|---|
| structuredData Object | assertXmlPathResultNotEquals |
@value | PageName | ||
| structuredData Object | assertXmlPathResultNotEquals |
Sheet:Column | PageName | ||
| structuredData Object | assertXmlPathResultNotEquals |
%dynamicVar% | PageName |
Inputs in the Input column can be either hardcoded (in this case the data is preceded by a "@"), passed from the datasheet (datasheet name : column name) or passed from a variable value (%variable name%), as given in the above example.
@Action(object = ObjectType.STRUCTUREDDATA, desc = "Assert XmlPath Result Not Equals ", input = InputType.YES)
public void assertXmlPathResultNotEquals() {
try {
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();
String expression = Data;
NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(doc, XPathConstants.NODESET);
Node nNode = nodeList.item(0);
String value = nNode.getNodeValue();
String inputValue = getInputValue(Input);
if (!value.equals(inputValue)) {
Report.updateTestLog(Action, "Element text [" + value + "] is not equal to [" + inputValue + "] as expected", Status.PASSNS);
} else {
Report.updateTestLog(Action, "Element text [" + value + "] should not be equal to [" + inputValue + "]", Status.FAILNS);
}
} catch (IOException | ParserConfigurationException | XPathExpressionException | DOMException
| SAXException ex) {
Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, ex);
Report.updateTestLog(Action, "Error validating XML element :" + "\n" + ex.getMessage(), Status.DEBUG);
}
}
storeXmlPathResultInVariable
Since: 3.0
Description: This function is used to extract a value from the XML response and store it in a variable.
Input Format : %variableName%
| ObjectName | Action | Input | Condition | Reference | |
|---|---|---|---|---|---|
| structuredData Object | storeXmlPathResultInVariable |
%dynamicVar% | PageName |
@Action(object = ObjectType.STRUCTUREDDATA, desc = "Store XmlPath Result", input = InputType.YES)
public void storeXmlPathResultInVariable() {
try {
String variableName = Input;
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);
}
}
storeXmlPathResultInDataSheet
Since: 3.0
Description: This function is used to extract a value from the XML response and store it in a datasheet.
Input Format : Sheet:Column
| ObjectName | Action | Input | Condition | Reference | |
|---|---|---|---|---|---|
| structuredData Object | storeXmlPathResultInDataSheet |
Sheet:Column | PageName |
@Action(object = ObjectType.STRUCTUREDDATA, desc = "Store XmlPath Result In DataSheet ", input = InputType.YES)
public void storeXmlPathResultInDataSheet() {
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 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();
String expression = Data;
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);
}
}