felix_ossigbona
12 years agoNew Contributor
Objects - Iterating and Deleting
I have just started using TestComplete so am not overly familiar with it. I have managed to read in some data from an excel file using the sample cade here (http://support.smartbear.com/viewarticle/56908/) but I am now trying to create an array of objects I can use later in my script.
I have worked out how to create a class, an object of that class and set the properties:
function test(){
// Create Class
TestClassObj = ODT.Classes.Declare("TestClass");
TestClassObj.AddProperty("username", "");
TestClassObj.AddProperty("password", "");
// Create an Object of TestClass
TestObj = ODT.Classes.New("TestClass");
// Set the properties of the object
TestObj.username = "felix";
TestObj.password = "mypassword";
}
For this to work I need to create an ODT item - I did this by right-clicking the Advanced folder and adding a new ODT item (i'm not sure if this can be done in code).
One problem I am having at present is taht I need to manually delete the class from the project before I can run the script again. I have tried deletin the class using:
ODT.Classes.Delete("TestClass");
But this gives me the following error:
"Cannot delete the TestClass class, since there are objects that belong to this class"
I'm not sure how to delete an object (I tried the 'delete' keyword, but it gave me the same error)
I also need to be able to iteralte/loop through the objects. For example I want to do something like the following.
{
num_of_objs = 7;
objects = [];
for i = 1:num_of_objs:
objects.append(ODT.Classes.New("TestClass"));
...
for i in enumerate(particles):
do stuff to each object
...
for i in enumerate(particles):
delete objects (so I can delete the class).
}
If someone could help me with the code to do the above it would be greatly appreciated.
Regards,
Felix
I have worked out how to create a class, an object of that class and set the properties:
function test(){
// Create Class
TestClassObj = ODT.Classes.Declare("TestClass");
TestClassObj.AddProperty("username", "");
TestClassObj.AddProperty("password", "");
// Create an Object of TestClass
TestObj = ODT.Classes.New("TestClass");
// Set the properties of the object
TestObj.username = "felix";
TestObj.password = "mypassword";
}
For this to work I need to create an ODT item - I did this by right-clicking the Advanced folder and adding a new ODT item (i'm not sure if this can be done in code).
One problem I am having at present is taht I need to manually delete the class from the project before I can run the script again. I have tried deletin the class using:
ODT.Classes.Delete("TestClass");
But this gives me the following error:
"Cannot delete the TestClass class, since there are objects that belong to this class"
I'm not sure how to delete an object (I tried the 'delete' keyword, but it gave me the same error)
I also need to be able to iteralte/loop through the objects. For example I want to do something like the following.
{
num_of_objs = 7;
objects = [];
for i = 1:num_of_objs:
objects.append(ODT.Classes.New("TestClass"));
...
for i in enumerate(particles):
do stuff to each object
...
for i in enumerate(particles):
delete objects (so I can delete the class).
}
If someone could help me with the code to do the above it would be greatly appreciated.
Regards,
Felix