Microsoft graph api 存储jsr223响应中的变量以在后续测试中使用

Microsoft graph api 存储jsr223响应中的变量以在后续测试中使用,microsoft-graph-api,jsr223,taurus,Microsoft Graph Api,Jsr223,Taurus,嗨,我正在尝试编写一个使用MicrosoftGraphAPI的taurus测试。我的目标是在POST请求中使用两个jsr223响应中的组id和用户id将用户添加到Azure组。问题是我一直在变老 Non HTTP response message: Illegal character in path at index 41: https://graph.microsoft.com/v1.0/groups/${AzureGroupId}/members/$ref 因为变量AzureGroupI

嗨,我正在尝试编写一个使用MicrosoftGraphAPI的taurus测试。我的目标是在POST请求中使用两个jsr223响应中的组id和用户id将用户添加到Azure组。问题是我一直在变老

 Non HTTP response message: Illegal character in path at index 41: https://graph.microsoft.com/v1.0/groups/${AzureGroupId}/members/$ref
因为变量
AzureGroupId
设置不正确。以下是获取组的测试:

      # Microsoft Graph Get AD groups
      - url: ${MicrosoftGraph}/groups?$orderby=displayName
        label: 1302_FetchMicrosoftAADGroups
        method: GET
        headers:
          Authorization: Bearer ${graph_api_access_token}
          Content-Type: "application/json"
          Accept: "application/json, text/plain, */*"
        assert-httpcode:
          - 200
          - 202
        jsr223:
          - langauge: groovy
            execute: after
            script-text: |
              import groovy.json.JsonSlurper
              def slurperresponse = new JsonSlurper().parseText(prev.getResponseDataAsString())
              for (entry in slurperresponse){
                if(entry.displayName == "ACME"){
                   vars.put("AzureGroupId",  entry.id)
                   break;
                }
              }
            script-file: jsr223/logger.groovy
            parameters: fetch_microsoft_ad_groups
下面是获取用户的测试:

      # Microsoft Graph Get AD users
      - url: ${MicrosoftGraph}/users
        label: 1302_FetchMicrosoftAADUsers
        method: GET
        headers:
          Authorization: Bearer ${graph_api_access_token}
          Content-Type: "application/json"
          Accept: "application/json, text/plain, */*"
        assert-httpcode:
          - 200
          - 202
        jsr223:
          - langauge: groovy
            execute: after
            script-text: |
              import groovy.json.JsonSlurper
              def slurperresponse = new JsonSlurper().parseText(prev.getResponseDataAsString())
              for (entry in slurperresponse){
                if(entry.userPrincipalName == "jon.doe@gmail.com"){
                   vars.put("AzureUserId",  entry.id)
                   break;
                }
              }
            script-file: jsr223/logger.groovy
            parameters: fetch_microsoft_ad_users
最后,我将结合这两个测试的结果,在此测试中提出POST请求:

      # Microsoft Graph Add a user
      - url: ${MicrosoftGraph}/groups/${AzureGroupId}/members/$ref
        label: 1324_AddUserToAzureADGroup
        method: POST
        headers:
          Authorization: Bearer ${graph_api_access_token}
          Content-Type: "application/json"
          Accept: "application/json, text/plain, */*"
        body:
          "@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/${AzureUserId}"
        assert-httpcode:
          - 204
        jsr223:
          - langauge: groovy
            execute: after
            script-file: jsr223/logger.groovy
            parameters: add_user_to_active_directory_group
POST请求失败,因为
url
格式不正确。有人能解释一下如何从响应中设置变量,以便我可以在后续请求中使用它作为url的一部分吗


谢谢

变量的范围设置不正确。部门

scenarios:
  TestScenario:
    variables:
      AzureGroupId: 0
      AzureUserId: 0
      AzureUserName: ""

需要设置。

请尝试以下引用的步骤。*************************************************************************************************def bufferedReader=new bufferedReader(new InputStreamReader(response.getEntity().getContent())def jsonResponse=bufferedReader.getText()println“response:\n”+jsonResponse def slurper=new JsonSlurper()def resultMap=slurper.parseText(jsonResponse)vars.put(“AzureUserId”,resultMap[“id”]))*********************************************************************************************对你有用吗?