public static IDisposable LaunchAndConnectToPrinterEmulator(this AutomationRunner testRunner, string make = "Airwolf 3D", string model = "HD", bool runSlow = false)
        {
            // Load the TestEnv config
            var config = TestAutomationConfig.Load();

            // Create the printer
            MatterControlUtilities.AddAndSelectPrinter(testRunner, make, model);

            Emulator emulator = new Emulator();

            emulator.PortName = config.Printer;
            emulator.RunSlow  = runSlow;

            emulator.Startup();

            // edit the com port
            SystemWindow containingWindow;
            var          editButton = testRunner.GetWidgetByName("Edit Printer Button", out containingWindow);

            testRunner.Delay(() => editButton.Enabled, 5);             // Wait until the edit button is ready to click it. Ensures the printer is loaded.
            testRunner.ClickByName("Edit Printer Button", 3);

            testRunner.ClickByName("Serial Port Dropdown", 3);

            testRunner.ClickByName(config.MCPort + " Menu Item", 5);

            testRunner.ClickByName("Cancel Wizard Button");

            // connect to the created printer
            testRunner.ClickByName("Connect to printer button", 2);

            testRunner.WaitForName("Disconnect from printer button", 5);

            return(emulator);
        }
        public static async Task RunTest(
            AutomationTest testMethod,
            string staticDataPathOverride      = null,
            double maxTimeToRun                = 60,
            QueueTemplate queueItemFolderToAdd = QueueTemplate.None,
            int overrideWidth        = -1,
            int overrideHeight       = -1,
            string defaultTestImages = null)
        {
            // Walk back a step in the stack and output the callers name
            StackTrace st = new StackTrace(false);

            Debug.WriteLine("\r\n ***** Running automation test: {0} {1} ", st.GetFrames().Skip(1).First().GetMethod().Name, DateTime.Now);

            if (staticDataPathOverride == null)
            {
                // Popping one directory above MatterControl, then back down into MatterControl ensures this works in MCCentral as well and MatterControl
                staticDataPathOverride = TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl", "StaticData");
            }

#if DEBUG
            string outputDirectory = "Debug";
#else
            string outputDirectory = "Release";
#endif

            Environment.CurrentDirectory = TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl", "bin", outputDirectory);

#if !__ANDROID__
            // Set the static data to point to the directory of MatterControl
            StaticData.Instance = new FileSystemStaticData(staticDataPathOverride);
#endif
            // Popping one directory above MatterControl, then back down into MatterControl ensures this works in MCCentral as well and MatterControl
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl"));

            if (queueItemFolderToAdd != QueueTemplate.None)
            {
                string queueTemplateDirectory = queueItemFolderToAdd.ToString();
                MatterControlUtilities.AddItemsToQueue(queueTemplateDirectory);
            }

            if (defaultTestImages == null)
            {
                defaultTestImages = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestImages");
            }

            UserSettings.Instance.set(UserSettingsKey.ThumbnailRenderingMode, "orthographic");
            //GL.HardwareAvailable = false;
            MatterControlApplication matterControlWindow = MatterControlApplication.CreateInstance(overrideWidth, overrideHeight);

            var config = TestAutomationConfig.Load();

            // Extract mouse speed from config
            AutomationRunner.TimeToMoveMouse = config.TimeToMoveMouse;

            await AutomationRunner.ShowWindowAndExecuteTests(matterControlWindow, testMethod, maxTimeToRun, defaultTestImages, config.AutomationInputType);
        }
Beispiel #3
0
        public static Emulator LaunchAndConnectToPrinterEmulator(this AutomationRunner testRunner, string make = "Airwolf 3D", string model = "HD", bool runSlow = false)
        {
            SystemWindow systemWindow;

            testRunner.GetWidgetByName("Hardware Tab", out systemWindow, 10);
            // make sure we wait for MC to be up and running
            testRunner.WaitforDraw(systemWindow);

            // Load the TestEnv config
            var config = TestAutomationConfig.Load();

            // Override the heat up time
            Emulator.DefaultHeatUpTime = config.HeatupTime;

            // Override the temp stabilization time
            WaitForTempStream.WaitAfterReachTempTime = config.TempStabilizationTime;

            // Create the printer
            testRunner.AddAndSelectPrinter(make, model);

            // Force the configured printer to use the emulator driver
            ApplicationController.Instance.ActivePrinter.Settings.SetValue("driver_type", "Emulator");

            // edit the com port
            testRunner.SwitchToPrinterSettings();

            var serialPortDropDown = testRunner.GetWidgetByName("com_port Field", out _, 1);

            testRunner.WaitFor(() => serialPortDropDown.Enabled);             // Wait until the serialPortDropDown is ready to click it. Ensures the printer is loaded.

            testRunner.ClickByName("com_port Field");

            testRunner.ClickByName("Emulator Menu Item");

            // connect to the created printer
            testRunner.ClickByName("Connect to printer button");

            testRunner.WaitForName("Disconnect from printer button");

            // Access through static instance must occur after Connect has occurred and the port has spun up
            Emulator.Instance.RunSlow = runSlow;

            return(Emulator.Instance);
        }
