si eres del tipo de persona que por cada línea de código que escribe, siempre está pensando en la o las pruebas unitarias asociadas a la misma; seguramente te habrás preguntado porqué es tan dificil crear pruebas automáticas para aplicaciones Windows?. Yo ya he escrito algo sobre las capacidades para las Coded UI Tests que podremos disfrutar dentro de poco en Visual Studio 2010, pero una de las tecnologías detrás de todo este tinglado es la Microsoft UI Automations Library y la verdad es que si bien es muy potente, es un tanto complicada de implementar.
He creado mi prueba de escritorio con la calculadora, y después de ejecutar la herramienta para crear un “wrapper” de la calculadora
he generado el siguiente código que me permitirá trabajar con la Calculadora con un modelo de objetos bastante comprensible.
1: using Core.UIItems;
2: using Core.UIItems.WindowItems;
3: using Repository;
4: public partial class Calculator : Repository.AppScreen {
5: private Core.UIItems.WindowStripControls.MenuBar Application;
6: private Core.UIItems.Panel ;
7: private Core.UIItems.Image ;
8: [Repository.ScreenAttributes.AutomationIdAttribute("Running History")]
9: private Core.UIItems.Label RunningHistory;
10: [Repository.ScreenAttributes.IndexAttribute("20", 0)]
11: private Core.UIItems.Label 20;
12: [Repository.ScreenAttributes.IndexAttribute("21", 1)]
13: private Core.UIItems.Label 21;
14: private Core.UIItems.Label Memory;
15: [Repository.ScreenAttributes.AutomationIdAttribute("Memory clear")]
16: private Core.UIItems.Button Memoryclear;
17: [Repository.ScreenAttributes.AutomationIdAttribute("Memory recall")]
18: private Core.UIItems.Button Memoryrecall;
19: [Repository.ScreenAttributes.AutomationIdAttribute("Memory store")]
20: private Core.UIItems.Button Memorystore;
21: [Repository.ScreenAttributes.AutomationIdAttribute("Memory add")]
22: private Core.UIItems.Button Memoryadd;
23: [Repository.ScreenAttributes.AutomationIdAttribute("Memory subtract")]
24: private Core.UIItems.Button Memorysubtract;
25: private Core.UIItems.Button Backspace;
26: [Repository.ScreenAttributes.AutomationIdAttribute("Clear entry")]
27: private Core.UIItems.Button Clearentry;
28: private Core.UIItems.Button Clear;
29: private Core.UIItems.Button Negate;
30: [Repository.ScreenAttributes.AutomationIdAttribute("Square root")]
31: private Core.UIItems.Button Squareroot;
32: private Core.UIItems.Button 7;
33: private Core.UIItems.Button 8;
34: private Core.UIItems.Button 9;
35: private Core.UIItems.Button Divide;
36: private Core.UIItems.Button Percentage;
37: private Core.UIItems.Button 4;
38: private Core.UIItems.Button 5;
39: private Core.UIItems.Button 6;
40: private Core.UIItems.Button Multiply;
41: private Core.UIItems.Button Reciprocal;
42: private Core.UIItems.Button 1;
43: private Core.UIItems.Button 2;
44: private Core.UIItems.Button 3;
45: private Core.UIItems.Button Subtract;
46: private Core.UIItems.Button Equals;
47: private Core.UIItems.Button 0;
48: [Repository.ScreenAttributes.AutomationIdAttribute("Decimal separator")]
49: private Core.UIItems.Button Decimalseparator;
50: private Core.UIItems.Button Add;
51: protected Calculator() {
52: }
53: public Calculator(Core.UIItems.WindowItems.Window window, Repository.ScreenRepository screenRepository) :
54: base(window, screenRepository) {
55: }
56: }
Obviamente, el proyecto está un poco verde, pero pinta muy bien y a partir de este punto es cuando puede ser interesante, especialmente teniendo en cuenta que soporta además de Winforms, WPF y Silverlight.