Forum Discussion

henil_shah's avatar
henil_shah
Contributor
9 years ago

How can I extract "clientid" from this html response into next request?

<script> s2pServerUrl = {uuid : x baseWebUrl : 'x', clientId: '123' </script>

 

I want this client id to be used in the request of next test case.

4 Replies

  • nmrao's avatar
    nmrao
    Icon for Champion Level 1 rankChampion Level 1
    Is that a partial html? it would be difficult. Full response would help.
    • henil_shah's avatar
      henil_shah
      Contributor

      The response is in full HTML having a script tag. I tried this

      def splitString = myString.split(':')

      but getting 'x'  now how to extract x out of ' ' ? I used split(' \' ') but its now working. Anyone knows how to split with single quote?

       

      PS - (' \ ' ') is without space! I just kept space here to demonstrate properly

      • HKosova's avatar
        HKosova
        Icon for Alumni rankAlumni

        How about using a regular expression?

        import java.util.regex.*
        def str = "<script> s2pServerUrl = {uuid : x baseWebUrl : 'x', clientId: '123' </script>"
        
        def matcher = str =~ /clientId\s*:\s*['"](\w+)['"]/
        def value = matcher[0][1]  // matcher[0] is entire matched string, [1] is the captured group
        
        log.info value  // 123