UITest.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 Window 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. return application.GetWindow("Sketch Assistant");
  29. }
  30. [TestMethod]
  31. public void CreateCanvasTest()
  32. {
  33. Window mainWindow = setupapp();
  34. Thread.Sleep(20);
  35. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  36. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  37. Thread.Sleep(20);
  38. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  39. mainWindow.Close();
  40. }
  41. [TestMethod]
  42. public void DrawLineTest()
  43. {
  44. Window mainWindow = setupapp();
  45. Thread.Sleep(20);
  46. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  47. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  48. Thread.Sleep(20);
  49. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  50. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  51. Thread.Sleep(20);
  52. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  53. Thread.Sleep(20);
  54. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  55. Thread.Sleep(7000);
  56. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  57. mainWindow.Close();
  58. }
  59. /*[TestMethod]
  60. public void DeleteLineTest()
  61. {
  62. Window mainWindow = setupapp();
  63. Thread.Sleep(20);
  64. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  65. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  66. Thread.Sleep(20);
  67. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  68. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  69. Thread.Sleep(20);
  70. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  71. Thread.Sleep(20);
  72. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  73. Thread.Sleep(7000);
  74. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  75. Thread.Sleep(20);
  76. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("DeleteButton")).Click();
  77. Thread.Sleep(20);
  78. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  79. Thread.Sleep(20);
  80. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  81. Thread.Sleep(20);
  82. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugThree")).Click();
  83. Thread.Sleep(24000);
  84. Assert.AreEqual("Last Action: Line number 0 was deleted", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  85. mainWindow.Close();
  86. }*/
  87. [TestMethod]
  88. public void UndoTest()
  89. {
  90. Window mainWindow = setupapp();
  91. Thread.Sleep(20);
  92. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  93. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  94. Thread.Sleep(20);
  95. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  96. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  97. Thread.Sleep(20);
  98. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  99. Thread.Sleep(20);
  100. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  101. Thread.Sleep(7000);
  102. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  103. Thread.Sleep(20);
  104. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  105. Thread.Sleep(20);
  106. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  107. mainWindow.Close();
  108. }
  109. [TestMethod]
  110. public void RedoTest()
  111. {
  112. Window mainWindow = setupapp();
  113. Thread.Sleep(20);
  114. Assert.AreEqual("none", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  115. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("CanvasButton")).Click();
  116. Thread.Sleep(20);
  117. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  118. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("EditMenuButton")).Click();
  119. Thread.Sleep(20);
  120. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugMode")).Click();
  121. Thread.Sleep(20);
  122. mainWindow.Get<Menu>(SearchCriteria.ByAutomationId("DebugOne")).Click();
  123. Thread.Sleep(7000);
  124. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  125. Thread.Sleep(20);
  126. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("UndoButton")).Click();
  127. Thread.Sleep(20);
  128. Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  129. Thread.Sleep(20);
  130. mainWindow.Get<Button>(SearchCriteria.ByAutomationId("RedoButton")).Click();
  131. Thread.Sleep(20);
  132. Assert.AreEqual("Last Action: Line number 0 was drawn.", mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString());
  133. mainWindow.Close();
  134. }
  135. }
  136. }