Forum Discussion
- Cizo89Frequent ContributorHi mchelikani,
try this script, it should help you:
def xpathAssertion = testRunner.testCase.testSteps["name_of_your_step"].addAssertion("XPath Match")
xpathAssertion.setPath("your_xpath")
xpathAssertion.setExpectedContent("expected_result")
xpathAssertion.setName("your_required_name_xpath")
def containsAssertion = testRunner.testCase.testSteps["name_of_your_step"].addAssertion("Contains")
containsAssertion.setToken("your_expected_string")
containsAssertion.setName("your_required_name_contains")
Regards,
Marek - mchelikaniContributorThank you for the Reply!
Does "Contains" check for the Token in only the Value of Elements or Attributes or It even Checks the Elements and Attributes also?
I would like to check if an XPath Present(Exists) in Response( don't care about the value). Which Assertion Should I use and what is the groovy syntax? - Cizo89Frequent ContributorHi,
if you want to use the XPath Present(Exists) function, I'd say that XPath Match assertion would be better than simple Contains Assertion.
Use the script for creating XPath Assertion with these modifications:
xpathAssertion.setPath("exists(your_xpath)")
xpathAssertion.setExpectedContent("true")
You just have to put your XPath into function exists(), that should work fine for your requirements
Regards,
Marek - mchelikaniContributorThanks!