Forum Discussion
mchelikani
11 years agoContributor
I am adding Assertions dynamically by reading the assertions from File as below in the TestRunListener.beforeStep.
Could you please verify if there is anything wrong on the below code?
Do I have to set any parameter to print the complete assertion in the junit report?
I am running the project from maven.
/*
* Create Assertion
*/
def buildAssertion(row, testStep, testCase){
log.info("\n Xpath Assertion, Row Number :"+ row.getRowNum())
def xpath = row.getCell(0)
def xpathValue = row.getCell(1)
def xpathValidationType = row.getCell(2)
//Print the Row Values
log.info("XPATH :"+row.getCell(0))
log.info("XPATH_VALUE :"+row.getCell(1))
log.info("XPATH_VALIDATION_TYPE :"+row.getCell(2))
def assertionName = testCase.name + "_" + testStep.getLabel() +"_Assertion_" + row.getRowNum()
def assertion = testStep.addAssertion("XPath Match")
log.info("%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "+assertion)
assertion.name= assertionName
assertion.setIgnoreNamespaceDifferences(true)
if(xpathValidationType.getStringCellValue() == "1"){
assertion.path = "exists("+xpath.getStringCellValue()+")"
assertion.expectedContent = "true"
log.info("Added Xpath Existance Assertion :"+xpath + " to TestStep " + testStep.getLabel())
} else if (xpathValidationType.getStringCellValue() == "2"){
assertion.path = xpath.getStringCellValue()
assertion.expectedContent = xpathValue.getStringCellValue()
log.info("Added XPath Match Assertion :"+xpath + " to TestStep " + testStep.getLabel())
} else if (xpathValidationType.getStringCellValue() == "0"){
log.info("XPATH_VALIDATION_TYPE =" +xpathValidationType +".Hence Not Adding Assertion.")
}
}
Could you please verify if there is anything wrong on the below code?
Do I have to set any parameter to print the complete assertion in the junit report?
I am running the project from maven.
/*
* Create Assertion
*/
def buildAssertion(row, testStep, testCase){
log.info("\n Xpath Assertion, Row Number :"+ row.getRowNum())
def xpath = row.getCell(0)
def xpathValue = row.getCell(1)
def xpathValidationType = row.getCell(2)
//Print the Row Values
log.info("XPATH :"+row.getCell(0))
log.info("XPATH_VALUE :"+row.getCell(1))
log.info("XPATH_VALIDATION_TYPE :"+row.getCell(2))
def assertionName = testCase.name + "_" + testStep.getLabel() +"_Assertion_" + row.getRowNum()
def assertion = testStep.addAssertion("XPath Match")
log.info("%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "+assertion)
assertion.name= assertionName
assertion.setIgnoreNamespaceDifferences(true)
if(xpathValidationType.getStringCellValue() == "1"){
assertion.path = "exists("+xpath.getStringCellValue()+")"
assertion.expectedContent = "true"
log.info("Added Xpath Existance Assertion :"+xpath + " to TestStep " + testStep.getLabel())
} else if (xpathValidationType.getStringCellValue() == "2"){
assertion.path = xpath.getStringCellValue()
assertion.expectedContent = xpathValue.getStringCellValue()
log.info("Added XPath Match Assertion :"+xpath + " to TestStep " + testStep.getLabel())
} else if (xpathValidationType.getStringCellValue() == "0"){
log.info("XPATH_VALIDATION_TYPE =" +xpathValidationType +".Hence Not Adding Assertion.")
}
}