Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Editing java arrays in QTP
#1
Not Solved
Hi,

I'm using v10 of QTP with the java add-in and my AUT is a java swing application.

I'm accessing a number of native java methods of the application in order to retrieve data that can't be retrieved through the UI. One of the methods returns a java array object which I am able to read using mic_arr_get and write to using mic_arr_set.

However, I would like to append extra data to the array but QTP doesn't seem to allow the mic_arr_set to write extra items to it. Below is an example in code:

Code:
'the getItems java method returns an array back to my retrieveItems QTP object - for the sake of argument lets say it returns 2 string items in the array and I output these into other variables
Set retrieveItems = myApplicationObject.getItems
item1 = retrieveItems.mic_arr_get(0)
item2 = retrieveItems.mic_arr_get(1)

'now I want to add a third item to the array
item3 = "this is my third item"
Set retrieveItems.mic_arr_set(2) = item3

When QTP tries to execute the final line of that code snippet I get back a subscript out of range error, presumably because the original array I retrieved only contained two items.

Therefore, I have 3 questions:
  1. Is there a way to count the number of items in the java array object that has been returned?
  2. Is there a way to append or delete items from the java array object?
  3. Bearing in mind I could get around this if I could create my own java array object and insert data into it, is there a way to create a new java array object?

Any help much appreciated!

David
Reply
#2
Not Solved
Hi David,

I am not sure if it will work for you but you can resize an array by "ReDim Preserve" statement.

So after you get the array, try to increase the size of the array by this statement and then set the value.

Learn about ReDim statement in the QTP Help file.
Reply
#3
Not Solved
Hi Prabhat,

Thanks for the suggestion, but unfortunately my java array is held as an object, rather than a variable so ReDim won't help here.

Many thanks

David
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Script Editing Problem neerdeth 4 3,526 07-20-2012, 10:12 AM
Last Post: Shridevi.Salagare
  How to convert three arrays into just ONE array? Arena 2 4,879 04-10-2012, 09:35 AM
Last Post: Arena
  Editing a notepad file in QTP arjun.singh 5 31,972 10-20-2011, 06:58 PM
Last Post: Ankesh
  Help on arrays AutomationTester2011 3 3,149 07-05-2011, 04:15 PM
Last Post: rajpes
  Java Web application not recorded by QTP9.5 even when Java/web addin is installed taruninpune@googlemail.com 0 2,911 12-16-2010, 12:42 PM
Last Post: taruninpune@googlemail.com

Forum Jump:


Users browsing this thread: 2 Guest(s)