Forum Discussion

naplespoet's avatar
naplespoet
New Contributor
14 years ago

Function creation with C#script

I'm new to c# and I used to use winrunner before HP days and one thing I used in functions were the parameters to push in so that when the function ran it would set the text value as to what I passed into the function call.

essentially I need to find out first how that part of the function is created and then how to then, when i pass the function in that value gets set in my text field.  I know im missing the value set in the function name , not sure how to set that up and how the text field knows that even though these are declared during this test run I only want to use what I passed in and not actually hardcode what User1/Pass1  into the text field expression.  Please help. Im reading as much as I can but cant seem to find a good example.



function Login ()



{


var User1;



var Pass1;


var Pass2;




    User1 = testuser     // username for textbox

    Pass1 = testpass     // password for textbox

    Pass2 = testpass01     // password for textbox



    form = page["table"]["cellSmall"]["table"]["formLogin"];


    textbox = form["cellSmall"]["textboxUserName"];


    textbox["Click"](16, 11);


    textbox["Text"] = "testuser";   // this would need to express value of what parameter I passed in grabbing it to  declared  values


    form["cell"]["passwordboxPassword"]["Text"] = "testpass";   // this would need to express value of what parameter I passed in grabbing it to declared values






 

1 Reply

  • Hi,



    I'm new to c# and I used to use winrunner before HP days and one thing I used in functions were the parameters to push in so that when the function ran it would set the text value as to what I passed into the function call.


    essentially I need to find out first how that part of the function is created



    See the code below, it explains how this should be done:

    function main() 

    {


        var User1 = "testuser";


        var Pass1 = "testpass";


        Login(User1, Pass1);


    }



    function Login(user, password)


    {


        //...


        form = page["table"]["cellSmall"]["table"]["formLogin"];


        textbox = form["cellSmall"]["textboxUserName"];


        textbox["Click"](16, 11);


        textbox["Text"] = user;   


        form["cell"]["passwordboxPassword"]["Text"] = password;




    If you need to pass several user/password pairs, I recommend that you consider data-driven testing.