using System; using System.IO; using System.Reflection; using Microsoft.VisualStudio.TestTools.UnitTesting; using TestStack.White; using TestStack.White.UIItems; using TestStack.White.UIItems.WindowItems; using TestStack.White.UIItems.Finders; using System.Threading; using SketchAssistantWPF; using System.Windows; using System.Diagnostics; using TestStack.White.UIItems.WindowStripControls; using TestStack.White.UIItems.MenuItems; using System.Collections.Generic; using System.Text.RegularExpressions; using WindowsInput; using WindowsInput.Native; using System.Threading.Tasks; using System.Linq; using Application = TestStack.White.Application; using Window = TestStack.White.UIItems.WindowItems.Window; namespace WhiteTests { [TestClass] public class UITest { private TestStack.White.Application application; /// /// The directory of the input files, saved for repeated use /// private String input_file_dir = null; /// /// instance of TestContext to be able to access deployed files /// private TestContext testContextInstance; /// ///Gets or sets the test context which provides ///information about and functionality for the current test run. /// public TestContext TestContext { get { return testContextInstance; } set { testContextInstance = value; } } /// /// A function that returns the path to the test_input_files folder. /// Do with it what you want. /// /// the path to the test_input_files folder public String getSketchAssistantDirectory() { Regex rx = new Regex(@"^(.*\\SketchAssistant\\)"); Match match = rx.Match(TestContext.DeploymentDirectory); String SketchAssistDir = match.Groups[1].Value; if (input_file_dir == null) { if (Directory.Exists(SketchAssistDir + @"WhiteTests\test_input_files\")) { input_file_dir = SketchAssistDir + @"WhiteTests\test_input_files\"; } else if (Directory.Exists(SketchAssistDir + @"WhiteTests\bin\Debug\test_input_files\")) { input_file_dir = SketchAssistDir + @"WhiteTests\bin\Debug\test_input_files\"; } else { Regex rx_0 = new Regex(@"^(.*\\projects\\)"); Match match_0 = rx_0.Match(TestContext.DeploymentDirectory); String ProjectsDir = match_0.Groups[1].Value; var dirs = Directory.GetDirectories(ProjectsDir, "test_input_files", SearchOption.AllDirectories); input_file_dir = dirs[0]; } } return input_file_dir; } public Window setupapp() { string outputDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string editedDir = outputDir.Replace("WhiteTests", "SketchAssistantWPF"); string app_path = editedDir + @"\SketchAssistantWPF.exe"; ProcessStartInfo processStart = new ProcessStartInfo(app_path, "-debug"); application = Application.Launch(processStart); return application.GetWindow("Sketch Assistant"); } [DataTestMethod] [TestCategory("FileIO")] [DataRow("line")] public void LoadSVGFileTest(String filename) { Window mainWindow = setupapp(); InputSimulator inputSimulator = new InputSimulator(); Thread.Sleep(30); string[] files = Directory.GetFiles(getSketchAssistantDirectory() + @"\whitelisted", "*.svg", SearchOption.AllDirectories); Thread.Sleep(30); mainWindow.Get(SearchCriteria.ByAutomationId("LoadMenuButton")).Click(); Thread.Sleep(30); mainWindow.Get(SearchCriteria.ByAutomationId("SVGMenuButton")).Click(); Thread.Sleep(1000); inputSimulator.Keyboard.TextEntry(getSketchAssistantDirectory() + @"whitelisted\" + filename + ".svg"); Thread.Sleep(1000); inputSimulator.Keyboard.KeyPress(VirtualKeyCode.RETURN); Thread.Sleep(1000); //Assert.AreEqual("Last Action: A new canvas was created.", mainWindow.Get(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString()); mainWindow.Close(); } [TestMethod] [TestCategory("DirectInput")] public void DrawLineOnCanvasTest() { Window mainWindow = setupapp(); Thread.Sleep(30); InputSimulator inputSimulator = new InputSimulator(); MouseSimulator mouseSimulator = new MouseSimulator(inputSimulator); Assert.AreEqual("none", mainWindow.Get(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString()); mainWindow.Get