Forum Discussion

Shilzoting's avatar
Occasional Contributor
2 years ago

How to create and send Json request in readyapi through script


I am writing Zephyr scale test case execution status update script in readyAPI. I want to create script which will create request add Authorization header and execute this request in afterTestcase event handler, but I am not sure how i can do it readyAPI 

can anyone please help me with this?

Thanks in advance 

2 Replies

  • nmrao's avatar
    Champion Level 3

    I want to create script which will create request

    One step at a time. How this request looks like? Is it fixed always? or changes values?

    • Shilzoting's avatar
      Occasional Contributor

      Yes, I am getting value from each Testcase Property and assign to Zephyr scale api parameter I am trigging this aftertestCase  event, below is my script but it's not working in event 


      def tcobject = testCaseRunner.getTestCase()
      def tsobject = testCaseRunner.getTestCase().testSuite
      def projobject = testCaseRunner.getTestCase().testSuite.project
      def stepList = tcobject.getTestStepList();

      // // Get all test cases’ names from the suite
      def testCaseName =;
      def testCaseID = projobject.getPropertyValue("testCaseKey")
      def testCycleID = projobject.getPropertyValue("TestCycleID");
      def projectKey = projobject.getPropertyValue("projectID")
      testcaseStatus=tcobject.getPropertyValue("tcstatus")"testCaseName"+testCaseName)"projectKey1"+projectKey)"testcaseKey1"+testCaseID)"testcycleKey1"+testCycleID)"statusinpost1"+testcaseStatus) ) )

      // "projectKey : $projectKey , TestCaseName : $testCaseName , TestCaseIID : $testCaseID, TestCycleID: $testCycleID , ";
      if (testCaseID == null || testCaseID.length() == 0 || testCycleID == null || testCycleID.length() == 0 || projectKey == null || projectKey.length() == 0) { "MANDATORY FIELDS NOT AVAILABLE. Please check Ready API script to confirm they have all fields defined"
      return 0

      // testcaseStatus="PASS"
      // Check whether the case has failed
      if (testcaseStatus == 'FAIL') {
      // Log failed cases and test steps’ resulting messages "$testCaseName has failed"
      for (testStepResult in testCaseRunner.getResults()) {
      testStepResult.messages.each() {
      msg -> msg
      postToZephyrScale(projectKey, testCaseID, testCycleID, "Fail")
      } else if (testcaseStatus == 'PASS') {
      postToZephyrScale(projectKey, testCaseID, testCycleID, "Pass") "$testCaseName Test Passed";

      // "Results updation to Jira is complete"
      //String projectKey, String testcaseKey, String testcycleKey, String status, String comment)
      def postToZephyrScale( String projectKey, String testcaseKey, String testcycleKey, String status ){

      def today = new Date()
      def formattedDate = today.format("yyyy-MM-dd'T'HH:mm:ssZ")"postToZephyrScale")"projectKey"+projectKey)"testcaseKey"+testcaseKey)"testcycleKey"+testcycleKey)"statusinpost"+status)

      def project = testRunner.testCase.testSuite.project
      def requestTc = project.testSuites["UpdateTCsStatus Suite"].testCases["TestExecutions Test Case"]
      def requestSTP = requestTc.getTestStepByName("StatusUpdate")
      def request = requestSTP.getHttpRequest()

      requestSTP.setPropertyValue("testCaseKey",testcaseKey.toString )
      requestSTP.setPropertyValue("status",status.toString ),context)
      // ("runner status ....:"+ runner.hasResponse())