使用Groovy Script

时间:2017-07-20 15:07:46

标签: json grails soap groovy

我正在发送JSON文件作为请求,并使用Groovy脚本为Rest Project在soap UI工具中获取响应。

但我在第2步中发现错误,因为它没有检索JSON文件的内容。以下是我的代码。

步骤:

  1. 从json文件中检索数据
  2. 来自json文件的
  3. 内容应放在body(参数)中,发送请求并获得响应
  4. 响应应将其传递给json文件并验证响应
  5. 第1步(脚本)

    File file1 = new File("C:\\GroovyTest\\requests\\aaa.json")     
    List textLine = file1.readLines()          
    log.info textLine     
    context.put('textLine', textLine)      
    log.info textLine     
    

    第2步(脚本)

    ${=new File("C:\\GroovyTest\\requests\\"+(context.get('filelist')).last()).text)     
    

    Step3(脚本)

    def fileList = context.get('fileList')    
    if (fileList != null)    
    {    
     def fileName = fileList.pop()    
    
    def newname = fileName[0..-5]    
    
    def response = context.expand( '${Step2#Response}' )    
    def f = new File("C:\\GroovyTest\\responses\\${fileName}_Response.xml")    
    f.write(response, "UTF-8")     
    
    if(fileList.size() >0)     
    {
     testRunner.gotoStepByName("Step2")     
    }
    }
    

0 个答案:

没有答案