Forum Discussion

chrisb's avatar
chrisb
Regular Contributor
11 years ago

Save method overwrites an object saved to stores

I am using the save method to save one property of an object to the project stores.



 dir = "C:\\testing\\WIP\\Stores\\Objects\\"+dirName;

 Objects.Save(fieldContent, hashIndex,"Text","","True",dir);



I then call Objects.Save a second time but pass a different directory name, I would expect the object to then be saved twice, once to the first directory and once to the new directory.



It seems that TC tries to be clever and recgonizes that the object is the same in both cases and overwrites the existing object with the latest version of the same object and updates the directory name (path).



Is there a way I can save the same object in two locations in the Stores? Ie. in 2 different directories. I need to do this to save test data from a common control that is tested using different data in two different tests.







  • Hi Chris



    An interesting problem and one for which I may be completely wrong, but have you tried looking in the two different file locations using Explorer to see if there are 2 physically different files?



    This in itself will not directly answer your query, but I think that the problem might lie in how the Objects.Save feature works.  Is it that this is a collection of objects in the store, each of which must be unique and the fact that you have specified different directory paths is irrelevant because these are just values of a key, being the object's name, which is the same in both cases, For example, if the key is 'A' and one of its values is 'C:/myDir/myFile' and I create another key 'A' with a value 'C:/yourDir/yourFile', there will still only be one object in the collection with key A (the object's name), but its values, in this case the directory location have changed.  If you want to have two objects in the collection you will need to have unique names for each.



    I would be interested to hear if my understanding of this is correct?



    Regards

    Stephen.
  • sbkeenan's avatar
    sbkeenan
    Frequent Contributor
    Hi Chris



    An interesting problem and one for which I may be completely wrong, but have you tried looking in the two different file locations using Explorer to see if there are 2 physically different files?



    This in itself will not directly answer your query, but I think that the problem might lie in how the Objects.Save feature works.  Is it that this is a collection of objects in the store, each of which must be unique and the fact that you have specified different directory paths is irrelevant because these are just values of a key, being the object's name, which is the same in both cases, For example, if the key is 'A' and one of its values is 'C:/myDir/myFile' and I create another key 'A' with a value 'C:/yourDir/yourFile', there will still only be one object in the collection with key A (the object's name), but its values, in this case the directory location have changed.  If you want to have two objects in the collection you will need to have unique names for each.



    I would be interested to hear if my understanding of this is correct?



    Regards

    Stephen.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Stephen is correct.  The second parameter in the "Save" method is the name or title of the object collection being saved.  Since that is not changing, all that is happening is that you are updating an existing object with a new information.  



    Perhaps, per iteration, you should adjust that second parameter to be different to differentiate between the two.
  • chrisb's avatar
    chrisb
    Regular Contributor
    Thanks Stephen and Robert. I'd originally looked at changing the name on each save by appending the name with the script name but there were some challenges with being able to have a way to easily retrieve the data from other scripts.

    I read test data in from Excel worksheets so I might just go the whole hog and look at writing data to Excel  using the Com object. This would give me one consistent place to go to for data and probably more control over how the test data is organized.

    Any suggestions from you guys with regards to storing test data, what methods have you used? spreadsheets, databases, project stores...?





  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    A question I would have is what is your purpose for saving the object?  Is it to compare it to something else later?  Is it as proof that something completed successfully?  A lot of where I store things has to do with what I plan on doing with it.  I really only store in the Objects.Store if I intend on using the object in a comparison later.
  • chrisb's avatar
    chrisb
    Regular Contributor
    Yep, so data that is required for the duration of a test I just save to a variable. Data that is required for test set up is read in from a spreadsheet. I am now chaining some tests together and basically want to take some data that is created by test A and and store it for use by Test B, whether test B runs immediately after or a week later. And yes, I am aware of the hazards of chaining tests!