Automation framework

Experiences, small talk, and other automation gossip.
omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Automation framework

Post by omayer » Sun Aug 14, 2011 5:37 am

what disadvantage does it have when creating common method to enter data in a textfield on different applications, is any challenge to identify the text field on different applications? or any peformance issue ?
Thanks,
Beginner

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Automation framework

Post by Ciege » Mon Aug 15, 2011 5:47 pm

I think the advantages far outweigh the disadvantages when creating and using a reusable common framework. However, since you ask about disadvantages one I can think of easily is if your different AUTs use different technologies you will have to have different code paths if the technologies result if severely different xPath recognitions or if manipulation of the object have severe differences.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Automation framework

Post by omayer » Tue Aug 23, 2011 6:36 pm

could you please provide any code sample for common function like enterring first name that will work for multiple application

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Automation framework

Post by Ciege » Tue Aug 23, 2011 6:45 pm

Here is a method I use for clicking in a text box. You can extend it to also accept a string variable to type into that text box.

Code: Select all

        public static int TextBoxClick(Ranorex.Form RanorexFormName, String TextBoxName)
        {
            int intResult = TextBoxClick(RanorexFormName, TextBoxName, false);
            return intResult;
        }
        public static int TextBoxClick(Ranorex.Form RanorexFormName, String TextBoxName, bool boolHideNotFoundError)
        {
            /************************************************************************
             * Function         : TextBoxClick(Ranorex.Form RanorexFormName, String TextBoxName)
             *
             * Description      : This method will search for and (if found)  
             *                  :  select a TextBox on the form.
             *                         
             * Parameters       : RanorexFormName   - The form object the the TextBox lives on
             *                  : TextBoxName       - Name of the TextBox to click
             *                  : boolHideNotFoundError - FALSE (default) - reports that the item was not found - returns -1
             *                  :                       - TRUE - Hides the error that the item was not found - Still returns -1
             *                  :                       - This option basically transforms this method into a check if exists method
             *                  
             * Return Type      : Integer
             * 
             * Return Value     : 0 for success, -1 for failure
             * 
             * Revision History
             * Date       : Author                    : Reason/Change
             * ---------- : ------------------------- : ------------------------------
             * 03/05/2009 : Chris Gendreau            : Initial Creation 
             * 12/10/2009 : Chris Gendreau            : Added HideNotFoundError option
            ************************************************************************/

            Ranorex.Text HDtext;
            int error = 0;

            //Search for the Text box on the Form
            try
            {
                RanorexFormName.EnsureVisible();
                RanorexFormName.Activate();
                Thread.Sleep(500);
                HDtext = RanorexFormName.FindSingle(".//text[@controlname='" + TextBoxName + "' or @text='" + TextBoxName + "' or @accessiblename='" + TextBoxName + "']", 30000);
            }

            catch (RanorexException e)
            {
                if (boolHideNotFoundError != true)
                {
                    Report.Error("Unable to find TextBox: " + TextBoxName);
                    Report.Error(e.ToString());
                    Report.Screenshot();
                }
                error = -1;
                return error;
            }
            //Click a TextBox
            try
            {
                Report.Debug("Clicking TextBox: " + TextBoxName);
                HDtext.Focus();
                Thread.Sleep(500);
                HDtext.Click(Location.Center);
                Report.Debug("  Clicked TextBox: " + TextBoxName);
            }

            catch (RanorexException e)
            {
                Report.Error(e.ToString());
                Report.Screenshot();
                error = -1;
            }

            return error;
        }//End TextBoxClick
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Automation framework

Post by omayer » Wed Aug 24, 2011 3:25 pm

Thank you Ciege, its very helpful , Please give me some feed back if I creat method in following way

Code: Select all

   public void CandQuickChckPhone( string ph1)
      {
        
        		//Enter phone      	
			repo.LeftNavigation.PrimaryHomePhone.InputTagTxtPhone2_ph1.Click();
			Keyboard.Press(ph1); 			
				   
        }

Tipu

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Automation framework

Post by Ciege » Wed Aug 24, 2011 4:11 pm

While it looks like your method would work, my suggestion for framework methods it to put a lot of error checking code in the method... You want to be able to make that piece of framework code as robust as possible to handle any potential errors and pass that information back to the caller. This way you have very strong code that can report accordingly what it is supposed to do, what it did and if there were any errors.
The more robust you make it the more of a chance you have of it working with several AUTs and allow several users to use your code going forward and understanding if there are any issues.

Take a second look at my code and see for yourself all the error checking and reporting this "simple" method is doing. It's much more than just clicking a text box...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Automation framework

Post by omayer » Wed Aug 24, 2011 4:39 pm

Thank you Ciege, this is great feedback, would you please add more code example here and there.

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Automation framework

Post by Ciege » Wed Aug 24, 2011 4:51 pm

omayer wrote:Thank you Ciege, this is great feedback, would you please add more code example here and there.

There are lots of great code examples strewn about the forums already as well as throughout the web (use Google!)... Also, check out the automation modules section in the forums... Ranorex is putting some nice code there as well...

Trying not to be offensive with this, but... Continually asking for others people code without showing much of a "let me try and do it myself first" attitude is considered rude... Please show a little initiative in doing things for yourself, asking direct, educated questions and it will seem less like you are asking others to do your job for you...

Sorry about that, I love helping out other people... But only the ones that want to help themselves first...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Automation framework

Post by omayer » Wed Aug 24, 2011 7:37 pm

Thank you Ciege, it wil be good start for me to read the forum and blog.