Forum Discussion

mcastellanos's avatar
mcastellanos
Occasional Contributor
9 years ago

Can I pass the object textfield Name as a parameter

Hi there!

 

I have the following objects (1 & 2) that TestComplete has identified, which they refer to text fields on a window.

 

1. Sys.Process("GemCat_Gui").WinFormsObject("frmPatternMetaData").WinFormsObject("grpPatternID").WinFormsObject("txtPatterName")

2. Sys.Process("GemCat_Gui").WinFormsObject("frmPatternMetaData").WinFormsObject("grpPatternID").WinFormsObject("txtSAPInvestigationDescription")

 

As one can see, the only portion of the name that changes for each text field is the last part within quotes, that is, "txtPatterName" and "txtSAPInvestigationDescription".

 

Can one parameterize that piece which refers to the specific text field? I would hate to repeat this line of text as many times as for each text field.

 

Any ideas would be appreciated as to how I can accomplish that. I tried to concatenate a parameter but TestComplete does not like it.

 

Thank you in advance!

Miguel

  • NisHera's avatar
    NisHera
    Valued Contributor

    Can one parameterize that piece which refers to the specific text field?  Simple answer is yes.

    But how ..depends on how your approch to designing tests.

    1.  if you use name mapping you may map up to the object "grpPatternID" and give single name something like "PatternID" then you can call Aliases.PatternID.GemCat.txtPatterName and Aliases.GemCat.PatternID.txtSAPInvestigationDescription
    2.  if you may like to have very simple mapping structure like me ..., would map only higher object such as maping object "frmPatternMetaData"  and find from there like Aliases.PatternID.PatternMetaData.findChild(".....","PatterName",10,true)
    3.  if you are not like name mapping can use Sys.Process("GemCat_Gui").findChild(".....","PatterName",10,true)
    4.  Or you can just use variables var PatternID = Sys.Process("GemCat_Gui").WinFormsObject("frmPatternMetaData").WinFormsObject("grpPatternID") can call PatternID.WinFormsObject("txtPatterName") and PatternID.inFormsObject("txtSAPInvestigationDescription")
    • mcastellanos's avatar
      mcastellanos
      Occasional Contributor

      Thank you for your response.

       

      It is not clear to me how one would go about doing something as below:

       

      Aliases.PatternID.GemCat.txtPatterName and

      Aliases.GemCat.PatternID.txtSAPInvestigationDescription


      Please note that I still have to hard-code for each text field. What if I want to do the following:


      param1 = "txtPatterName"
      Aliases.PatternID.GemCat.param1 (this is what doesn't work in TC. How would you do something like that?)  or approaches 2, 3, and 4 are more conducive for something like that. I would like to concatenate the base string (green text) which stays the same and only pass the text field name (blue text).

      • NisHera's avatar
        NisHera
        Valued Contributor

        probably after concatinate TC would it identified as just a string 

        but TC need objects to work with. eval() function gets object out of string

        try something like..........(in jscript)

         

        param1 = "txtPatterName"

        objStr = "Aliases.PatternID.GemCat."+param1

        eval(objStr )