Quantcast
Viewing all articles
Browse latest Browse all 261

Replace in postman java script | replace domain name with ip in url and then set as environment variable

Let us assume a POST response is returning a URL in header.  

Now, how to replace the DNS name with IP address and set the URL as environment variable ? 

Below postman java script does the job. 

The first var line(var siteurl) gets the URL from the POST response. 
The second var line(var ip) gets the IP from environment variable , 
The third var line(var location)  replaces the DNS name with IP and then 
The fourth var line sets the new URL that is replaced from third line as environment variable(location). 

var siteurl = pm.response.headers.get("location");  // location= https://www.this-is-amazon-site-hostname.com/books
console.log("siteurl="+siteurl) //	https://www.this-is-amazon-site-hostname.com/booksvar ip = pm.environment.get("serverip"); //serverip is the environment variable
console.log("Server IP="+ip)  	//   10.123.4.23var location = siteurl.replace("www.this-is-amazon-site-hostname.com", ip);
console.log("location="+location) // https://www.10.123.4.23/bookspm.environment.set("sitenewurl",location)//sitenewurl is the environment variable and the value will be set to  https://www.10.123.4.23/books




Viewing all articles
Browse latest Browse all 261

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>