Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Showing posts with label Data driven testing. Show all posts
Showing posts with label Data driven testing. Show all posts

Multiple Iteration Data Driven Code Ui Testing

 How  to Data driving a Test project in Visual Studio Using Coded Ui Testing for multiple Couded Ui Class files for varying iterations:

For long this has been a debatable issue as to how we can unleash the data driving functionality in the Automation Testing that needs to be done in the Visual Studio tool using its Test project feature. We utilize the Coded Ui Test approach for functional automation testing to achieve the same. With initial hiccups always going to ramp down the confidence one can repose in a tool, I am sure that with experience and devoted mindset the same can be overcome and the great quality this tool has in it can be leveraged with slight knowledge of the usage of the hierarchy available therein.
We already have gone through the tool basics on how it does object recognition and how it undergoes the test effort automatically , but when it comes to take the data drving approach we might just encounter some hiccups as has been outlined by some of my colleagues in the IT industry with tons of mail shooting into my inbox on their inability to do the data driving for the test projects. The error they complain or more clinically speaking the shortcoming the tool has in it is that when we need to data drive the test file wherein separate Coded ui Class file has separate number of iterations to be undergone, the Coded Ui Test approach does not meet the expectation of the automation gurus in the IT sector !

How good that holds is for all of us to take a call on but as a matter of fact the approach that we try to adopt in data driving our test files need to be addressed first and that might just provide a necessary resolution of the problems that we encounter.

