How to call an external API in truclient protocol of loadrunner

1.3k views Asked by At

I am recording a script using truclient protocol.In my script ,i need to externally call an API which generates the Password. The password is fetched using the co-relation,which is used as an input for Login. I am however unable to call the external API using the true client protocol. Could anybody please suggest how to call an external API in true client protocol.

1

There are 1 answers

2
Erxin On

Have you tried the evaluate JavaScript step? You can post the message to the server and get the generated password during the runtime. XHR and fetch API should be supported in Chrome and Firefox, TCIE should support XHR.

Sure. Please check the detail steps:

  1. Drag and drop an evaluate JS step from TruClient

  2. Open the script editor

  3. Add these code, make sure use the sync XHR to ensure the password is returned before the end step started:

    var xhr = new XMLHttpRequest(); xhr.open("POST", '/server', false);

    //Send the proper header information along with the request xhr.setRequestHeader("xxx", "value"); xhr.send();

    if (this.status === 200) { // Request finished. Do processing here. } var password = xhr.response;

  4. Change the login password step from plain text to JS and use

    ArgsContext.password

    to reference the previous received password.

If you have another questions please let me know. How to use the argument context you could reference this link.

BTW. the window and document object of the page can be referenced with AUT.window, AUT.document in TruClient.

Please check the help document from here.