UFT Java Add-In returning arrays and/or objects
I am new to UFT/QTP and I trying to figure out if there is a way for a helper class in the Java Add-In for UFT to return an array of values (or even a specific Object) to UFT. To give a quick idea of what I am trying to accomplish: I address a custom Java component that represents a table with multiple columns. I like to receive all the values for one row by calling a method like GetRowContents(5) on the custom component. It would be perfect if the method could just return a simple array of strings. Please note that I am working with a fully custom component. There is no underlying JTable or something I could address; I have to rely on a helper class in the Java Add-In.
As far as I can tell from the documentation that comes with UFT, the methods in the helper class can only return Strings. However, the API reference shows that you can return a Retval in which you can pass an Object. I tried doing this, returning both arrays and objects, but I seem to fail to receive them at the VBScript side in UFT. The debugger of UFT shows that my variables are empty when the call is made to the Java Add-In. Since my VBScript knowledge is about non-existent, I could also be doing something wrong here.
I tried searching the internet for some answers or examples, but it is surprising that so few answers can be found. I found actually only one topic that addresses the same problem, and it was posted in 2007 on this forum as well: sqaforums.com. However, no clear solution is given there and I am now wondering if anyone has found a proper solution? If anyone can refer me to some proper source of information, that would also be appreciated.
At this point I am thinking of using JSON to encode the values of the array and returning them as a string to VBScript, but this feels all a bit cumbersome.
This topic is a bit advanced for me. It sounds as if the EA Extensibility Accelerator may be of use here. I'm not sure.
Thanks for the tip, I did not know about the Extensibility Accelerator. However, based on the tutorial video of HP about the EA, I get the feeling this is specifically for Web testing, while I am trying to test a standalone Java application.
am not much in using Java-addin and its methods - but rather than using the existing method like GetRowContents(5) which i guess might be returning a string with all col values.
Originally Posted by Sjoerd
But to return you a array with all row values - You can write a small function to get data from each cell for that row - store it in the array and loop through all columns
I hope i understood your question in a right way, else please throw few more details what you would like to achieve
Thanks for suggestion, I think you understood my question correctly.
I indeed also thought of building a GetRowContents(rowIndex, columnIndex) method, but since the application communicates a lot with a server, these requests might put a significant strain on the server and impose some time delay, which I do not really want during the auto tests. I expect that I will need other methods for other (unrelated) objects that also return arrays. It would be more convenient for me if I could just return an array of Strings, instead of building something around this.
The application might be communicating lot with the server but the validation you are doing doesnt trigger any action on the app right.
Originally Posted by Sjoerd
I mean when you try to get contents from the page, it is actually working on UI or the HTML part which doesnt trigger any requests & hence any delay.
Please let us know which actions might lead to the delay and also what all actions you would likely to do so this forum might be able to suggest.
Well, I am trying to automate the testing, so some things might trigger actions in the app. For example, we have a custom made list that receives its contents from a server. Since the list may contain many, many items, not all its contents is sent at once. Now if in my test I say 'select row number 350', then the content for this row may not loaded yet and needs to be retrieved from the server. This might cause a bit of delay. If the methods are called more often and with 'inconvenient' arguments, these delays might add up quite a bit. This example is heavily simplified, but you may assume that the delay can become significant in my use-case.
The good news is that I did find some workaround. If you type .Object in the VBScript code, you get a reference to the actual Java object from which you can call all its public methods. When you return an array from one of these public methods, you can access the array by means of the undocumented method mic_arr_get(index). I found the information on http://www.advancedqtp.com/handling-java-arrays/. It is, however, still a shame that this doesn't work from the Add-In. I would have liked to be able to return an array/object in the Retval-object and then use that on the QTP side.
If someone still finds a clean way to return arrays from the Java Add-In to QTP, I would love to hear it :-)