示例#1
0
        void attributeForm_onAttributeSelected(string name, string value)
        {
            AgentResponse agentResponse = new AgentResponse();

            agentResponse.messageType = AgentResponse.MessageType.CAPTURE_STEP_REPONSE;

            RanorexStepCaptureReponse captureResponse = new RanorexStepCaptureReponse();

            agentResponse.stepCaptureReponse = captureResponse;
            captureResponse.action           = "Get Attribute";

            ElementInfo elementInfo = attributeForm.currentElement;

            captureResponse.target = elementInfo.Path.ToResolvedString();

            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add("name", name);

            captureResponse.properties = properties;

            RanorexStepExecutionResponse executionResponse = new RanorexStepExecutionResponse();

            executionResponse.success = true;
            executionResponse.message = value;

            agentResponse.stepExecutionResponse = executionResponse;

            agentServer.SendMessage(agentResponse);
        }
示例#2
0
        private void SendTerminate(string reason)
        {
            AgentResponse agentResponse = new AgentResponse();

            agentResponse.stepExecutionResponse = new RanorexStepExecutionResponse();
            agentResponse.messageType           = AgentResponse.MessageType.TERMINATION_RESPONSE;

            agentResponse.stepExecutionResponse.message = reason;
            agentServer.SendMessage(agentResponse);
        }
示例#3
0
        private void ProcessValidateItems(ElementInfo elementInfo, IList <ValidationRecordItem> recordedItems)
        {
            FlushRecording();

            AgentResponse agentResponse = new AgentResponse();

            agentResponse.messageType = AgentResponse.MessageType.CAPTURE_STEP_REPONSE;

            RanorexStepCaptureReponse    captureResponse   = new RanorexStepCaptureReponse();
            RanorexStepExecutionResponse executionResponse = new RanorexStepExecutionResponse();

            agentResponse.stepCaptureReponse = captureResponse;

            Dictionary <string, object> properties = new Dictionary <string, object>();

            Dictionary <string, string> attributes     = new Dictionary <string, string>();
            Dictionary <string, object> structuredData = new Dictionary <string, object>();

            foreach (ValidationRecordItem item in recordedItems)
            {
                if (item.Action == ValidationAction.NotExists || item.Action == ValidationAction.Exists)
                {
                    continue;
                }

                if (elementInfo == null)
                {
                    elementInfo = item.Info;
                }
                if (item.Action == ValidationAction.CompareImage || item.Action == ValidationAction.ContainsImage)
                {
                    ImageSearchProperties searchProps = item.ImageBasedLocation;
                    Rectangle             imgRect     = searchProps.ImageSelectionRectangle;
                    CompressedImage       image       = elementInfo.LiveElementOrSnapshot.CaptureCompressedImage();
                    properties.Add("image", image.ToBase64String());
                    properties.Add("imageAction", item.Action.ToString());
                    properties.Add("clipX", imgRect.X);
                    properties.Add("clipY", imgRect.Y);
                    properties.Add("clipWidth", imgRect.Width);
                    properties.Add("clipHeight", imgRect.Height);

                    structuredData.Add("imageValidated", true);
                }
                else
                {
                    executionResponse.message += item.MatchName + "=" + item.MatchValue + "\n";
                    attributes.Add(item.MatchName, item.MatchValue);
                }
            }

            properties.Add("attributes", attributes);
            structuredData.Add("attributes", attributes);
            captureResponse.action = "Get Attribute";

            string absolutePath = elementInfo.Path.ToResolvedString();

            if (absolutePath.StartsWith("/mobileapp"))
            {
                absolutePath = Regex.Replace(absolutePath, "/mobileapp\\[@devicename='[^\\/]*'\\]", "/mobileapp");
            }
            captureResponse.target = absolutePath;

            captureResponse.properties = properties;

            executionResponse.structuredData = structuredData;
            executionResponse.success        = true;

            agentResponse.stepExecutionResponse = executionResponse;


            agentServer.SendMessage(agentResponse);
        }
