Page 1 of 1

How to make generic function for different type of controls

Posted: Tue Sep 11, 2012 3:42 am
by omayer
how to create generic functions that will work for all same type controls like enter on textfield, click on radio button since i am running into lots of controls into a page which i don't want to create each functions for each controls. Thank you in Advance

Re: How to make generic function for different type of controls

Posted: Tue Sep 11, 2012 8:17 am
by sdaly
You can achieve this by using the Adapter type -

Code: Select all

Button b = "/button[@text='Start']";
DoSomething(b);

public static void DoSomething(Adapter a){
	a.Click();
}
Not a generic method, but should work for you!

Re: How to make generic function for different type of controls

Posted: Wed Sep 12, 2012 2:48 am
by omayer
Thank you Sdaly to look into it.
testcase 1. need to create customer > enterfname, enterlname, enteraddress, click on save button
how will i make reusable function that will do enterfname, enterlname, enteraddres
currently i have - enterfname(string fname);
public void enterfname(string fname)
{
inputtag fnameField = "/dom@asdf.....";
fnameField .value=fname;

}

but the problem i have to create four separate functions

Re: How to make generic function for different type of controls

Posted: Wed Sep 12, 2012 6:45 am
by sham526
U can try like this:
Pass the inputTag also as the parameter, so that it can be a reusable function.

public void enterfname(string fname,InputTag myTag)
{
inputtag fnameField = myTag
fnameField .value=fname;
-------------
-------------
}

Re: How to make generic function for different type of controls

Posted: Wed Sep 12, 2012 3:31 pm
by omayer
Thank you so much, this is very helpful with sample code.

is this how will i call the function
enterfname("joe",fnamefield)

public void enterfname(string fname,InputTag myTag)
{
inputtag fnameField = myTag ----- where do i defined the rxpath or how to find the fnamefield
fnameField .value=fname;
-------------
-------------
}

Re: How to make generic function for different type of controls

Posted: Thu Sep 13, 2012 6:22 am
by sham526
If the elements were stored in Repository then simply call the function as below.
enterfname("joe",Recording1.Repo.------.MyinpTag)

Re: How to make generic function for different type of controls

Posted: Fri Sep 14, 2012 5:37 pm
by omayer
elements were NOT stored in Repository

Re: How to make generic function for different type of controls

Posted: Tue Sep 18, 2012 6:39 am
by sham526
Sorry for the late response.In that case search for each element before calling the function.
Example(In Vb.Net)
Dim btn_ok as InputTag=nothing
Dim bool as boolean=Host.Local.TryfindSingle("./dom[]//InputTag[@InnerText='ok']",btn_ok)

If bool then
'Call the Function that clicks the btn.
enterfname("joe",btn_ok)
Else
'OK Button was NOT Found.
'Report it to the result and log files.
EndIf

'Same case for Cancel button also.
Dim btn_Cancel as InputTag=nothing
Dim bool as boolean=Host.Local.TryfindSingle("./dom[]//InputTag[@InnerText='cancel']",btn_cancel)

If bool then
'Call the Function that clicks the btn.
enterfname("joe",btn_cancel)
Else
'Cancel Button was NOT Found.
'Report it to the result and log files.
EndIf

Re: How to make generic function for different type of controls

Posted: Wed Sep 19, 2012 5:03 pm
by omayer
Thank you Sham526, this is very helpful

Re: How to make generic function for different type of controls

Posted: Thu Sep 20, 2012 6:17 am
by sham526
:D