Search code examples
erlangtsung

Tsung replace characters in a dynamic variable


Using

 <dyn_variable name="OK_Button" jsonpath="test.items[0].links[0].href"/>

I am able to extract the the below url from the json http://localhost:8081/mycode/1.5.0/extended/call/action

But, In the next request Iwant to make use of the above url by changing the IP and port


Solution

  • for example:

    <dyn_variable name="ok_button" jsonpath = "test.items[0].links[0].href"/>
    <setdynvars sourcetype="eval"
            code='fun({Pid,DynVars})->
                      {ok,Val}=ts_dynvars:lookup(ok_button,DynVars),
                      L1 = re:replace(Val,"localhost","192.169.1.100",[{return,list}]),
                      L2 = re:replace(L1,"8801","8800",[{return,list}]),
                      L2 end.'>
        <var name="new_address" />
    </setdynvars>
    
    %% ok_button tolower
    %% L2 = "http://192.169.1.100:8800/mycode/1.5.0/extended/call/action"
    
    <request subst="true">
         <http url="%%_new_address%%" method="POST" contents="......."
    </request>