Nagravision_SA__1
12 years agoContributor
Loop on AssertionStatus of a REST GET Call not working
Hello,
I wrote a script to loop on a given testStep until the assertionStatus is valid or a specified time out occur.
In this case, I am checking a on GET REST Response until a status has been reached. The Mockup Service reply the content of a property.
- If I give the correct response and run the script, the AssertionStatus return VALID and I leave the loop succesfully.
- If i give the incorrect response and rune the script, the Loop check periodically for the response. I the supply the correct response in the property, but the AssertionStatus remains FAILED.
- if right after I stop the script and run it again .. it works properly.
Can you advise whyn the AssertionStatus is not set properly in the loop ??
The same problem is true if instead of calling a mock service, i am calling a web service (SOAP) waiting for a STARTED status to be returned (basically telling me the server is up and running).
Loop send me UNKNOWN assert status, since the web service is not available to start with, but never get me the VALID status, even after the service is up and running...
I wrote a script to loop on a given testStep until the assertionStatus is valid or a specified time out occur.
In this case, I am checking a on GET REST Response until a status has been reached. The Mockup Service reply the content of a property.
- If I give the correct response and run the script, the AssertionStatus return VALID and I leave the loop succesfully.
- If i give the incorrect response and rune the script, the Loop check periodically for the response. I the supply the correct response in the property, but the AssertionStatus remains FAILED.
- if right after I stop the script and run it again .. it works properly.
Can you advise whyn the AssertionStatus is not set properly in the loop ??
The same problem is true if instead of calling a mock service, i am calling a web service (SOAP) waiting for a STARTED status to be returned (basically telling me the server is up and running).
Loop send me UNKNOWN assert status, since the web service is not available to start with, but never get me the VALID status, even after the service is up and running...
import com.eviware.soapui.model.testsuite.Assertable.AssertionStatus;
import org.apache.commons.lang.time.StopWatch
def long timeout = 0
def String callingTestSuite
def String callingTestCase
def testStepToRun
boolean success = false
boolean wait = true
// Initialising external properties
try {
timeout = testRunner.testCase.getPropertyValue("timeOutInMs").toLong()
} catch (Throwable e) {
log.error('Missing timeOutInMs Property. Please check Testcase '+testRunner.testCase.getLabel())
assert false, 'Missing timeOutInMs Property. Please check Testcase '+testRunner.testCase.getLabel()
}
try {
callingTestSuite = testRunner.testCase.getPropertyValue("callingTestSuite")
} catch (Throwable e) {
log.error('Missing callingTestSuite Property. Please check Testcase '+testRunner.testCase.getLabel())
assert false, 'Missing callingTestSuite Property. Please check Testcase '+testRunner.testCase.getLabel()
}
try {
callingTestCase = testRunner.testCase.getPropertyValue("callingTestCase")
} catch (Throwable e) {
log.error('Missing callingTestCase Property. Please check Testcase '+testRunner.testCase.getLabel())
assert false, 'Missing callingTestCase Property. Please check Testcase '+testRunner.testCase.getLabel()
}
try {
stepName = testRunner.testCase.getPropertyValue("testStepNameToRun")
} catch (Throwable e) {
log.error('Missing testStepNameToRun Property. Please check Testcase '+testRunner.testCase.getLabel())
assert false, 'Missing testStepNameToRun Property. Please check Testcase '+testRunner.testCase.getLabel()
}
if (stepName != null) {
try {
testStepToRun = testRunner.testCase.getProject().getTestSuiteByName(callingTestSuite).getTestCaseByName(callingTestCase).getTestStepByName(stepName)
} catch (Throwable e) {
log.error('Could not found test Step named '+ stepName +' in '+ testRunner.testCase.getProject().getName() +'/'+ callingTestSuite + '/' + callingTestCase)
assert false, 'Could not found test Step named '+ stepName +' in '+ testRunner.testCase.getProject().getName() +'/'+ callingTestSuite + '/' + callingTestCase
}
// Initialise stopWatch
StopWatch stopWatch = new StopWatch()
stopWatch.start()
log.info ('Calling ' + testStepToRun.getLabel() + ' until timeout (' +timeout+ 'ms) or success')
while(!(success) && wait) {
// Rune the provided test step
testRunner.runTestStep(testStepToRun)
// Check assertion status
success = testStepToRun.getAssertionStatus() == AssertionStatus.VALID
log.info "[LOOP] Assert Status :"+ testStepToRun.getAssertionStatus()
wait = stopWatch.getTime() <= timeout
if(!wait) {
log.error(stepName +" could not be treated in the given timeout (${timeout}) ms.")
}
if(success) {
log.info(stepName +" finished succesfully.")
}
sleep(1000)
}
stopWatch.stop()
} else {
log.error('The stepName property cannot be null when calling API method '+testRunner.testCase.getProject().getName() +'/'+ callingTestSuite + '/' + callingTestCase)
assert false, 'The stepName property cannot be null when calling API method '+testRunner.testCase.getProject().getName() +'/'+ callingTestSuite + '/' + callingTestCase
}