Forum Discussion
> Is this what you wanted?
Not quite yet. I would like to find a way to include placeholders representing default properties of test-suite and test-case into the expected content, i.e. into the string that one puts into the "Content"-field of a "Contains Assertion".
Right now, I know how to include project properties there, e.g. using:
some text ${#Project#foobar} some more text
But that only works with Custom Properties! What do I have to write to e.g. include the name of the TestCase (i.e. the value of the "Name" property from the TestCase's "TestCase Properties"-tab) into that field?
Hope, I could make myself clear...
Ok, hopefully this is what you mean (ellaborating on the second part of what I said before), see how you find this approach:
1. You'll need to reference the testRunner object prior to the Request and Assertion, so create a Groovy TestStep for this:
2. Use the syntax below to assign the value of the TestStep object's name to a context property (testCaseName):
3. Insert the context property into the constains Assertion using the usual syntax:
4. Run the TestCase and the Assertion should check for the text (including the contents of testCaseName) - Note you need to run the whole TestCase rather than just the Request TestStep, otherwise the context property testCaseName wont be present.
Any good?
Cheers,
Rup
- nmrao9 years agoChampion Level 3
If I understand right, mmoser18 is looking for way to access the standard properties from script assertion, then here is the way to go:
To access project name from script assertsion
context.testCase.testSuite.project.name
Similarly- To access test case name
context.testCase.name
- To access test suite name
context.testCase.testSuite.name
Just this is for the information - when you open script assertion, top right corner, the editor shows the available variables where testRunner is not available there which is the reason you could see null. Also if you see groovy script step editor, it shows testRunner on top of it so that is accessible there as Rup mentioned.Don't be astonished, the same above snippets work from groovy script test step as well.
Hope this helps.
EDIT:
Just went thru the post in detail once again, found that you need to do contains assertion, could not try exactly what you want. But the same can be achieved by using script assertion.
Here is code snippet to make a contains assertion to see if the response contains the value of Project Property - Script Language i.e Groovy
def stdProjectPropValue = context.testCase.testSuite.project.defaultScriptLanguage
def responseText = messageExchange.responseContent
assert responseText.contains(stdProjectPropValue), "Response does not contain ${stdProjectPropValue}"
Related Content
- 9 months agoroopepaajanen
- 5 years agoforX