Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.
Saving output from JavaScript
LegacyForum
Posts: 1,664 ✭✭
I found some JavaScript that will give me the IP Address of the local machine where I am running tests and this code works quite nicely.
function GetIPAddress(input, context) {
var ip = java.net.InetAddress.getLocalHost();
var ipStr = new java.lang.String(ip.getHostAddress());
return (ipStr);
}
The problem is that I need to save the return value for later use in an XML Data Bank and the Python code I usually employ as shown below does not work (the error message is "Traceback (innermost last): File "<string>", line 9, in showMe TypeError: getXMLFromString(): 1st arg can't be coerced to String[]). I would think I might need to return a string array from the GetIPAddress function in order for the showMe function to work as expected, but I am not sure how to do it. Help!
from com.parasoft.api import *
from soaptest.api import *
from java.util import *
from java.text import *
from java.lang import *
def showMe(input, context):
return SOAPUtil.getXMLFromString([input])
CODE
function GetIPAddress(input, context) {
var ip = java.net.InetAddress.getLocalHost();
var ipStr = new java.lang.String(ip.getHostAddress());
return (ipStr);
}
The problem is that I need to save the return value for later use in an XML Data Bank and the Python code I usually employ as shown below does not work (the error message is "Traceback (innermost last): File "<string>", line 9, in showMe TypeError: getXMLFromString(): 1st arg can't be coerced to String[]). I would think I might need to return a string array from the GetIPAddress function in order for the showMe function to work as expected, but I am not sure how to do it. Help!
CODE
from com.parasoft.api import *
from soaptest.api import *
from java.util import *
from java.text import *
from java.lang import *
def showMe(input, context):
return SOAPUtil.getXMLFromString([input])
0
Comments
-
Hi jstrom,
It looks like you have two scripts here, in different languages - we just need to put them together. The error is likely caused by the fact that the input argument is not actually a string (you can cast it to a string with something like str(input)).
Here's the full working example in Jython which should give you the desired information:CODEfrom com.parasoft.api import *
from soaptest.api import *
from java.lang import *
from java.net import *
def getgetIPAddress(input, context):
ip = InetAddress.getLocalHost()
ipStr = String(ip.getHostAddress())
return SOAPUtil.getXMLFromString([ipStr]);0 -
Works like a charm, many thanks!0