Exemplo n.º 1
0
        /// <summary>
        /// Closes the XamlBrowserHost application
        /// </summary>
        public void Close()
        {
            if (monitor != null)
            {
                //remove the UiaDistributedTestcaseHost from the remote site because we are about to close the host process
                //

                remoteHost = null;

                //Close the host process
                monitor.Close();
                monitor  = null;
                hWndHost = IntPtr.Zero;

                //give some time for the app to shutdown
                Thread.Sleep(2000);
            }
        }
Exemplo n.º 2
0
        internal void RunTest(UiaDistributedTestcaseHost host, AutomationElement automationElement, string uiElementName)
        {
            if (stepInfos.Count == 0)
            {
                throw new InvalidOperationException("You must first add one or more steps run this testcase");
            }

            //Because we the Testcase object has a MarshalByRef shared state, we
            //need to ensure that we have a server channel in this AppDomain.
            //


            //attach the testcase to the host
            host.AttachTestcase(this, uiElementName);

            //run all the steps
            int nextStep = 0;

            try
            {
                for (int i = 0; i < stepInfos.Count; i++)
                {
                    nextStep = i + 1;
                    UiaDistributedStepInfo stepInfo = stepInfos[i];

                    //Invoke with the automation element, otherwise have the host invoke it with the UIElement
                    if (stepInfo.Target == UiaDistributedStepTarget.AutomationElement)
                    {
                        PerformStep(i, automationElement);
                    }
                    else //UiElement
                    {
                        host.PerformStep(i);
                    }
                }
            }
            finally
            {
                //run any remaining steps marked "alwaysRun"
                for (int i = nextStep; i < stepInfos.Count; i++)
                {
                    UiaDistributedStepInfo stepInfo = stepInfos[i];
                    if (!stepInfo.AlwaysRun)
                    {
                        continue;
                    }

                    try
                    {
                        //Invoke with the automation element, otherwise have the host invoke it with the UIElement
                        if (stepInfo.Target == UiaDistributedStepTarget.AutomationElement)
                        {
                            PerformStep(i, automationElement);
                        }
                        else //UiElement
                        {
                            host.PerformStep(i);
                        }
                    }
                    catch (Exception e)
                    {
                        //Because these are clean up steps we ---- exceptions thrown by them
                        GlobalLog.LogDebug("AlwaysRun Step Failed with the following exception: " + e.ToString());
                    }
                }
            }
        }