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; 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[] files; Regex rx = new Regex(@"^(.*\\SketchAssistant\\)"); Match match = rx.Match(TestContext.DeploymentDirectory); String SketchAssistDir = match.Groups[1].Value; try { files = Directory.GetFiles(SketchAssistDir + @"SketchAssistantWPF\bin\", "SketchAssistantWPF.exe", SearchOption.AllDirectories); } catch { Regex rx_0 = new Regex(@"^(.*\\projects\\)"); Match match_0 = rx_0.Match(TestContext.DeploymentDirectory); String ProjectsDir = match_0.Groups[1].Value; files = Directory.GetFiles(ProjectsDir, "SketchAssistantWPF.exe", SearchOption.AllDirectories); } ProcessStartInfo processStart = new ProcessStartInfo(files[0], "-debug"); application = Application.Launch(processStart); return application.GetWindow("Sketch Assistant"); } [TestMethod] [TestCategory("bla")] public void CreateCanvasTest() { Window mainWindow = setupapp(); Thread.Sleep(20); Assert.AreEqual("none", mainWindow.Get(SearchCriteria.ByAutomationId("LastActionBox")).Text.ToString()); mainWindow.Get