public override string DefaultDescription(MappedItem control)
        {
            string description = "Validates that the text at ({0},{1}) on {2} is equal to \"{3}\"";
            string controlName = control == null ? "<Unset Control>" : control.Name;

            return string.Format(description, X, Y, controlName, Text);
        }
Пример #2
0
        public override bool Play(MappedItem control, Log log)
        {
            string expectedText = expressionParam.GetValue();

            if (expectedText == null)
                expectedText = "";

            foreach (Variable v in this.TestItem.Test.Variables.OrderBy(v => v.Name.Length))
            {
                expectedText = expectedText.Replace(v.Name, "\"" + v.Value + "\"");
            }

            var expression = new CompiledExpression(expectedText);

            try
            {
                EvaluatedResult = (bool)expression.Eval();

            }
            catch (Exception ex)
            {
                //expression was not a boolean
            }

            if (EvaluatedResult)
            {
                foreach (TestItem testItem in this.TestItem.TestItems)
                {
                    testItem.Play(log);
                }
            }

            return true;
        }
Пример #3
0
        public override string DefaultDescription(MappedItem mappedItem)
        {
            if(mappedItem == null)
                return string.Format("Enters \"{0}\"", textParam.Value);

            return string.Format("Enters \"{0}\" in the '{1}' object", textParam.Value, mappedItem.FriendlyName);
        }
Пример #4
0
        public override bool Play(MappedItem mappedItem, Log log)
        {
            string text = textParam.GetValue();
            Keyboard.SendKeys(text);

            AppProcess process = AppManager.GetProcess(mappedItem);
            MappedItem window = AppManager.GetWindow(mappedItem);

            IUIItem uiItem = AppPlaybackService.GetControl(process, window, mappedItem, AppManager);

            AutomationElement findWindowElement = uiItem.AutomationElement;

            while (findWindowElement.Current.LocalizedControlType != "window"
                && !(findWindowElement.Current.LocalizedControlType == "pane"
                 && TreeWalker.ControlViewWalker.GetParent(findWindowElement).Current.LocalizedControlType == "process"))
            {
                findWindowElement = TreeWalker.ControlViewWalker.GetParent(findWindowElement);
            }

            Screenshot screenshot = CreateScreenshot(log, findWindowElement.Current.NativeWindowHandle);

            screenshot.Adornments.Add(
                new ControlHighlightAdornment
                {
                    X = (int)uiItem.Bounds.X - (int)findWindowElement.Current.BoundingRectangle.X,
                    Y = (int)uiItem.Bounds.Y - (int)findWindowElement.Current.BoundingRectangle.Y,
                    Width = (int)uiItem.Bounds.Width,
                    Height = (int)uiItem.Bounds.Height
                });

            string description = string.Format("The text '{0}' was entered in {1}", text, mappedItem.Name);
            log.CreateLogItem(LogItemCategory.Event, description, screenshot);

            return true;
        }
Пример #5
0
        public override bool Play(MappedItem control, Log log)
        {
            Variable variable = this.TestItem.Test.Variables.FirstOrDefault(v => v.Name.Equals(variableParam.Value));
            variable.Value = valueParam.GetValue();

            log.CreateLogItem(LogItemCategory.Message, string.Format("Variable '{0}' was set to value: {1}", variable.Name, variable.Value));

            return true;
        }
Пример #6
0
        public override bool Play(MappedItem control, Log log)
        {
            log.CreateLogItem(LogItemCategory.Event, nameParameter.GetValue());
            log.StartLogItemChildren();

            foreach (TestItem testItem in TestItem.TestItems)
            {
                if (!testItem.Play(log))
                    return false;
            }

            log.EndLogItemChildren();
            return true;
        }
Пример #7
0
        public override bool Play(MappedItem control, Log log)
        {
            double seconds;

            if (!double.TryParse(delayParameter.GetValue(), out seconds))
            {
                log.CreateLogItem(LogItemCategory.Error, "Not a valid value for seconds", null);
                return false;
            }

            Thread.Sleep(TimeSpan.FromSeconds(seconds));
            log.CreateLogItem(LogItemCategory.Event, string.Format("Delayed {0} second(s)", seconds));

            return true;
        }