示例#4
0
        private void ProcessRecordItem(RecordItem recordItem)
        {
            if (recordingFlushed)
            {
                AgentResponse agentResponse = new AgentResponse();
                agentResponse.messageType = AgentResponse.MessageType.CAPTURE_STEP_REPONSE;

                RanorexStepCaptureReponse captureResponse = new RanorexStepCaptureReponse();
                agentResponse.stepCaptureReponse = captureResponse;

                Dictionary <string, object> properties = new Dictionary <string, object>();
                XmlNode parentNode = new XmlNode("recorditem");
                XmlNode recordNode = recordItem.CreateXmlNode(parentNode, false);

                properties.Add("attributes", recordNode.Attributes);

                captureResponse.action = recordItem.DisplayName;

                if (recordItem is ElementRecordItem)
                {
                    RepositoryEntry repoEntry = ((ElementRecordItem)recordItem).GetBoundRepositoryEntry();

                    if (repoEntry != null)
                    {
                        string absolutePath = repoEntry.AbsolutePath.ToResolvedString();
                        if (absolutePath.StartsWith("/mobileapp"))
                        {
                            absolutePath = Regex.Replace(absolutePath, "/mobileapp\\[@devicename='[^\\/]*'\\]", "/mobileapp");
                        }
                        captureResponse.target = absolutePath;
                    }
                }

                if (recordItem is MouseRecordItem)
                {
                    MouseRecordItem mouseItem = (MouseRecordItem)recordItem;
                    captureResponse.action = mouseItem.Action.ToString();
                    properties.Add("button", mouseItem.Button.ToString());
                    properties.Add("location", mouseItem.ElementLocation.FixedLocation.X + ";" + mouseItem.ElementLocation.FixedLocation.Y);
                    properties.Add("duration", 200);
                    captureResponse.properties = properties;
                    Console.WriteLine(mouseItem.Action.ToString());
                    Console.WriteLine((String)properties["location"]);
                    Console.WriteLine((String)captureResponse.target);
                    Debug.Print((String)mouseItem.Action.ToString());
                    Console.Write((String)mouseItem.Action.ToString());
                    agentServer.SendMessage(agentResponse);
                }
                else if (recordItem is KeyboardSequenceRecordItem)
                {
                    KeyboardSequenceRecordItem sequenceItem = (KeyboardSequenceRecordItem)recordItem;
                    properties.Add("sequence", sequenceItem.KeySequence);
                    properties.Add("pressTime", 0);
                    properties.Add("duration", 200);
                    captureResponse.properties = properties;
                    agentServer.SendMessage(agentResponse);
                }
                else if (recordItem is KeyboardRecordItem)
                {
                    KeyboardRecordItem keyboardItem = (KeyboardRecordItem)recordItem;
                    properties.Add("data", keyboardItem.KeyData.ToString());
                    properties.Add("scanCode", keyboardItem.ScanCode);
                    properties.Add("setModifiers", keyboardItem.SetModifiers);
                    properties.Add("pressTime", 0);
                    properties.Add("duration", 200);
                    captureResponse.properties = properties;
                    agentServer.SendMessage(agentResponse);
                }
                else if (recordItem is MouseWheelRecordItem)
                {
                    MouseWheelRecordItem wheelItem = (MouseWheelRecordItem)recordItem;
                    string orientation             = wheelItem.Orientation.ToString();
                    properties.Add("orientation", orientation);
                    properties.Add("delta", wheelItem.Delta);
                    properties.Add("duration", 200);
                    captureResponse.properties = properties;
                    agentServer.SendMessage(agentResponse);
                }
                else if (recordItem is SetValueRecordItem)
                {
                    SetValueRecordItem setValueItem = (SetValueRecordItem)recordItem;
                    properties.Add("name", setValueItem.AttributeName);
                    properties.Add("value", setValueItem.AttributeValue);
                    captureResponse.properties = properties;
                    agentServer.SendMessage(agentResponse);
                }
                else if (recordItem is ElementRecordItem)
                {
                    ElementRecordItem elementItem = (ElementRecordItem)recordItem;
                    captureResponse.properties = properties;
                    agentServer.SendMessage(agentResponse);
                }
            }
        }
示例#5
0
        void agentServer_OnCommand(Command command)
        {
            RanorexStepExecutionResponse stepResponse = null;

            if (command.command == "invoke")
            {
                if (!reportSetupDone)
                {
                    TestReport.Setup(Report.CurrentReportLevel, null, true, TestReport.EnableTracingScreenshots, 0, null);
                    reportSetupDone = true;
                }

                if (showExecutionUI)
                {
                    ProgressForm.Show();
                }
                else
                {
                    ProgressForm.Hide();
                }

                Dictionary <string, object> arguments = command.arguments;
                Hashtable props = (Hashtable)arguments["props"];

                if (sessionType == "Mobile")
                {
                    string target = (string)command.arguments["target"];
                    if (target.StartsWith("/mobileapp/"))
                    {
                        target.Replace("/mobileapp", "/mobileapp[@devicename'" + mobileDevice + "']");
                    }
                }

                foreach (DictionaryEntry entry in props)
                {
                    arguments.Add((string)entry.Key, entry.Value);
                }
                stepResponse = new RanorexHandlerFactory().GetHandler((string)command.arguments["itest-action"], repo).Execute(arguments);
                EXECUTION_INDEX++;
            }
            else if (command.command == "ping")
            {
                agentServer.Ping();
            }
            else if (command.command == "open")
            {
                try
                {
                    if ((bool)command.arguments["capture"] == true)
                    {
                        isInteractive = true;
                    }

                    OpenSession(command);

                    stepResponse         = new RanorexStepExecutionResponse();
                    stepResponse.success = true;
                }
                catch (Exception e)
                {
                    stepResponse         = new RanorexStepExecutionResponse();
                    stepResponse.success = false;
                    stepResponse.message = "Failed to open Ranorex session: " + e.Message;

                    agentServer.DropClient();
                }
            }
            else if (command.command == "close")
            {
                closeSession();
                agentServer.DropClient();
            }
            else if (command.command == "startcapture")
            {
            }
            else if (command.command == "stopcapture")
            {
                Thread startThread = new Thread(StopRecording);
                startThread.SetApartmentState(ApartmentState.STA);
                startThread.Start();
            }

            if (stepResponse != null)
            {
                AgentResponse agentResponse = new AgentResponse();
                agentResponse.messageType           = AgentResponse.MessageType.EXECUTION_STEP_RESPONSE;
                agentResponse.stepExecutionResponse = stepResponse;
                agentServer.SendMessage(agentResponse);
            }
        }