Beispiel #4
0
        public static Process LaunchAndConnectToPrinterEmulator(AutomationRunner testRunner, bool runSlow = false, string make = "Airwolf 3D", string model = "HD")
        {
            // Load the TestEnv config
            var config = TestAutomationConfig.Load();

            // Create the printer
            MatterControlUtilities.AddAndSelectPrinter(testRunner, make, model);

            var process = new Process();

            process.StartInfo = new ProcessStartInfo()
            {
                FileName  = "python",
                Arguments = string.Format("{0} {1}{2}",
                                          StaticData.Instance.MapPath("../PrinterEmulator.py"),
                                          config.Printer,
                                          runSlow ? " slow" : ""),

                WindowStyle = ProcessWindowStyle.Minimized
            };

            process.Start();

            // edit the com port
            testRunner.ClickByName("Edit Printer Button");
            testRunner.Wait(2);

            testRunner.ClickByName("Com Port Dropdown");

            testRunner.ClickByName(config.MCPort + " Menu Item", 1);

            testRunner.ClickByName("Cancel Wizard Button");

            // connect to the created printer
            testRunner.ClickByName("Connect to printer button", 2);

            testRunner.Wait(2);

            return(process);
        }
Beispiel #5
0
        public static async Task RunTest(
            AutomationTest testMethod,
            string staticDataPathOverride      = null,
            double maxTimeToRun                = 60,
            QueueTemplate queueItemFolderToAdd = QueueTemplate.None,
            int overrideWidth        = -1,
            int overrideHeight       = -1,
            string defaultTestImages = null)
        {
            // Walk back a step in the stack and output the callers name
            //StackTrace st = new StackTrace(false);
            //Debug.WriteLine("\r\n ***** Running automation test: {0} {1} ", st.GetFrames().Skip(1).First().GetMethod().Name, DateTime.Now);

            if (staticDataPathOverride == null)
            {
                // Popping one directory above MatterControl, then back down into MatterControl ensures this works in MCCentral as well and MatterControl
                staticDataPathOverride = TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl", "StaticData");
            }

#if DEBUG
            string outputDirectory = "Debug";
#else
            string outputDirectory = "Release";
#endif

            Environment.CurrentDirectory = TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl", "bin", outputDirectory);

            // Override the default SystemWindow type without config.json
            AggContext.Config.ProviderTypes.SystemWindowProvider = "MatterHackers.Agg.UI.OpenGLWinformsWindowProvider, agg_platform_win32";

#if !__ANDROID__
            // Set the static data to point to the directory of MatterControl
            AggContext.StaticData = new FileSystemStaticData(staticDataPathOverride);
#endif
            // Popping one directory above MatterControl, then back down into MatterControl ensures this works in MCCentral as well and MatterControl
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl"));

            if (queueItemFolderToAdd != QueueTemplate.None)
            {
                MatterControlUtilities.AddItemsToQueue(queueItemFolderToAdd.ToString());
            }

            if (defaultTestImages == null)
            {
                defaultTestImages = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestImages");
            }

            UserSettings.Instance.set(UserSettingsKey.ThumbnailRenderingMode, "orthographic");
            //GL.HardwareAvailable = false;

            var config = TestAutomationConfig.Load();
            if (config.UseAutomationDialogs)
            {
                AggContext.Config.ProviderTypes.DialogProvider = "MatterHackers.Agg.Platform.AutomationDialogProvider, GuiAutomation";
            }

            // Extract mouse speed from config
            AutomationRunner.TimeToMoveMouse = config.TimeToMoveMouse;
            AutomationRunner.UpDelaySeconds  = config.MouseUpDelay;

            // Automation runner must do as much as program.cs to spin up platform
            string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms";
            AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider);
            AppContext.Platform.ProcessCommandline();

            var(width, height) = RootSystemWindow.GetStartupBounds();

            rootSystemWindow = Application.LoadRootWindow(
                overrideWidth == -1 ? width : overrideWidth,
                overrideHeight == -1 ? height : overrideHeight);

            OemSettings.Instance.ShowShopButton = false;

            if (!config.UseAutomationMouse)
            {
                AutomationRunner.InputMethod = new WindowsInputMethods();
            }

            await AutomationRunner.ShowWindowAndExecuteTests(
                rootSystemWindow,
                testMethod,
                maxTimeToRun,
                defaultTestImages,
                closeWindow : () =>
            {
                if (ApplicationController.Instance.ActivePrinter.Connection.CommunicationState == CommunicationStates.Printing)
                {
                    ApplicationController.Instance.ActivePrinter.Connection.Disable();
                }

                rootSystemWindow.Close();
            });
        }