Пример #8
0
        public override bool Play(MappedItem control, Log log)
        {
            string testName = testNameParam.GetValue();
            string filePath =
                this.TestItem.Test.Project.TestFiles.First(
                    t => t.Name.Substring(0, t.Name.Length - DefaultData.TestExtension.Length).Equals(testName)).FilePath;

            Test test = testFileManager.Open(filePath);
            test.Project = TestItem.Test.Project;

            log.CreateLogItem(LogItemCategory.Event, string.Format("Running test: {0}", testName));
            log.StartLogItemChildren();
            test.Play(log);
            log.EndLogItemChildren();
            return true;
        }
Пример #9
0
        public override bool Play(MappedItem control, Log log)
        {
            var previousTestItems = TestItem.Parent.TestItems.TakeWhile(t => !t.Equals(this.TestItem)).Reverse();

            TestItem ifTestItem = previousTestItems.FirstOrDefault(t => t.Operation is IfOperation);

            bool execute = ifTestItem == null || !(ifTestItem.Operation as IfOperation).EvaluatedResult;

            if (execute)
            {
                foreach (TestItem testItem in this.TestItem.TestItems)
                {
                    testItem.Play(log);
                }
            }

            return true;
        }
        public override bool Play(MappedItem control, Log log)
        {
            Variable variable = this.TestItem.Test.Variables.FirstOrDefault(v => v.Name.Equals(variableParam.Value));

            AppProcess process = AppManager.GetProcess(control);
            MappedItem window = AppManager.GetWindow(control);

            IUIItem uiItem = AppPlaybackService.GetControl(process, window, control, AppManager);
            Point clickPoint = new Point(X, Y);
            Point globalPoint = new Point((int)uiItem.Bounds.X + clickPoint.X, (int)uiItem.Bounds.Y + clickPoint.Y);

            Screenshot screenshot = CreateScreenshot(log);

            Cursor.LeftClick(globalPoint);
            string actualText = CopyText();

            variable.Value = actualText;

            log.CreateLogItem(LogItemCategory.Message, string.Format("Variable '{0}' was set to value: {1}", variable.Name, variable.Value));

            return true;
        }
        public override bool Play(MappedItem control, Log log)
        {
            VariableOperationParameterValue variableOperationParameterValue = variableParameter.ParameterValue as VariableOperationParameterValue;

            Variable variable = variableOperationParameterValue.GetVariable();

            variable.CurrentTableRow = 0;

            for (int i = 0; i < variable.DataTableValue.Rows.Count; i++)
            {
                foreach (TestItem testItem in TestItem.TestItems)
                {
                    if (!testItem.Play(log))
                        return false;
                }

                variable.CurrentTableRow++;
            }

            variable.CurrentTableRow = 0;

            return true;
        }
        public override bool Play(MappedItem control, Log log)
        {
            Variable variable = this.TestItem.Test.Variables.FirstOrDefault(v => v.Name.Equals(variableParam.Value));

            string filePath = filePathParam.GetValue();

            string[] fileLines = File.ReadAllLines(filePath);

            DataTable dataTable = variable.DataTableValue;

            //string[] columnNames = variable.DataTableValue.Columns.OfType<DataColumn>().Select(c => c.ColumnName).ToArray();

            dataTable.Clear();

            foreach (string row in fileLines)
            {
                string[] fields = row.Split(',');
                dataTable.Rows.Add(fields);
            }

            log.CreateLogItem(LogItemCategory.Message, string.Format("Variable '{0}' was set from file : {1}", variable.Name, filePath));

            return true;
        }
Пример #13
0
        public override bool Play(MappedItem mappedItem, Log log)
        {
            AppProcess process = AppManager.GetProcess(mappedItem);
            MappedItem window = AppManager.GetWindow(mappedItem);

            IUIItem uiItem = AppPlaybackService.GetControl(process, window, mappedItem, AppManager);
            AutomationElement findWindowElement = ExternalAppInfoManager.GetWindowAutomationElement(uiItem);

            Point clickPoint = this.GetClickPoint(CreateScreenshot(log, findWindowElement.Current.NativeWindowHandle, false));
            Point globalPoint = new Point((int)uiItem.Bounds.X + clickPoint.X, (int)uiItem.Bounds.Y + clickPoint.Y);

            Cursor.Position = globalPoint;

            Screenshot screenshot = CreateScreenshot(log, findWindowElement.Current.NativeWindowHandle);
            screenshot.Adornments.Add(
                new ControlHighlightAdornment
                {
                    X = (int)uiItem.Bounds.X - (int)findWindowElement.Current.BoundingRectangle.X,
                    Y = (int)uiItem.Bounds.Y - (int)findWindowElement.Current.BoundingRectangle.Y,
                    Width = (int)uiItem.Bounds.Width,
                    Height = (int)uiItem.Bounds.Height
                });

            Cursor.LeftClick(globalPoint);

            string description = string.Format("The {0} was clicked with the left mouse button", mappedItem.Type);

            log.CreateLogItem(LogItemCategory.Event, description, screenshot);

            int screenshotX = globalPoint.X - (int)findWindowElement.Current.BoundingRectangle.X;
            int screenshotY = globalPoint.Y - (int)findWindowElement.Current.BoundingRectangle.Y;

            screenshot.Adornments.Add(new ClickAdornment { ClickX = screenshotX, ClickY = screenshotY });

            return true;
        }
 public override string DefaultDescription(MappedItem control)
 {
     return string.Format("Set table variable {0} from file {1}", variableParam.Value, filePathParam.Value);
 }
Пример #15
0
 public override string DefaultDescription(MappedItem control)
 {
     return string.Format("Message: {0}", messageParameter.Value);
 }
Пример #16
0
        public static IUIItem GetControl(AppProcess process, MappedItem window, MappedItem control, AppManager appManager)
        {
            Process wProcess = Process.GetProcessesByName(process.Name).First();
            Application application = Application.Attach(wProcess);

            Window appWindow = null;

            if (control.Type == "pane")
            {

            }

            /*IEnumerable<string> enumerable = application.GetWindows().Select(w => w.Title);
            IEnumerable<string> list2 = application.GetWindows().Select(w => w.AutomationElement.Current.Name);
            */
            List<string> windowTitles2 = GetWindowsForProcess(process.Name);

            if (!window.Name.IsNullOrEmpty())
                appWindow = application.GetWindow(SearchCriteria.ByAutomationId(window.Name), InitializeOption.NoCache);
            else
            {
                for (int i = 0; i < 5; i++)
                {
                    List<string> windowTitles = GetWindowsForProcess(process.Name);
                    string windowName = window.Text;
                    string closestTitle = windowTitles[0];
                    decimal toleranceLevel = windowName.Length * 0.7m;

                    foreach (string windowTitle in windowTitles)
                    {
                        int num1 = LevenshteinDistance.GetToleranceLevel(windowTitle, windowName);
                        if (num1 < toleranceLevel)
                        {
                            toleranceLevel = num1;
                            closestTitle = windowTitle;
                        }
                    }

                    try
                    {
                        List<Window> windows = application.GetWindows();

                        appWindow = application.GetWindows().FirstOrDefault(w => w.AutomationElement.Current.Name.Equals(closestTitle));

                        if (appWindow == null)
                        {
                            List<IntPtr> handles = EnumerateProcessWindowHandles(wProcess.Id).ToList();

                            Dictionary<string, IntPtr> windowHandleDict = new Dictionary<string, IntPtr>();

                            StringBuilder builder = new StringBuilder(1024);

                            foreach (IntPtr myIntPtr in handles)
                            {
                                GetWindowText(myIntPtr, builder, 1024);

                                string windowTitle = builder.ToString();
                                windowHandleDict[windowTitle] = myIntPtr;
                            }

                            AutomationElement element = AutomationElement.FromHandle(windowHandleDict[closestTitle]);

                            appWindow = new Win32Window(element, WindowFactory.Desktop, InitializeOption.NoCache,
                                new NullWindowSession());
                        }

                        break;
                    }
                    catch (Exception ex)
                    {

                    }

                }
            }

            BringWindowToFront(appWindow.AutomationElement.Current.NativeWindowHandle);

            if (control == null || control.Type == "window" || control.Equals(window))
                return appWindow;

            Stack<MappedItem> mappedItemTree = new Stack<MappedItem>();
            MappedItem currentMappedItem = control;

            if (window == null)
            {

            }

            while (currentMappedItem != window)
            {
                mappedItemTree.Push(currentMappedItem);
                currentMappedItem = appManager.GetMappedItem(currentMappedItem.ParentId);
            }

            IUIItem currentControl = appWindow;
            AutomationElement elemn;

            while (mappedItemTree.Count > 0)
            {
                MappedItem currentMappedItemControl = mappedItemTree.Pop();

                if (!currentMappedItemControl.Name.IsNullOrEmpty())
                {
                    AutomationElement element = currentControl.AutomationElement.FindFirst(TreeScope.Descendants,
                        new PropertyCondition(AutomationElement.AutomationIdProperty, currentMappedItemControl.Name));

                    //AutomationElement element = currentControl.GetElement(SearchCriteria.ByAutomationId(currentMappedItemControl.Name));

                    currentControl = new UIItem(element, new NullActionListener());

                    continue;
                }

                if (!string.IsNullOrEmpty(currentMappedItemControl.Text))
                {
                    currentControl = new UIItem(currentControl.GetElement(SearchCriteria.ByText(currentMappedItemControl.Text)),
                        new NullActionListener());

                    continue;
                }

            }

            return currentControl;
        }
Пример #17
0
 public override string DefaultDescription(MappedItem control)
 {
     return string.Format("Run Test \"{0}\"", TestName);
 }
Пример #18
0
        public AppProcess GetProcess(MappedItem mappedItem)
        {
            if (mappedItem.Type == "process")
                return null;

            MappedItem parent = GetMappedItem(mappedItem.ParentId);

            while (parent != null)
            {
                if (parent.Type == "process")
                    return parent as AppProcess;

                parent = GetMappedItem(parent.ParentId);
            }

            return null;
        }
        public override bool Play(MappedItem control, Log log)
        {
            AppProcess process = AppManager.GetProcess(control);
            MappedItem window = AppManager.GetWindow(control);

            IUIItem uiItem = AppPlaybackService.GetControl(process, window, control, AppManager);
            Point clickPoint = new Point(X,Y);
            Point globalPoint = new Point((int)uiItem.Bounds.X + clickPoint.X, (int)uiItem.Bounds.Y + clickPoint.Y);

            Screenshot screenshot = CreateScreenshot(log);

            Cursor.LeftClick(globalPoint);
            string actualText = CopyText();
            string expectedText = textParam.GetValue();

            if (actualText == null)
                actualText = "";

            if (expectedText == null)
                expectedText = "";

            string originalExpectedText = expectedText;

            foreach (Variable v in this.TestItem.Test.Variables.OrderBy(v => v.Name.Length))
            {
                expectedText = expectedText.Replace(v.Name, v.Value.ToString());
            }

            Expression e = new Expression(expectedText);

            try
            {
                expectedText = e.Evaluate().ToString();
            }
            catch (Exception ex)
            {
                //e.Evaluate() errored out.  Probably not an expression

                expectedText = originalExpectedText;
            }

            if(!Equals(actualText, expectedText))
            {
                string error = "Expected \"{0}\" but value was \"{1}\"";
                error = string.Format(error, expectedText, actualText);

                log.CreateLogItem(LogItemCategory.Error, error, screenshot);
                return false;
            }

            string description = "Validated that the text at ({0},{1}) on {2} is equal to \"{3}\"";
            description = string.Format(description, X, Y, control.Name, Text);

            log.CreateLogItem(LogItemCategory.Validation, description, screenshot);

            return true;
        }
Пример #20
0
        public MappedItem GetWindow(MappedItem mappedItem)
        {
            MappedItem parent = GetMappedItem(mappedItem.ParentId);

            if (mappedItem.Type == "window" || (mappedItem.Type == "pane" && parent.Type == "process"))
                return mappedItem;

            MappedItem previousParent = null;
            while (parent != null)
            {
                if (parent.Type == "window" || (parent.Type == "pane" && GetMappedItem(parent.ParentId).Type == "process"))
                    return parent;
                previousParent = parent;
                parent = GetMappedItem(parent.ParentId);
            }

            return previousParent;
        }
 public override string DefaultDescription(MappedItem control)
 {
     return string.Format("Set variable {0} to value at point ({1},{2})", variableParam.Value, clickXParam.Value, clickYParam.Value);
 }
Пример #22
0
 public abstract bool Play(MappedItem control, Log log);
Пример #23
0
 public override string DefaultDescription(MappedItem control)
 {
     return "Creates a Log group named: " + nameParameter.Value;
 }
Пример #24
0
 public abstract string DefaultDescription(MappedItem control);
Пример #25
0
        private TestItem CreateOnScreenAction(MouseEventArgs mouseEventArgs, out IUIItem whiteControl, bool takeScreenshot = true)
        {
            TestItem action = new TestItem { Type = TestItemTypes.OnScreenAction };
            MappedItem mappedItem = null;

            whiteControl = CreateWhiteControl(mouseEventArgs.Location, ref mappedItem);
            currentMappedItem = mappedItem;
            action.ControlId = mappedItem.Id;

            if (ScreenshotsEnabled && takeScreenshot)
            {
                Screenshot screenshot = CreateNewScreenshot();
                action.Screenshot = screenshot;
            }

            return action;
        }
Пример #26
0
        private MappedItem FindMappedItem(MappedItem parentMappedItem, string id)
        {
            if (Equals(parentMappedItem.Id, id))
            {
                return parentMappedItem;
            }

            return parentMappedItem.Children
                .Select(mappedItem => FindMappedItem(mappedItem, id))
                .FirstOrDefault(findMappedItem => findMappedItem != null);
        }
Пример #27
0
        public override bool Play(MappedItem control, Log log)
        {
            log.CreateLogItem(LogItemCategory.Message, string.Format("Message: {0}", messageParameter.GetValue()));

            return true;
        }
Пример #28
0
 public override string DefaultDescription(MappedItem control)
 {
     return "Evaluates the boolean expression.";
 }
Пример #29
0
        public IUIItem CreateWhiteControl(Point point, ref MappedItem mappedItem)
        {
            try
            {
                UIItem uiItem = ExternalAppInfoManager.GetControl(point);

                //work with pane as window here???
                if (uiItem.AutomationElement.Current.LocalizedControlType.Equals("window")
                    || (uiItem.AutomationElement.Current.LocalizedControlType.Equals("pane")
                        && TreeWalker.ControlViewWalker.GetParent(uiItem.AutomationElement).Current.LocalizedControlType.Equals("process")))
                {
                    Process process1 = Process.GetProcessById(uiItem.AutomationElement.Current.ProcessId);

                    AppProcess appProcess1 = appManager.FindOrCreateProcess(process1.ProcessName);

                    string name = uiItem.AutomationElement.Current.AutomationId;

                    int num;
                    if (int.TryParse(name, out num))
                        name = "";

                    string type = uiItem.AutomationElement.Current.ControlType.LocalizedControlType;
                    string text = uiItem.AutomationElement.Current.Name;

                    if (type == "edit")
                        text = "";

                    Rect bounds = uiItem.AutomationElement.Current.BoundingRectangle;
                    bounds.X = 0;//;window.Current.BoundingRectangle.X;
                    bounds.Y = 0;//window.Current.BoundingRectangle.Y;
                    mappedItem = appManager.FindOrCreateMappedItem(appProcess1.Id, name, bounds, type, text);

                    if (uiItem.AutomationElement.Current.LocalizedControlType.Equals("pane"))
                    {

                    }

                    return uiItem;
                }

                TreeWalker walker = TreeWalker.ControlViewWalker;
                AutomationElement automationElement = uiItem.AutomationElement;
                Stack<AutomationElement> uiElementTree = new Stack<AutomationElement>();

                int delNum;

                while (automationElement != AutomationElement.RootElement)
                {
                    if (!((string.IsNullOrEmpty(automationElement.Current.Name)
                        && string.IsNullOrEmpty(automationElement.Current.AutomationId))
                        || int.TryParse(automationElement.Current.AutomationId, out delNum)))
                    {
                        uiElementTree.Push(automationElement);
                    }

                    automationElement = walker.GetParent(automationElement);
                }

                Process process = Process.GetProcessById(uiItem.AutomationElement.Current.ProcessId);

                AppProcess appProcess = appManager.FindOrCreateProcess(process.ProcessName);

                string parentId = appProcess.Id;

                AutomationElement window = uiElementTree.Peek();
                MappedItem createdMappedItem = null;

                while (uiElementTree.Count > 0)
                {
                    automationElement = uiElementTree.Pop();
                    string name = automationElement.Current.AutomationId;

                    int num;
                    if (int.TryParse(name, out num))
                        name = "";

                    string type = automationElement.Current.ControlType.LocalizedControlType;
                    string text = automationElement.Current.Name;

                    if (type == "edit")
                        text = "";

                    Rect bounds = automationElement.Current.BoundingRectangle;
                    bounds.X -= window.Current.BoundingRectangle.X;
                    bounds.Y -= window.Current.BoundingRectangle.Y;
                    createdMappedItem = appManager.FindOrCreateMappedItem(parentId, name, bounds, type, text);

                    parentId = createdMappedItem.Id;
                }

                mappedItem = createdMappedItem;

                return uiItem;
            }
            catch (Exception ex)
            {

                return null;
            }
        }
Пример #30
0
 public override string DefaultDescription(MappedItem control)
 {
     return string.Format("Set variable {0} to value {1}", variableParam.Value, valueParam.Value);
 }