Forum Discussion

AAB's avatar
AAB
Regular Contributor
5 years ago

ReadyAPI- repeat teststep until desired response and then move on

Hi,

 

I have read a tread here on smartbear that interested me. nmrao had written a groovy code for someone.

I have adapted it to my script because I have a big latency on the receiving of a correct answer. Therefore I first added a 'delay' in the framework, but it still can take 10000ms before the logfile is documented and the HTTP request is loading this. That's why I was searching a better way to catch this.

My framework is like this:

If the response I'm expecting is not visible in GetFileFromPalDBMed it needs to rerun until that file is present. There is a big latency so I would let the Delay in it. But nevertheless have an extra code to rerun the previous HTTP step until the file is present.

 

I've adapted my code like such:

import groovy.xml.XmlSlurper
import groovy.json.JsonSlurper

def getID = testRunner.testCase.getPropertyValue("fsbTransId")
log.info getID
//read the http body without parsing as text. without headers
def response = context.expand( '${GetFileFromPalDBMed#Response}' )
log.info "response = " + response
//read text as xml file, then with jsonparser find folder

if(!response.contains(getID))
{
	def holder = new com.eviware.soapui.support.XmlHolder(response)
	if(holder){
		def isRetry = true
		while(isRetry){
			def state = holder.getNodeValue('/palngv3debug/download/20201021-162223-'+ getID + ".paldata")
			log.info "value of state in the response is ${state}"
			if(state == getID){
				log.info "Since the value is success, setting value of isRetry to false"
				isRetry = false
				}else {
					     log.info "Retrying as state is not success"
           				testRunner.runTestStepByName('GetFileFromPalDBMed')
					}
			}
		}
	}

def xml = new XmlSlurper().parseText(response)
xml.body.div[0].div[0].div[1].table.'*'.each {
	
	if (it.text().contains(getID) && it.text().contains(".paldata")) {
		log.info "Found it!!: surf to: https://fsb-adm1-int.names.belgium.be:8095/palngv3debug/download/" + it.text()
		def url = "https://fsb-adm1-int.names.belgium.be:8095/palngv3debug/download/" + it.text()
	testRunner.testCase.setPropertyValue("url", url)
	}
}
log.info "done"
//create other step to send the url, in that step assert that all id's are present

 

But apparently this peace of code that I've copied from this subject doesn't like the "@" character in the field. The logfiles are files that are created with random characters, thus my file can possibly contain an @ in it.

error:  

java.lang.RuntimeException: net.sf.saxon.trans.XPathException: XPath syntax error at char 50 in {...tqGwW4D@s0LaHSQ8QAAAFg.pald...}: Unexpected token "@" beyond end of expression error at line: 17

How can I solve this please?

 

The response is HTML page looking like this:

<html>
   <head>
      <meta charset="utf-8"/>
      <meta name="description" content=""/>
      <meta name="author" content=""/>
      <meta name="viewport" content="width=device-width, initial-scale=1"/>
      <link rel="stylesheet" href="/css/normalize.css"/>
      <link rel="stylesheet" href="/css/skeleton.css"/>
      <link rel="icon" type="image/png" href="../../html/images/favicon.png"/>
      <title>FSB INT PAL NG V3 debug interface</title>
   </head>
   <body>
      <div class="section" style="margin-top: 30px;">
         <div class="container">
            <h3>FSB INT PAL NG V3 debug interface</h3>
            <div class="u-full-width">
               <a href="palngv3debug.sh?action=get">
                  <input type="submit" class="button-primary" value="Refresh"/>
               </a>
               <a href="palngv3debug.sh?action=clear">
                  <input type="submit" class="button-primary" value="Clear"/>
               </a>
            </div>
            <h5>Debug files</h5>
            <div class="row">
               <table class="twelve columns">
                  <tr>
                     <td>
                        <a href="/palngv3debug/download/20201021-170205-X5BNbbAHZrmOAQA320OM6QAAAI0.paldata">20201021-170205-X5BNbbAHZrmOAQA320OM6QAAAI0.paldata</a>
                     </td>
                  </tr>
                  <tr>
                     <td>
                        <a href="/palngv3debug/download/20201021-170205-X5BNbbAHZrmOAQA320OM6QAAAI0.metadata">20201021-170205-X5BNbbAHZrmOAQA320OM6QAAAI0.metadata</a>
                     </td>
                  </tr>
                </table>
              </div>
            </div>
         </div>
     </body>
</html>

 

Thanks in advance,

AboveAndBeyond

  • AAB : You are getting error at Line no. 17 because there is a syntax error with '(inverted commas). Correct it and i think error will get resolved.

     

  • AAB : You are getting error at Line no. 17 because there is a syntax error with '(inverted commas). Correct it and i think error will get resolved.

     

    • AAB's avatar
      AAB
      Regular Contributor

      Hello HimanshuTayal 

       

      Thanks for your response. Sorry for the delay. It did indeed solve the problem.

      But the loop doesn't work. Could you fix this please? I think I need a "sleep" in or a counter somehow. I would suggest to put the counter on 5 max. Can you help me with that?

       

      Thanks in advance

      AboveAndBeyond.

      • HimanshuTayal's avatar
        HimanshuTayal
        Community Hero

        AAB : Just looked at your XML it's a html file and i don't think XMLSlurper will be able to extract data out of it.

         

        In getNodeValue you are giving href data which is not a node. So in order to get data from the HTML response you need to think of any other logic on how you can fetch data out of HTML.