예제 #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 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);
        }
예제 #3
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);
            }
        }