Advertisement
Guest User

CUI01

a guest
Mar 22nd, 2015
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.69 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. [CodedUITest]
  19. public class MyUi : SilverlightControl
  20. {
  21.  
  22.     [TestMethod]
  23.     public void BasicCodedUiObjectModelTest()
  24.     {
  25.         BrowserWindow.Launch("http://localhost/DenSite/SmallSL01TestPage.html");
  26.         SilverlightEdit uICalc1Edit = GetEditControl();
  27.         uICalc1Edit.Text = "422f";
  28.         Playback.Wait(10000);
  29.     }
  30.  
  31.     private SilverlightEdit GetEditControl()
  32.     {
  33.         return browserWindow.SLDocument.SLDiv.SlCustom.SLControl.MyEditControl;
  34.     }
  35.  
  36.     public IEWindow browserWindow {
  37.         get {
  38.             if ((mUISmallSL01InternetExpWindow == null)) {
  39.                 mUISmallSL01InternetExpWindow = new IEWindow();
  40.             }
  41.             return mUISmallSL01InternetExpWindow;
  42.         }
  43.     }
  44.  
  45.     private IEWindow mUISmallSL01InternetExpWindow;
  46. }
  47.  
  48. public class IEWindow : BrowserWindow {
  49.     // ctor not needed for the basic test...
  50.     //public UISmallSL01InternetExpWindow()
  51.     //{
  52.     //    #region Search Criteria
  53.     //    //this.SearchProperties[UITestControl.PropertyNames.Name] = "SmallSL01";
  54.     //    //this.SearchProperties[UITestControl.PropertyNames.ClassName] = "IEFrame";
  55.     //    //this.WindowTitles.Add("SmallSL01");
  56.     //    #endregion
  57.     //}
  58.  
  59.     public SilverlightDocument SLDocument
  60.     {
  61.         get {
  62.             mUISmallSL01Document = null; // debug
  63.             if ((mUISmallSL01Document == null)) {
  64.                 mUISmallSL01Document = new SilverlightDocument(this);
  65.             }
  66.             return mUISmallSL01Document;
  67.         }
  68.     }
  69.  
  70.     private SilverlightDocument mUISmallSL01Document;
  71.  
  72. } // UISmallSL01InternetExpWindow : BrowserWindow
  73.  
  74. public class SilverlightDocument : HtmlDocument {
  75.  
  76.     public SilverlightDocument(UITestControl searchLimitContainer) :
  77.         base(searchLimitContainer)
  78.     {
  79.        // this.SearchProperties[HtmlDocument.PropertyNames.Id] = null;
  80.        // this.SearchProperties[HtmlDocument.PropertyNames.RedirectingPage] = "False";
  81. //this.SearchProperties[HtmlDocument.PropertyNames.FrameDocument] = "False";
  82.        // this.FilterProperties[HtmlDocument.PropertyNames.Title] = "SmallSL01";
  83.         //this.FilterProperties[HtmlDocument.PropertyNames.AbsolutePath] = "/DenSite/SmallSL01TestPage.html";
  84.         //this.FilterProperties[HtmlDocument.PropertyNames.PageUrl] = "http://localhost/DenSite/xSmallSL01TestPage.html";
  85.         this.WindowTitles.Add("SmallSL01");
  86.  
  87.     }
  88.  
  89.     public SilverlightDiv SLDiv
  90.     {
  91.         get
  92.         {
  93.             if ((mUISilverlightControlHoPane == null))
  94.             {
  95.                 mUISilverlightControlHoPane = new SilverlightDiv(this);
  96.             }
  97.             return mUISilverlightControlHoPane;
  98.         }
  99.     }
  100.  
  101.     private SilverlightDiv mUISilverlightControlHoPane;
  102.  
  103. }
  104.  
  105. public class SilverlightDiv : HtmlDiv
  106. {
  107.  
  108.     public SilverlightDiv(UITestControl searchLimitContainer) :
  109.         base(searchLimitContainer)
  110.     {
  111.         #region Search Criteria
  112.         //this.SearchProperties[HtmlDiv.PropertyNames.Id] = "silverlightControlHost";
  113.         //this.SearchProperties[HtmlDiv.PropertyNames.Name] = null;
  114.         //this.FilterProperties[HtmlDiv.PropertyNames.InnerText] = null;
  115.         //this.FilterProperties[HtmlDiv.PropertyNames.Title] = null;
  116.         //this.FilterProperties[HtmlDiv.PropertyNames.Class] = null;
  117.         //this.FilterProperties[HtmlDiv.PropertyNames.ControlDefinition] = "id=\"silverlightControlHost\"";
  118.         //this.FilterProperties[HtmlDiv.PropertyNames.TagInstance] = "1";
  119.         //this.WindowTitles.Add("SmallSL01");
  120.         #endregion
  121.     }
  122.  
  123.     public SilverlightCustom SlCustom
  124.     {
  125.         get
  126.         {
  127.             if ((this.mUIItemCustom == null))
  128.             {
  129.                 this.mUIItemCustom = new SilverlightCustom(this);
  130.             }
  131.             return this.mUIItemCustom;
  132.         }
  133.     }
  134.  
  135.     private SilverlightCustom mUIItemCustom;
  136. } //UISilverlightControlHoPane : HtmlDiv
  137.  
  138. public class SilverlightCustom : HtmlCustom
  139. {
  140.  
  141.     public SilverlightCustom(UITestControl searchLimitContainer) :
  142.         base(searchLimitContainer)
  143.     {
  144.         //this.SearchProperties["TagName"] = "OBJECT";
  145.         //this.SearchProperties["Id"] = null;
  146.         //this.SearchProperties[UITestControl.PropertyNames.Name] = null;
  147.         //this.FilterProperties["Class"] = null;
  148.         //this.FilterProperties["ControlDefinition"] = "width=\"100%\" height=\"100%\" data=\"data:ap";
  149.         //this.FilterProperties["TagInstance"] = "1";
  150.         //this.WindowTitles.Add("SmallSL01");
  151.     }
  152.  
  153.     public SilverlightUtilityControl SLControl
  154.     {
  155.         get
  156.         {
  157.             if ((this.mUIMainPageMainPage == null))
  158.             {
  159.                 this.mUIMainPageMainPage = new SilverlightUtilityControl(this);
  160.             }
  161.             return this.mUIMainPageMainPage;
  162.         }
  163.     }
  164.  
  165.     private SilverlightUtilityControl mUIMainPageMainPage;
  166. } //UIItemCustom : HtmlCustom
  167.  
  168. public class SilverlightUtilityControl : SilverlightControl
  169. {
  170.  
  171.     public SilverlightUtilityControl(UITestControl searchLimitContainer) :
  172.         base(searchLimitContainer)
  173.     {
  174.         // This next line must be present - comment it out to see the Coded UI failures
  175.         this.SearchProperties[UITestControl.PropertyNames.ControlType] = "MainPage";
  176.         //this.WindowTitles.Add("SmallSL01");
  177.  
  178.     }
  179.  
  180.     public SilverlightEdit MyEditControl {
  181.         get
  182.         {
  183.             mmahEdit = null; //debug
  184.             if ((this.mmahEdit == null))
  185.             {
  186.                 // The next line must be present...
  187.                 mmahEdit = new SilverlightEdit(this);
  188.  
  189.                 // The next line must reference a control - break the name to see the error
  190.                 this.mmahEdit.SearchProperties[SilverlightEdit.PropertyNames.AutomationId] = "Calc1";
  191.                 //this.mmahEdit.WindowTitles.Add("SmallSL01");
  192.  
  193.             }
  194.             return this.mmahEdit;
  195.         }
  196.     }
  197.  
  198.     private SilverlightEdit mmahEdit;
  199.  
  200. } // UIMainPageMainPage : SilverlightControl
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement