Ejemplo n.º 1
0
        public bool ExecuteQuery(AutomationElement querySet, AutomationElement queryNode)
        {
            string exportDir = Path.Combine(_exportDirectory, querySet.GetName());
            if (!Directory.Exists(exportDir))
            {
                Directory.CreateDirectory(exportDir);
            }

            string fileName = Path.Combine(exportDir, queryNode.GetName() + ".html");
            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            queryNode.AddToSelection();

            var queryEditor = _mainWindow.FindChildByAutomationId("verticalSplit")
                .FindChildByIndex(ControlType.Pane, 1)
                .FindChildByAutomationId("tcQueries")
                .FindChildByName(queryNode.GetName());
            queryEditor.SetFocus();

            var btnPin = queryEditor
                .FindChildByAutomationId("QueryControl")
                .FindChildByAutomationId("panTop")
                .FindChildByAutomationId("btnPin");
            
            //Mouse.Click(btnPin.GetClickablePoint().ToDrawingPoint());

            var btnExecute = queryEditor
                .FindChildByAutomationId("QueryControl")
                .FindChildByAutomationId("panTop")
                .FindChildByAutomationId("btnExecute");
            btnExecute.Invoke();

            // sleep just enough to start the query and show the status bar
            Thread.Sleep(1000); 

            // wait for the status bar to say "Query sucessful"
            var panBottom = queryEditor
                .FindChildByAutomationId("QueryControl")
                .FindChildByAutomationId("panMain")
                .FindChildByAutomationId("splitContainer")
                .FindChildByIndex(ControlType.Pane, 1)
                .FindChildByAutomationId("panBottom");

            while (true)
            {
                var statusStrip = queryEditor
                    .FindChildByAutomationId("QueryControl")
                    .FindChildByAutomationId("statusStrip");

                if (statusStrip.FindChildByName("Query successful") !=null )
                    break;

                Thread.Sleep(100);
            }

            // export to html
            var mnuExport = panBottom
                .FindChildByName("toolStrip1")
                .FindChildByName("Export");
            mnuExport.Invoke();

            var mnuExportToHtml = mnuExport.FindChildByName("Export to HTML");
            mnuExportToHtml.Invoke();

            var dialog = _mainWindow.WaitForChild("Save Results", TimeSpan.FromSeconds(10));
            var editFilename = dialog
                .FindChildByIndex(ControlType.Pane, 0)
                .FindChildByAutomationId("FileNameControlHost")
                .FindChildByIndex(ControlType.Edit, 0);
            var save = dialog.FindChildByName("Save");

            editFilename.SetText(fileName);
            save.Invoke();
            _mainWindow.WaitForChildToDissapear("Save Results", TimeSpan.FromSeconds(10));

            if (_baselineDirectory != null)
            {
                string baseline = Path.Combine(_baselineDirectory, querySet.GetName(), queryNode.GetName() + ".html");

                string result = File.ReadAllText(fileName);
                string expected = File.ReadAllText(baseline);
                if (result != expected)
                {
                    return false;
                }

                Console.Write("...baseline matches...");
            }

            return true;
        }