Advertisement
Guest User

Aardvark Silverlight Coded UI Test

a guest
Apr 18th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.35 KB | None | 0 0
  1. using System.Threading.Tasks;
  2. using System;
  3. using System.CodeDom.Compiler;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.Text.RegularExpressions;
  7. using System.Windows.Input;
  8. using Microsoft.VisualStudio.TestTools.UITest.Extension;
  9. using Microsoft.VisualStudio.TestTools.UITesting;
  10. using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;
  11. using Microsoft.VisualStudio.TestTools.UITesting.SilverlightControls;
  12. using Microsoft.VisualStudio.TestTools.UITesting.WinControls;
  13. using Microsoft.VisualStudio.TestTools.UnitTesting;
  14. using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
  15. using Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse;
  16. using MouseButtons = System.Windows.Forms.MouseButtons;
  17.  
  18. namespace CUI
  19. {
  20.  
  21.     [CodedUITest]
  22.     public class MyUi : SilverlightControl
  23.     {
  24.         [TestMethod]
  25.         public void BasicCodedUiObjectModelTest()
  26.         {
  27.             SilverlightEdit uICalc1Edit = GetEditControl("http://localhost/DenSite/SmallSL01TestPage.html", "Calc1");
  28.             uICalc1Edit.Text = "42";
  29.             Playback.Wait(1000);
  30.         }
  31.  
  32.         private SilverlightEdit GetEditControl(string Url, string AutomationId)
  33.         {
  34.             IEWindow myBrowser = browserWindow(Url);
  35.             SilverlightDocument mySlDocument = myBrowser.SLDocument;
  36.             SilverlightDiv mySlDiv = mySlDocument.SLDiv;
  37.             SilverlightCustom mySlCustom = mySlDiv.SlCustom;
  38.             SilverlightUtilityControl mySLControl = mySlCustom.SLControl;
  39.             SilverlightEdit myEdit = mySLControl.MyEditControl(AutomationId);
  40.  
  41.             return myEdit;
  42.  
  43.            // return browserWindow(Url).SLDocument.SLDiv.SlCustom.SLControl.MyEditControl(AutomationId);
  44.         }
  45.  
  46.         public IEWindow browserWindow(string Url)
  47.         {
  48.  
  49.             if (_ieWindow == null)
  50.             {
  51.                 _ieWindow = new IEWindow(Url);
  52.             }
  53.             return _ieWindow;
  54.         }
  55.  
  56.         private IEWindow _ieWindow;
  57.     }
  58.  
  59.    //--
  60.  
  61.     public class IEWindow : BrowserWindow
  62.     {
  63.  
  64.         public IEWindow(string Url)
  65.         {
  66.             BrowserWindow.Launch(Url);
  67.         }
  68.  
  69.         public IEWindow()
  70.         {
  71.             SearchProperties[UITestControl.PropertyNames.Name] = "SmallSL01";
  72.         }
  73.  
  74.         public SilverlightDocument SLDocument
  75.         {
  76.             get
  77.             {
  78.                 if (_slDocument == null)
  79.                 {
  80.                     _slDocument = new SilverlightDocument(this);
  81.                 }
  82.                 return _slDocument;
  83.             }
  84.         }
  85.  
  86.         private SilverlightDocument _slDocument;
  87.  
  88.     } // UISmallSL01InternetExpWindow : BrowserWindow
  89.  
  90.     //--
  91.  
  92.     public class SilverlightDocument : HtmlDocument
  93.     {
  94.  
  95.         public SilverlightDocument(UITestControl searchLimitContainer) :
  96.             base(searchLimitContainer)
  97.         { }
  98.  
  99.         public SilverlightDiv SLDiv
  100.         {
  101.             get
  102.             {
  103.                 if (_slDiv == null)
  104.                 {
  105.                     _slDiv = new SilverlightDiv(this);
  106.                 }
  107.                 return _slDiv;
  108.             }
  109.         }
  110.  
  111.         private SilverlightDiv _slDiv;
  112.     }
  113.  
  114.     public class SilverlightDiv : HtmlDiv
  115.     {
  116.  
  117.         public SilverlightDiv(UITestControl searchLimitContainer) :
  118.             base(searchLimitContainer)
  119.         { }
  120.  
  121.         public SilverlightCustom SlCustom
  122.         {
  123.             get
  124.             {
  125.                 if (_slCustom == null)
  126.                 {
  127.                     _slCustom = new SilverlightCustom(this);
  128.                 }
  129.                 return _slCustom;
  130.             }
  131.         }
  132.  
  133.         private SilverlightCustom _slCustom;
  134.     } //UISilverlightControlHoPane : HtmlDiv
  135.  
  136.     public class SilverlightCustom : HtmlCustom
  137.     {
  138.  
  139.         public SilverlightCustom(UITestControl searchLimitContainer) :
  140.             base(searchLimitContainer)
  141.         { }
  142.  
  143.         public SilverlightUtilityControl SLControl
  144.         {
  145.             get
  146.             {
  147.                 if (_slUtilityControl == null)
  148.                 {
  149.                     _slUtilityControl = new SilverlightUtilityControl(this);
  150.                 }
  151.                 return _slUtilityControl;
  152.             }
  153.         }
  154.  
  155.         private SilverlightUtilityControl _slUtilityControl;
  156.     } //UIItemCustom : HtmlCustom
  157.  
  158.     //
  159.  
  160.     public class SilverlightUtilityControl : SilverlightControl
  161.     {
  162.  
  163.         public SilverlightUtilityControl(UITestControl searchLimitContainer) :
  164.             base(searchLimitContainer)
  165.         {
  166.             // This next line must be present - comment it out to see the Coded UI failures
  167.             SearchProperties[UITestControl.PropertyNames.ControlType] = "MainPage";
  168.         }
  169.  
  170.         public SilverlightEdit MyEditControl(string AutomationId)
  171.         {
  172.  
  173.             if (_slEditControl == null)
  174.             {
  175.                 // The next line must be present...
  176.                 _slEditControl = new SilverlightEdit(this);
  177.  
  178.                 // The next line must reference a control - break the name to see the error
  179.                 _slEditControl.SearchProperties[SilverlightEdit.PropertyNames.AutomationId] = AutomationId;
  180.             }
  181.             return this._slEditControl;
  182.         }
  183.  
  184.         private SilverlightEdit _slEditControl;
  185.  
  186.     } // UIMainPageMainPage : SilverlightControl
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement