Forum Discussion

bdrummond's avatar
bdrummond
Contributor
8 years ago

Object.Save() type-mismatch error - cannot save a property to TC Objects

 was wondering if TC cannot store a property of an object as Test Complete Object?

 

I have tried to save an object, but more precisely, trying to save the wText property of a title box as an object - so then i can verify it later on.

 

Any suggestion, of a better practice on how to store this wText as object and then use it for a checkpoint later on the test?

 

//Script unit to replace exising chart title to be saved.
//

//import unit uniqueID
var impUnit = require("uniqueId");

function chartTitle(){
  var ic = Aliases.IC;
  var getTitleBox = ic.saveChartAsForm.titleTxtBox;
  var x = impUnit.getObject(); //Retrieve the result of function uniqueId() from other unit.
  
  //set random number onto the title
  getTitleBox.SetText(x);  
  Log.Message("This is the randomly generated chart name: " + x);
    
  //Get the String object under title txt box
  var a = getTitleBox.wText; //----> this wont work...(?)<----
  var x = a;  
  Log.Message(x);
  
  //Prepares the property name
  propertyNames = "Generated Chart ID";

  //Save object into Objects in TestComplete
  Objects.Save(x, propertyNames);
  
}

I have attach an image to better understanding what i am trying to do.

 

Much appreciate it for any advise.

 

regards,

 

BD

  • What does the following code actually return

     

    impUnit.getObject()

    As per the following, the first parameter of Objects.Save needs to be an onscreen object/component identified by TestComplete.  Second parameter needs to be a string to be used to save the Object in the stores.  It is a required field so, if you are missing the name string, it won't work.  Also, it needs to not contain spaces or special characters.  For property names to save, this is a space delimited list of properties.

     

    So... generally speaking, you aren't using Objects.Save properly...  1) you might not actually be passing in the proper object, depends upon that above code. 2) You are apparently missing the parameter to indicate the name to use for saving the object. and 3) if you want to store the wText property, your propertyNames variable should simply be "wText".  This will store that property and it's value.

     

    So... based upon what I'm seeing, I'd change the code to the following (see bolded line).  This will store the title box object into the stores area with the wText property set to whatever the current value is.  


     

    //Script unit to replace exising chart title to be saved.
    //
    
    //import unit uniqueID
    var impUnit = require("uniqueId");
    
    function chartTitle(){
      var ic = Aliases.IC;
      var getTitleBox = ic.saveChartAsForm.titleTxtBox;
      var x = impUnit.getObject(); //Retrieve the result of function uniqueId() from other unit.
      
      //set random number onto the title
      getTitleBox.SetText(x);  
      Log.Message("This is the randomly generated chart name: " + x);
        
      //Get the String object under title txt box
      var a = getTitleBox.wText; //----> this wont work...(?)<----
      var x = a;  
      Log.Message(x);
      
      //Prepares the property name
      propertyNames = "Generated Chart ID";
    
      //Save object into Objects in TestComplete
      Objects.Save(getTitleBox, "TitleBox", "wText");
      
    }
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    What does the following code actually return

     

    impUnit.getObject()

    As per the following, the first parameter of Objects.Save needs to be an onscreen object/component identified by TestComplete.  Second parameter needs to be a string to be used to save the Object in the stores.  It is a required field so, if you are missing the name string, it won't work.  Also, it needs to not contain spaces or special characters.  For property names to save, this is a space delimited list of properties.

     

    So... generally speaking, you aren't using Objects.Save properly...  1) you might not actually be passing in the proper object, depends upon that above code. 2) You are apparently missing the parameter to indicate the name to use for saving the object. and 3) if you want to store the wText property, your propertyNames variable should simply be "wText".  This will store that property and it's value.

     

    So... based upon what I'm seeing, I'd change the code to the following (see bolded line).  This will store the title box object into the stores area with the wText property set to whatever the current value is.  


     

    //Script unit to replace exising chart title to be saved.
    //
    
    //import unit uniqueID
    var impUnit = require("uniqueId");
    
    function chartTitle(){
      var ic = Aliases.IC;
      var getTitleBox = ic.saveChartAsForm.titleTxtBox;
      var x = impUnit.getObject(); //Retrieve the result of function uniqueId() from other unit.
      
      //set random number onto the title
      getTitleBox.SetText(x);  
      Log.Message("This is the randomly generated chart name: " + x);
        
      //Get the String object under title txt box
      var a = getTitleBox.wText; //----> this wont work...(?)<----
      var x = a;  
      Log.Message(x);
      
      //Prepares the property name
      propertyNames = "Generated Chart ID";
    
      //Save object into Objects in TestComplete
      Objects.Save(getTitleBox, "TitleBox", "wText");
      
    }
    • bdrummond's avatar
      bdrummond
      Contributor

      hi tristaanogre,

       

      thank you for your input. I have tried your suggested work and applied it to the test complete. it is now working as expected. 

       

      to follow-up on your question on

       

        var x = impUnit.getObject(); //Retrieve the result of function generateRandomId() from other unit.

      this is so i can grab the result of random number to make the Chart title unique-ish. The function for this random number generation is in another Unit..and is as follow:

       

      //Script unit to generate 4 digits random number.
      //
      
      function generateRandomId() {
      
        /*Math.random() generate random number between 0-1*/
        
        return 'Xplot_ID' + Math.random().toString(10).substr(2, 4);
        
      }
      
      // Makes the uniqueId  function available to other units
      module.exports.getObject = generateRandomId;

      I can see the object saved in TC project's Store now and also it's 'wText' properties - I should have read the Object.Save() method Doc more thoroughly before.

       

      thanks you for your expertise.

       

      BD