This is a CodedUI blog which serves as a - One stop solution blog for all CodedUI related information.
Hope you enjoy this.
If anyone has any information it can be shared and also if any improvements can be made please let me know.
Few of the topics can be found in other blogs. My main moto is to share knowledge and also collecting the information
Tuesday, 17 June 2014
Object Repository Framework in CodedUI for Web applications- Type 1
Earlier when i used to work with QTP tool, the objects are well organised in the object repository and it was very easy for the maintenance or to update any properties of objects.
Where as in CUIT we face an issue with maintaining an object repository. Once we record any test case and check for UIMap.Designer.cs file we see all the controls added and its a mess to understand what exactly is happening.
After a little RnD, i have come with a object repository kind of framework for my project which i am working on. Thought of sharing so it would be helping even other.
As seen in the Figure1, there are two additional files which have been added i.e. DataDic.cs and ObjectRepository.csv.
Below are the steps to start with building a framework.
Adding the Parent Controls to UIMap.
As per the Figure2, UIGoogleDocument will be the parent map. Accordingly add all the parent controls in all the pages of you application. How to add a control without recording an action can be done as per the below link Adding-ui-control-to-uimap-without recording
Add an .csv file to the solution, i.e. ObjectRepository.csv file as showing in the Figure1.
Let the data be added in the csv file as shown below.(Note - don't have spaces. those spaces after comma are just for better understanding)
ObjectName, ObjectType, ParentObject, Property, Value
ObjectName is the unique name given for the each object. Parent Object is under which parent the object come. Property is what properties to be defined and value is the corresponding value for name provided
Add an DataDic.cs file, in which we define the DataDictionary and add the values in the DataDictionary by reading the values from excel sheet.
public class excelread
public static Dictionary<string, Dictionary<string, string>> dataKey = new Dictionary<string, Dictionary<string, string>>();
public void Readcsv()
string fullPathToExcel = @"C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CodedUITestProject1\CodedUITestProject1\ObjectRepository.csv";
StreamReader reader = new StreamReader(File.OpenRead(fullPathToExcel));
string line = reader.ReadLine().ToString();
string values = line.Split(',');
string key = values.ToString();
Dictionary<string, string> datavalues = new Dictionary<string, string>();