Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. //generate unique string and assign it to property based on step
  2. import net.sf.json.groovy.JsonSlurper
  3. import java.time.*
  4.  
  5. //defining variables
  6. def Destination_name
  7. def startdate
  8. def CreateProjectTestCase = context.testCase
  9. //Appending a random number to destination Name
  10. Destination_name = "Soap_UI" + String.valueOf(Math.abs(new Random().nextInt() % 600000) + 1)
  11. startdate=new Date().format( 'yyyy-MM-dd' )+ "T00:00:00.000"+ "+" + "0000"
  12. log.info startdate
  13. //Getting instance of the property file
  14. propTestStep_id= CreateProjectTestCase.getTestStepByName("Destinationname")
  15. propTestStep_id.setPropertyValue("destinationName",Destination_name)
  16. propTestStep_id.setPropertyValue("startDate",startdate)
  17. log.info Destination_name
  18.  
  19.  
  20. // extract json from step response and save it in a variable
  21.  
  22. import net.sf.json.groovy.JsonSlurper
  23. def CreateProjectTestCase = context.testCase
  24.  
  25. // Fetching json response
  26. def soapResponse = context.expand('${createdestination#Response}')
  27. def json = new JsonSlurper().parseText(soapResponse)
  28. def did=json.id
  29. propTestStep=CreateProjectTestCase.getTestStepByName("getdestinationidforpayroll")
  30. propTestStep.setPropertyValue("pdid",did.toString())
  31.  
  32. assert did!=null
  33.  
  34.  
  35. //extract data from jdbc/xml and apply assetion
  36.  
  37. import com.eviware.soapui.support.XmlHolder
  38.  
  39. def holder = new XmlHolder( messageExchange.responseContentAsXml )
  40. def totalRows = holder.getNodeValue('//Results/ResultSet/Row/PAYROLL_DESTINATION.DESTINATION_NAME')
  41. log.info totalRows
  42. assert totalRows!=null
  43.  
  44. //set common headers in all requests
  45.  
  46. import net.sf.json.groovy.JsonSlurper
  47. import com.eviware.soapui.support.types.StringToStringMap
  48. import com.eviware.soapui.model.project.ProjectFactoryRegistry
  49. import com.eviware.soapui.impl.wsdl.WsdlProjectFactory
  50.  
  51.  
  52. def workspace = testRunner.testCase.testSuite.project.workspace
  53. def testProject = (workspace==null) ?
  54. ProjectFactoryRegistry.getProjectFactory(WsdlProjectFactory.WSDL_TYPE).createNew("soapui-Automation-suite.xml") :
  55. workspace.getProjectByName("Paid")
  56. // assert workspace!=null
  57. if(!testProject.open && workspace!=null) {
  58. workspace.openProject(testProject)
  59. log.info("Project loaded")
  60. }
  61.  
  62. def CreateProjectTestCase = context.testCase
  63.  
  64.  
  65. def header = new StringToStringMap()
  66. def header1 = new StringToStringMap()
  67.  
  68. String token = context.expand('${Destinationname#headertoken}')
  69. log.info token
  70.  
  71. //some requests not working with all the header parameters so creating two separate headers which be used based on request requirement
  72. header.put("authorization",token)
  73. header.put("referer","https://mss-middleware-dot-gdc-javelin-v2-1-qa.appspot.com/_ah/api/static/proxy.html?usegapi=1&jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en.tZDXb_qbHrc.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Frs%3DAGLTcCOgQjGru3ruZo70XwAerRmnfOfOeA");
  74. header.put("user-agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36")
  75. header.put("x-clientdetails","appVersion=5.0%20(Windows%20NT%2010.0%3B%20Win64%3B%20x64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F63.0.3239.132%20Safari%2F537.36&platform=Win32&userAgent=Mozilla%2F5.0%20(Windows%20NT%2010.0%3B%20Win64%3B%20x64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F63.0.3239.132%20Safari%2F537.36")
  76. header.put("x-goog-encode-response-if-executable","base64")
  77. header.put("x-javascript-user-agent","google-api-javascript-client/1.1.0")
  78. header.put("x-origin","https://gdc-javelin-v2-1-qa.appspot.com")
  79. header.put("x-referer","https://gdc-javelin-v2-1-qa.appspot.com")
  80. header.put("x-requested-with","XMLHttpRequest")
  81.  
  82. header1.put("authorization",token)
  83.  
  84. testRunner.testCase.testSteps["Viewdestinations"].getHttpRequest().setRequestHeaders(header)
  85. testRunner.testCase.testSuite.project.workspace
  86. testRunner.testCase.testSteps["Adddestinationinpayroll"].getHttpRequest().setRequestHeaders(header)
  87.  
  88.  
  89. //sample groovy scripts
  90.  
  91. def a="chandan";
  92. println(a)
  93.  
  94. //list
  95. def list=[8, 1, 2, 3, 4]
  96.  
  97. list.add(5)
  98.  
  99. for (i in list) {
  100. print(i)
  101. }
  102.  
  103. def flag=list.contains(4)
  104. println(flag)
  105. list.sort()
  106. for (i in list) {
  107. println(i)
  108. }
  109.  
  110. def map= ["name":"chandan","age":29,"salary":20000.00]
  111.  
  112. for (i in map) {
  113. println "key is "+i.getKey()+"value is "+i.getValue()
  114. }
  115. assert map.containsKey("namqe")
  116. def ad="chandan"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement