QA_Chief
QA_Chief

Reputation: 3

Intellij Http Client - use function() import from external js to initialize an inplace variable

I am currently transcribing a postman collection to intellij http client and even though most of the stuff did work I am currently stuck at a specific problem where I need an inplace Variable @inplaceVar (that is valid for all requests in the same http file) to be initialized with an external js function import

This is how it works for PreRequest variables:

< {%
  import {certainFunction} from 'script/source';
  request.variables.set("onetimeusevar", certainFunction());  
%}

PreRequest Variables are only valid for the following request though so I need to import a function from my external file.js to be used with an inplace variable @inplaceVar because as I said I want to reuse this var for other requests in the same file

I have certain ideas on how to solve the scoping issue

  1. I could use client.global.set("varname", function()) but that causes all sorts of inconsistencies that global variables bring in a multirequest test setup and is prone to bite me in the ...

  2. Maybe I could create temporary temp.js file that I can initialize with the needed variables and overwrite for subsequent testruns/other http.files... Don't know how easy that is to implement though

Upvotes: 0

Views: 725

Answers (1)

QA_Chief
QA_Chief

Reputation: 3

Ok so I found a solution for my case:

@sth = "ARTS{{$random.integer(111111111, 999999999)}}PPE";

The specifics for my string are not as complicated so I can do this inline on the variable itself without needing a function.

Upvotes: 0

Related Questions