UITest.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.IO;
  3. using System.Reflection;
  4. using Microsoft.VisualStudio.TestTools.UnitTesting;
  5. using TestStack.White;
  6. using TestStack.White.UIItems;
  7. using TestStack.White.UIItems.WindowItems;
  8. using TestStack.White.UIItems.Finders;
  9. using System.Threading;
  10. using SketchAssistantWPF;
  11. using System.Windows;
  12. using System.Diagnostics;
  13. using TestStack.White.UIItems.WindowStripControls;
  14. using TestStack.White.UIItems.MenuItems;
  15. namespace WhiteTests
  16. {
  17. [TestClass]
  18. public class UITest
  19. {
  20. private TestStack.White.Application application;
  21. public void setupapp()
  22. {
  23. string outputDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  24. string editedDir = outputDir.Replace("WhiteTests", "SketchAssistantWPF");
  25. string app_path = editedDir + @"\SketchAssistantWPF.exe";
  26. ProcessStartInfo processStart = new ProcessStartInfo(app_path, "-debug");
  27. application = Application.Launch(processStart);
  28. Window mainWindow = application.GetWindow("Sketch Assistant");
  29. }
  30. [TestMethod]
  31. public void CreateCanvasTest()
  32. {
  33. setupapp();
  34. Window mainWindow = application.GetWindow("Sketch Assistant");
  35. Thread.Sleep(20);
  36. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  37. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  38. Thread.Sleep(20);
  39. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  40. mainWindow.Close();
  41. }
  42. [TestMethod]
  43. public void DrawLineTest()
  44. {
  45. setupapp();
  46. Window mainWindow = application.GetWindow("Sketch Assistant");
  47. Thread.Sleep(20);
  48. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  49. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  50. Thread.Sleep(20);
  51. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  52. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  53. Thread.Sleep(20);
  54. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  55. Thread.Sleep(20);
  56. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  57. Thread.Sleep(7000);
  58. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  59. mainWindow.Close();
  60. }
  61. }
  62. }