Advertisement
ekostadinov

WebAii test

Apr 1st, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.92 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4. using ArtOfTest.WebAii.Core;
  5. using ArtOfTest.WebAii.Silverlight;
  6. using ArtOfTest.WebAii.Silverlight.UI;
  7. using Microsoft.VisualStudio.TestTools.UnitTesting;
  8. using System.Globalization;
  9. using DBServer.Selenium.Silvernium.Fixtures;
  10. //using NUnit.Framework;
  11. using System.Windows.Automation;
  12. using System.Windows.Automation.Text;
  13. using System.Diagnostics; // for Process
  14. using System.Threading; // for Thread.Sleep()
  15. using Microsoft.VisualStudio.TestTools.UnitTesting;
  16. using NUnit.Framework;
  17. using OpenQA.Selenium;
  18. using OpenQA.Selenium.Firefox;
  19. using Selenium;
  20. using ThoughtWorks.Selenium.Silvernium;
  21. using Telerik.WebAii;
  22. using Telerik.WebAii.Controls;
  23. using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
  24. using Button = ArtOfTest.WebAii.Controls.Xaml.Wpf.Button;
  25. using TestContext = Microsoft.VisualStudio.TestTools.UnitTesting.TestContext;
  26.  
  27.  
  28. namespace FuncTest
  29. {
  30.     /// <summary>
  31.     /// Summary description for WebAii
  32.     /// </summary>
  33.     [TestClass]
  34.     public class WebAii
  35.     {
  36.         private Browser browser { get; set; }
  37.         private const string URL = "http://demos.telerik.com/silverlight/";
  38.        
  39.         public WebAii()
  40.         {
  41.             //
  42.             // TODO: Add constructor logic here
  43.             //
  44.         }
  45.  
  46.         private TestContext testContextInstance;
  47.  
  48.         /// <summary>
  49.         ///Gets or sets the test context which provides
  50.         ///information about and functionality for the current test run.
  51.         ///</summary>
  52.         public TestContext TestContext
  53.         {
  54.             get
  55.             {
  56.                 return testContextInstance;
  57.             }
  58.             set
  59.             {
  60.                 testContextInstance = value;
  61.             }
  62.         }
  63.  
  64.         #region Additional test attributes
  65.         //
  66.         // You can use the following additional attributes as you write your tests:
  67.         //
  68.         // Use ClassInitialize to run code before running the first test in the class
  69.         // [ClassInitialize()]
  70.         // public static void MyClassInitialize(TestContext testContext) { }
  71.         //
  72.         // Use ClassCleanup to run code after all tests in a class have run
  73.         // [ClassCleanup()]
  74.         // public static void MyClassCleanup() { }
  75.         //
  76.         // Use TestInitialize to run code before running each test
  77.         // [TestInitialize()]
  78.         // public void MyTestInitialize() { }
  79.         //
  80.         // Use TestCleanup to run code after each test has run
  81.         // [TestCleanup()]
  82.         // public void MyTestCleanup() { }
  83.         //
  84.         #endregion
  85.  
  86.         public void SetUp()
  87.         {
  88.             //Settings.Current.Web.EnableSilverlight = true;
  89.             Settings.WebSettings web = new Settings.WebSettings();
  90.             Settings.WpfSettings wpf = new Settings.WpfSettings();
  91.             Settings set = new Settings(web, wpf);
  92.             Manager man = new Manager(false);
  93.             man.Start();
  94.            
  95.             Manager.Current.LaunchNewBrowser();
  96.             browser = Manager.Current.ActiveBrowser;
  97.  
  98.            
  99.         }
  100.  
  101.         public void TearDown()
  102.         {
  103.             browser.Close();
  104.         }
  105.        
  106.         [TestMethod]
  107.         public void TestWeb()
  108.         {
  109.             Settings mySettings = new Settings();
  110.             mySettings.Web.DefaultBrowser = BrowserType.FireFox;
  111.             mySettings.Web.EnableSilverlight = true;
  112.             Manager myManager = new Manager(mySettings);
  113.             myManager.Start();
  114.             myManager.LaunchNewBrowser();
  115.             // Navigate to the page
  116.             //myManager.ActiveBrowser.NavigateTo(URL, false);
  117.            
  118.             // Launch a browser instance
  119.             browser = Manager.Current.ActiveBrowser;
  120.             browser.NavigateTo(URL, false);
  121.             browser.WaitUntilReady();
  122.             var aframes = browser.Frames;
  123.             var adesktop = browser.Desktop;
  124.             var time = browser.CommandTimeOut;
  125.             var tree = browser.DomTree;
  126.             var nodes = tree.Root.ChildNodes;
  127.             var child = tree.Root.Children;
  128.  
  129.  
  130.  
  131.             // Get an instance of our Silverlight app.
  132.             SilverlightApp app = browser.SilverlightApps()[0];
  133.  
  134.             var xmllist = app.Find.AllByType<Button>();
  135.             var uilist = app.Find.AllByType<ArtOfTest.WebAii.Silverlight.UI.Button>();
  136.             var idlist = app.Find.AllByAutomationId("radButton");
  137.            
  138.             var byname = app.Find.AllByName("EXPLORE ALL CONTROLS");
  139.             var text = app.Find.AllByTextContent("EXPLORE ALL CONTROLS");
  140.             app.RefreshVisualTrees();
  141.            
  142.  
  143.             // Click the button
  144.             var btn = app.FindName<ArtOfTest.WebAii.Silverlight.UI.Button>("EXPLORE ALL CONTROLS");
  145.             btn.User.Click();
  146.            
  147.             // Verify the text
  148.            
  149.         }
  150.     }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement