Coded UI Automation Testing: Functional Automation In VSTS2010

How to do Automation Testing Using Coded Ui Testing :
Once we are done with the recording of our navigation and doing some functional activity like logging into the gmail account or any other such event and wish to now view the code for the recording that sax been carried out, we can stop recording. Now suppose the same is to be done , just click on the last button within the small window in the right hand side corner in the below side of the computer screen.

Just click on the last button which has the word “Generate code” subscribed on it. Clicking this very button results all the UI activity getting coded down into C# scripts. This very language is in toto dependent on the type of language selected during the project creation window.  Clicking of this very Button opens up another pop up which has in it the field for writing the name of the coded scripts which in turn is modularized under the same function name . Now we are having a modularized functional block which does the complete activity that we had performed during the Recording time [here being the Logging into the Gmail Account]. Suppose we give the same function name as LogIntoGmail.
Now just close the record phase by clicking on the close button within the small pop up [i:e Record pop up]. The IDE of VSTS opens up within which we have the CodedUiTest file availed with the default name being the CodedUITest1.cs as can be seen in the Solution Explorer window .  Depending on the naming conventions we can just we may rename this very file as in this case can be “LogIntoGmail_Class_CUI.cs”.
After having renamed this the reference needs to be updated which is done automatically by the editor itself after clicking the confirmation option as asked by the same. Now just double click the CodedUI class file.  Within, the class file – a constructor is availed having the same name as is the name of the CodedUITest Fie in this case being : “LogIntoGmail_Class_CUI.cs”.  After delving into the class block we can find a yet another function name : LogIntoGmail. This name is the same as was the functiona name provided by us during the Add generate code button click.  The function call is only available here , so where is the code for the recordings we performed. Well the same can be discussed in some other columns , however for now what we can do is  keep this as taken for granted that in our project in which ever Coded UI Test Class file  we paste this very function call , and run the code, we will get the Playback for all the steps that we recorded.
I hope I am pretty lucid when I say this , to be more clear  just go into the Solution explorer and Right Click on the Project Name Which is already created by you , add another CodedUi Test File , and give its name as  “LogIntoGmail_Replica_Class_CUI.cs”. Now just double click the class file and under the constructor write a function call for the same set of playback as was achieved by the Previous recording by writing :  LogIntoGmail.   

 What will this do for us , Well a lot of Reusability cann be availed by this very functionality.  Now we have two Coded Ui Class files namely : LogIntoGmail_Class_CUI.cs & LogIntoGmail_Replica_Class_CUI.cs . Now save the complete Test Project  and plan for running your Automation Scripts. For the same purpose we can go into the Tools Menu and under it Window Menu – Go For Test View . This is actually the view which has in it the Various Class file names availed. Give a refresh to the Test View screen, we get the two class files names coming up in the same. Now , of the items available we can see two listed as : Run the first one LogIntoGmail_Class_CUI by clicking the same and giving a run button click. The recorded scenario will be played back . Now, Run the first one LogIntoGmail_Replica _Class_CUI by clicking the same and giving a run button click. The recorded scenario will be played back . This shows the Code Reusability. Will Take this to next level in future posts..

Post a Comment


Close Menu