Forum Discussion

nisgupta's avatar
nisgupta
Valued Contributor
7 years ago

Framework - generic functions - passing Name mapping as parameters

For Web Application 

Is any one creating the framework where generic functions are created for different web objects like check box, Text box, button? 

 

for e.g. 

 

for select and click on the button 

 

function SelectButton(ButtonObj)
 {
       if(ButtonObj.WaitForProperty("Enabled", true, 3000))
{
        ButtonObj.ClickButton();
         Log.Message(ButtonObj.contentText + " is clicked");
}
else{
            Log.Error("No Button is Found");
}

}

 

 

Then from the main script .. 

 

call this function by passing Alias Name Mapping as parameters 

Have attached the scrrenshots.

 

Let me know if any more information is needed.

 

Thanks

Nishchal

 

 

 

 

12 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    Based on your code what i understand, you want to have some generic functions which can perform actions like ClickButton, Select Dropdown, etc.

     

    Yes, this kind of functions would be useful when you want to have a framework for Object actions.

     

    In some scenarios, It won't be helpful if you trying to do different operations with Textbox.

     

    As tristaanogreAlexKaras said, If it is useful for your AUT structure and business needs then it is good have.

     

    I have similar kind of function that i wrote for Setting up of Text,

     

    function EnterText(objMainObject,strValue,strFridenlyName)
    { 
          
        //objMainObject should be Text box object
    	if(objMainObject != null)
    	{
    		  if((objMainObject.Exists) && (objMainObject.Visible)) 
    		  {
    				
    			if(aqConvert.VarToStr(strValue) == "null")
    			{
    				  objMainObject.Keys("^a");
    				  objMainObject.Keys("[BS]");          
    			}
    			else if(aqConvert.VarToStr(strValue) != "")
    			{
    				  
    				if(aqString.Compare(aqConvert.VarToStr(objMainObject.getText()),strValue,true) != 0)
    				{
    					  objMainObject.Keys(strValue);
    					  
    					if(aqString.Compare(aqConvert.VarToStr(objMainObject.getText()),strValue,true) == 0)
    					{
    					  Log.Event(strFridenlyName + " object is entered as " + strValue);
    					} 
    					else
    					{
    						Log.Error(strFridenlyName + " object is not entered as " + strValue);
    					}
    				}
    				else
    				{
    					  Log.Event(strFridenlyName + " object is already as " + strValue);
    					  break;
    				}
    				  
    			}
    			else
    			{
    				  Log.Message("No value found for input");
    			}
    		}
    	}
    }

     

    • nisgupta's avatar
      nisgupta
      Valued Contributor

      Thank everyone for the updates .

       

      The reason why I am trying to go create generic functions because we have 300-400 web applications that will be automated in the future. If I create generic functions and passing Name Mapping as parameters then we have to create less functions whenever we work for automation for new application.

       

      I am trying to create generic function for radio button. We are using java script .

       

      Let me know if additional details . Attached the screenshot.

      • shankar_r's avatar
        shankar_r
        Community Hero

        Hi,

         

        You can create generic function to click the Radio button and it will have only the Click operation.

         

        But in-order to know which Radio needs to be clicked, you need to have function to identify that.

         

        ForEx:

        In your attached screenshot, if you want to click the second radio button how will find it. If you know how to find it then you create common functions to do that.

         

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    I haven't gone quite to that level but I know others who have. It's not an unusual way of doing things.  An automation framework can be as granular or as general as you would like.  In a POS application I did testing on, I had generic functions for applying payments that I used all over the place.  That's a bit more generalized as it's not a single button press but I know of some other framework structures that go a bit more granular.  


    Are you haven particular problems with this?  Is there something not working for you?

    • nisgupta's avatar
      nisgupta
      Valued Contributor

      Thank you very much for the updates.

       

      No this kind of framework requires less coding in terms of creating the functions for every applications. Yes We have to be dependent on Name mapping as we are passing Name Mapping as parameters.

       

      The biggest challenge is code completion do not appear . For e.g. if you look at the the screenshot functionscript1.png .

       

      Also if we have new type of web Object then there is a challenge of writing the functions ie. writing the logic for e.g. how can we write the generic function of radio buttons.

       

      Do you think is this a good framework ?

       

      Thanks

      NG

       

       

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        If it meets your business needs, does what you need it to do, and is easily maintainable and expandable... then yes, it's a good framework.

         

        As mentioned, I don't go quite this granular.  I prefer to write my framework on a functional level (applying a payment, entering contact details, saving a file, etc) rather than on granular controls.

         

        As for code completion, this is to be expected.  The function you displayed doesn't know what "ButtonObj" is... there's no context for it to know how to complete that code.  

         

        As for radio buttons, what I would do is map the parent object for the radio buttons (panel, etc) and each of the buttons underneath it.  Your parameters for that function would be the parent object and the button name.  But this is just one way, I'm sure there are others.  Again... if it works for you, then it works.

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi Nishchal,

     

    Fully in line with Robert - if this framework works for you then it is a good one.

    The only potential problem is non-existing objects.

    I.e.: your code for drop-down contains a line like

    <parameterObject>.WaitProperty("Exists", true, ...)

    While running, TestComplete will try to evaluate the <parameterObject> and if it does not exist, TestComplete will wait for the object to appear within default timeout. If it is expected that the <parameterObject> may not exist then you will get not necessary execution performance loss.