As has been provided at the  below link [ Mahe's mail ]http://www.articlesontesting.com/2011/07/issues-in-visual-studio-coded-ui.html the issue is simple . The Test project created by the user has in it three Coded Ui Test files  addressing three different business scenarios, and the business requirement that needs to be addressed is that the three different coded ui Test files need to iterate different number of times. The below description is definitely going to clear the cloud on this.
Three business scenarios are as under :
1.       One being the Login Scenario
2.       Second being the business requiremenmt such as doing some search event/transaction.
3.       Third being the Log Out Scenario.
The traditional approach we have been following is have a single data file with all data in it. The same can be adopted with this set of scenarios as well, but it definitely will involve some degree of coding and technical skills which we can avoid by transforming our approach to test the same.

Have one data sheet file in csv format for the Login Scenario.
Have one data sheet file in csv format for the search event.
Third scenario is definitely not dependent on data set up.

But one general issue that would be pondered upon is how to run all the three in unison .
This has a solution in the following approach . Just add an ordered test file by using the following link.
And then call them in the order the business requirement is. First Login Coded ui test file, then Search Coded uI test file and then finally log out Coded Ui test file.

The business runs smooth and also the effort and expertise you need to implement the same is very less .
That indeed is quite a good degree of ROI.

DataSheet Import in QTP

In QTP very often we need to import the run time data contents into some external excel sheet for genuinely important reason that is report generation as well as status tracking.

How can we import a datatable is been outlined as under?

Dim strFileName
strFileName ="C:\AutomationProject1\Report.xls"
datatable.ImportSheet strFileName,"sheet1","Global"
rCount=Datatable.GetRowCount
Datatable.GetSheet("Global").Addparameter "C",""
For i=1 to rCount
 datatable.SetCurrentRow(i)
 x=datatable.Value("A",Global)
 y=datatable.Value("B",Global)
 val=cint(x)+cint (y)
 msgbox val
datatable.Value("C", Global)= val
Next
datatable.Export strFileName

For gaining more insights in the automation using QTP log on to below url :

Automation Testing Using QTP


SetCurrentRow Method In QTP

Data Driven Testing is the most important aspect within the framework of the Automation Testing.
Some methods have a lot of relevance when we concentrate on the automation of a module using this very technique.


Sets the specified row as the current (active) row in the run-time Data Table.
Important Information
  • You can set a row only if it contains at least one value.
  • If you call another action (local or external) after performing this method, then when you return to the current action after the called action is complete, the current row in the action sheet is reset to the row corresponding to the current iteration (regardless of the value previously set in the DataTable.SetCurrentRow step.)
Syntax
DataTable.SetCurrentRow(RowNumber)


The following example uses the SetCurrentRow method to change the active row to the second row in the global run-time Data Table.
DataTable.SetCurrentRow (2)
The example below performs the equivalent of renaming a column (parameter) in the DataTable by copying the data from one column to a new column with a new name, and then deleting the old column.
'add a new column
DataTable.GetSheet("dtGlobalSheet").AddParameter "NewColumn","Row1Value"

'copy the cells from the old column into the new column
cnt=DataTable.GetRowCount
For i=1 to cnt
       DataTable.SetCurrentRow(i)
       OldVal=DataTable.Value("OldColumn","dtGlobalSheet")
       DataTable.Value("NewColumn","dtGlobalSheet")=OldVal
Next

'delete the old column
DataTable.GetSheet("dtGlobalSheet").DeleteParameter("OldColumn")


Coded UI Automation Testing Walkthrough : Data Parameterization from CSV File

Now we will externalize data from a csv file in the following unit. Just create a csv file using excel sheet as is mentioned below. Though the file location is not at all a point of concern, yet we can avoid the same by keeping it in the project directory itself just in case the same project needs to be run from some other machine, the debug still works well.


Some Related posts on Coded UI Testing using VSTS :
 





Yeah we have created a csv file and have linked it up from the CodedUiTest file, via Test view. Right click to click its properies and follow up.








Now the automated script has been data driven in the true sense , and now if you change the userid and password in the csv file, the script will log you into the respective accounts.

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.





Datasheet Handling in Data driven Testing4 - QTP

QTP Datadriven testing : Parameter in Datasheet programming :

A parameter (column) in a sheet in the run-time Data Table. This object is not a built-in utility object, but can be accessed using one of the following methods:

    * DTSheet.AddParameter
    * DTSheet.GetParameter

      Note: All methods performed on this object apply to the run-time DataTable object only. Changes to the run-time DataTable object are reflected in the test results, but the design-time Data Table is not affected.

Associated Properties

    * Name Property
    * RawValue Property
    * Value Property
    * ValueByRow Property

Example:AddParameter

The following example uses the AddParameter method to create the new Parameter, "Arrival" within the new sheet, MySheet of the run-time Data Table, and sets the first cell in the column as "New York". Because the method also returns the newly created parameter, it is possible to use methods or check properties of the new sheet within the same statement.

ParamName=DataTable.AddSheet("MySheet").AddParameter("Arrival", "New York").Name

Note that if a parameter with the name "Arrival" already exists in the sheet, the example above will return "Arrival1" as the actual name assigned to the new parameter.

The example below performs the equivalent of renaming a column (parameter) in the DataTable by copying the data from one column to a new column with a new name, and then deleting the old column.

'add a new column
DataTable.GetSheet("dtGlobalSheet").AddParameter "NewColumn","Row1Value"

'copy the cells from the old column into the new column
cnt=DataTable.GetRowCount
For i=1 to cnt
       DataTable.SetCurrentRow(i)
       OldVal=DataTable.Value("OldColumn","dtGlobalSheet")
       DataTable.Value("NewColumn","dtGlobalSheet")=OldVal
Next

'delete the old column
DataTable.GetSheet("dtGlobalSheet").DeleteParameter("OldColumn")

GetParameter  Example

The following example uses the GetParameter method to return the "Destination" parameter from the run-time Data Table sheet: MySheet.

DataTable.GetSheet("MySheet").GetParameter("Destination")

Name  Example

The following example uses the Name method to return the name of the newly created parameter in the run-time Data Table and writes it in the report.

Dim paramname

paramname = DataTable.LocalSheet.AddParameter("Food", "pizza").Name

Reporter.ReportEvent 1, "The New Parameter name is", paramname

RawValue  Example

The following example uses the RawValue property to find the formula used in the current row of the Date column in the ActionA sheet of the run-time Data Table. The statement below returns the value: =NOW()

FormulaVal=DataTable.GetSheet("ActionA").GetParameter("Date").RawValue

Value Example

The following example uses the Value property to set the value in the current row of the Destination parameter (column) in the "ActionA" sheet of the run-time Data Table.

DataTable.GetSheet("ActionA").GetParameter("Destination").Value="New York"

Note: You could omit the word Value in the statement above, because Value is the default property for the DTParameter object.

Example ValueByRow

The following example uses the ValueByRow property to find the value in the 4th row of the Destination parameter (column) in the "ActionA" sheet of the run-time Data Table.

DataTable.GetSheet("ActionA").GetParameter("Destination").ValueByRow(4)

Datasheet Handling in Data driven Testing1 - QTP

Description

A sheet in the run-time Data Table. This object is not a built-in utility object, but can be accessed using one of the following methods or properties:

  • DataTable.AddSheet  
  • DataTable.GetSheet
  • DataTable.GlobalSheet
  • DataTable.LocalSheet

    Notes:
    All methods performed on this object apply to the run-time DataTable object only. Changes to the run-time DataTable object are reflected in the test results, but the design time Data Table is not affected.
    When working with scripted components, the name of the (single) Data Sheet is identical to the name of scripted component. If you save the scripted component with a new name, the name of the data sheet changes accordingly.

Associated Methods

  • AddParameter Method

  • DeleteParameter Method

  • GetCurrentRow Method

  • GetParameter Method

  • GetParameterCount Method

  • GetRowCount Method

  • SetCurrentRow Method

  • SetNextRow Method

  • SetPrevRow Method

Associated Properties

  • Name Property



DataTable.AddSheet(SheetName)


Argument

Type

Description

SheetName

String

Assigns a name to the new sheet.

Return Value

DTSheet Object.

Example

The following example uses the AddSheet method to create the new sheet, "MySheet" in the run-time Data Table and then adds a parameter to the new sheet.

Variable=DataTable.AddSheet ("MySheet").AddParameter("Time", "8:00") 


DataTable.GetSheet(SheetID)


Argument

Type

Description

SheetID

Variant

Identifies the sheet to be returned. The Sheet ID can be the sheet name or index. Index values begin with 1.

Return Value

DTSheet Object

Examples

The following example uses the GetSheet method to return the "MySheet" sheet of the run-time Data Table and add a parameter to it.

MyParam=DataTable.GetSheet ("MySheet").AddParameter("Time", "8:00")

You can also use this to add a parameter to the "MySheet" local sheet (note that no value is returned).

DataTable.GetSheet ("MySheet").AddParameter "Time", "8:00"

The example below performs the equivalent of renaming a column (parameter) in the DataTable by copying the data from one column to a new column with a new name, and then deleting the old column.

'add a new column
DataTable.GetSheet("dtGlobalSheet").AddParameter "NewColumn","Row1Value"

'copy the cells from the old column into the new column
cnt=DataTable.GetRowCount
For i=1 to cnt
       DataTable.SetCurrentRow(i)
       OldVal=DataTable.Value("OldColumn","dtGlobalSheet")
       DataTable.Value("NewColumn","dtGlobalSheet")=OldVal
Next

'delete the old column
DataTable.GetSheet("dtGlobalSheet").DeleteParameter("OldColumn")

DataTable.GlobalSheet

Example

The following example uses the GlobalSheet property to return the global sheet of the run-time Data Table in order to add a parameter (column) to it.

ParamValue=DataTable.GlobalSheet.AddParameter("Time", "5:45")

You can also use this method to add a parameter to the global sheet (note that no value is returned).

DataTable.GlobalSheet.AddParameter "Time", "5:45"


DataTable.LocalSheet

Example

The following example uses the LocalSheet property to return the local sheet of the run-time Data Table in order to add a parameter (column) to it.


Data Driven Approach - QTP Automation

Data Driven Approach: In Automation testing

Data driven approach advocates externalizing the test data from the test automation tool (usually into an Excel sheet; Databases, XML files or other data sources may be used as well), to improve the maintainability of test data. It is aimed at helping business users to manipulate the test data without having to modify the actual scripts. It is also helpful when we need to drive a test script with multiple sets of input data. For example: running the same script for different roles/user id’s.
Pros:
·         Avoids hard-coding of test data in the scripts
·         Non-technical users can easily change the test data using the Excel sheets, without modifying the scripts in any way
·         The same script can easily be executed with multiple rows of test data
·         Reasonably simple to implement

Cons:
·         Provide features for non technical business users to interact with the framework

Demonstration on parameterizing data using QTP Datasheet

Step 1 - Go to Automation à Record and Run Settings, and open the ch1blogs site in a new IE Browser.



Step 2 - Click on Automation à Record/F3/ Record from the Tool bar. 

Based on Step 1 perform the following operations  –
·         An IE browser opens up with the URL https:\\ch1blogs
·         A User Authentication window pops up asking the user to enter the User Id and Password
·         Enter the details and the user is navigated to Blogs Home Page.
·         Click on Explore à View My Blog which navigates the user to the Blog Site page.

When you see the same in the script, (QTP – Explore View), the operations are recorded with hardcoded values for User Id and Password.

User name is the User Id entered and Password is the encrypted version of the Password entered during recording.




If we hard code these values, we cannot run the same script on several sets of data.  Hence we need to parameterize these values.

Data Drive the values using QTP Datasheet

Step 1 – Go to Tools à Data Driver

 The following window will be displayed with all hard coded values.


In my case User Id and Password are the hardcoded values and hence the value of “Constants” is 1(since it is a Constant Value) and the value of “Parameterized” is 0, since the value is not Parameterized yet.

Step 2 - Click Parameterize…  Select Parameterization Type window appears as below. 

Step 3

·         Step by Step Parameterization is selected by default, to perform a Step by Step Parameterization of the objects.

·         Parameterize All, parameterizes all the objects at a stretch.

·         Select Step by Step Parameterization and Click on Next.



Step 4 –

·         Parameterize the Selected Step appears with the hierarchy of the operations performed displayed in the left.

·         Select the hardcoded value – UserName in our case and click on the icon next to the Parameter – called Parameter Options


Step 5 –

·         When clicked on the Parameter Options, Parameter Options is displayed.

·         Since we are parameterizing through QTP data table, we select Data Table option under Parameter Types

·         Edit the Name to any Logical Name, to be the column name in the Data Table.
(The left screen below gives the Name, generated by the tool and LoginId (name in the right screen) is the name given by the user.

         


Step 6

·         Select the location where the column LoginId should exist in the Data Table.  By default the option is Global sheet. 

·         It can be Global or Local based on the usage of the value.

·         If the variable has to be used multiple times for various iterations, it is put in Local, if it has to be used once it is normally put in Global.


Step 7 – Click OK

Step 8

·         The user is back in “Parameterize the Selected Step”.

·         Click FINISH.

Step 9

·         Now the user is back in “Data Driver”

·         Now the User Name value is no more a Constant and it is Parameterized.

·         Hence the value for Constant becomes 0 and the value for Parameterized becomes 1.



Step 10 – Click OK

Step 11

·         Now the QTP script has changed from hardcoded 132218 to the Parameterized value.

·         The hardcoded value “132218” is replaced by DataTable(“LoginId”,dtGlobalSheet)

·         LoginId is the column name given to the Parameterized value and dtGlobalSheet is the location, the LoginId column is available in the Data Sheet.

·         In the Data Table(left bottom), you can view the Input Parameter LoginId, with the value, and in the Active Screen to the right the User name column is highlighted.





·         The advantage of using the Data Driver is the value need not be hardcoded and any number of LoginIds can be passed to work on multiple logins.

·         Several iterations can be performed with same or different sets of data.

·         The test data can be changed as and when needed without touching the script.