Data Parameterization In Coded Ui Automation Testing Using VSTS

Data Parameterization In Coded Ui Automation Using VSTS:

Data parameterization is one of the high priority task whenever you are into Automating the testing of certain Modules that have been stabilized for future releases.

To progress successfully in parameterizing the data content within the scripts is what needs to be approached for not only technically,  but also very logically.  Normally in Other automation tools the Data Parameterization tool we prefer is Excel, however in VSTS Coded Ui automation we prefer CSV Files which are a bit complicated to handle and are a bit limited in terms of robustness and user comfort in handling data interpretation for a user who has not been into the data creation right from the beginning of the data setup.

Some commands that serve a lot of purpose in this regard belong to the Class "TestContext". This very class contains in it all the required functions that ease out the Automation handling onto the data present in the Coded Ui scripts. The very genuine example that we can take forward from hereon will be the same scenario as was previously discussed - the login into gmail account.
If we go by the recorded scripts the playback results into logging into the application by the same user again and again. However, if at all in future the user changes some of its data , the code might just not do the needful of logging into the system for him, and the complete effort might go in vain. Herein let us discuss the methodology of parameterizing the UserId and password from some external source such as "CSV" in our case.

Create a CSV file and add two columns in it in the excel sheet format. Suppose we have named it as GlobalParams.csv. In it just have two columns as UserId and Password. Now under the userId Column just enter your Userid which you use to log into the Gmail account, and under the password column do enter your password. Hitherto, we have just entered the two fields that is expected to be changed and can be handled from outside the application Recorded scripts. Save the csv file and close the same. Now we have data driven Automation Testing in our picture.

How to link up the CSV file to our CodedUi test file :

For this go to the Tools - Windows - Test View. Within the Test View we can see the Class file methods  available . Just Right click the Method name which has the Login functionality recorded in its code block. Go into data field and just provide the path of the csv file which you have created right now.

After having linked up the csv file with the Test View class method, we have our data in the csv linked up in our respective class method's code blocks. Go into the CodedUiTest Method by double clicking the class emthod wherein you added the csv path. Just before the function call just override the data content from the UIMap.designer.cs file by assigning the value to the fields in the below format :

        TestContext.Datarow["UserId"].Tostring;
        Playback.Encrypttext(TestContext.Datarow["UserId"].Tostring);

The code above is very simple especially the first one is pretty explanatory in its own sense. TestContext is the Class name that has all the methods that is needed to handle to complete the access of the data from within the csv file. Datarow is the method of the class TestContext whihc helps uys fetch data from the Particular row which is mentioned in the Square brackets. The Tostring method is used to convert datatype into string .

The second one might be creating some eye scare , but it is nothing new. Like in QTP for password protected field we go for QTP encryption tool,similarly in VSTS  we do it herein code itsel by using the Playback.Encrypttext method.

[Do Note that Playback is a yet another class that needs to be kept tracked of and can be brought ot tremendous use for our scripting purpose]

Some other properties that can be used repeatedly are Playback.wait series methods.

Now with the two codes above we can fetch data from csv file , but where are we going to assign them,
For this we need to navigate to the function definition which is in the UImap.designer.cs file. Just double click the Class Method from Test View. The function call is there, double click the function name ,Press F12 button automatically the control flows to the Code segment which was captured during the Record Time. Find for the commented section that has the UserId you entered in green. Just take the code below the Commented line having the series : This.....  . And paste it in the Function call segment just before the Function call so that the recorded values are overridden by these values fetched from the csv. Do not forget to add UIMap just after This. in the line , so that the new segment would look like This.UImap.... .

Similarly parameterize the Pasword field as well so that now the Playback will be done for the data combination provided in the CSV file and is independent from the Record time values.

Hereby we have been able to introduce the Data Driven Automated Testing model into the Recorded scenario.





0 comments:

Post a Comment