public override void AddImage(VisualRecorder recorder, string url, double[] channelBound, bool isRef)
 {
     byte[] cap = recorder.ScreenCapture(channelBound, GetScreenshotImage(url));
     if (isRef)
     {
         imagesList.Clear();
     }
     imagesList.Add(cap);
 }
 public VisualAction(VisualRecorder recorder, bool stop, string type, int line, string script, long timeLine, string channelName, double[] channelBound, string imageType, PerformanceCounter cpu, PerformanceCounter ram, float netSent, float netReceived) : this()
 {
     this.Type         = type;
     this.Line         = line;
     this.Script       = script;
     this.TimeLine     = timeLine;
     this.ChannelName  = channelName;
     this.ChannelBound = new TestBound(channelBound);
     this.imagesList.Add(recorder.ScreenCapture(channelBound));
     this.ImageType = imageType;
     this.ImageRef  = 0;
     this.Stop      = stop;
 }
 public virtual void AddImage(VisualRecorder recorder, string url, double[] channelBound, bool isRef)
 {
 }
 public VisualActionSync(VisualRecorder recorder, bool stop, string type, int line, string script, long timeLine, string channelName, double[] channelBound, string imageType, PerformanceCounter cpu, PerformanceCounter ram, float netSent, float netReceived)
     : base(recorder, stop, type, line, script, timeLine, channelName, channelBound, imageType, cpu, ram, netSent, netReceived)
 {
 }
    public RecordExecution(int type, string[] commandsData, VisualRecorder recorder) : base()
    {
        RecordType recordType = (RecordType)type;

        if (recordType == RecordType.Stop)
        {
            recorder.Stop();
        }
        else if (recordType == RecordType.Download)
        {
            response.type         = 1;
            response.atsvFilePath = recorder.GetDownloadFile();
        }
        else if (recordType == RecordType.Summary)
        {
            if (bool.TryParse(commandsData[0], out bool passed) && int.TryParse(commandsData[1], out int actions))
            {
                if (!passed && commandsData.Length >= 8 && int.TryParse(commandsData[6], out int errorLine))
                {
                    recorder.Summary(passed, actions, commandsData[2], commandsData[3], commandsData[4], commandsData[5], errorLine, commandsData[7]);
                }
                else
                {
                    recorder.Summary(passed, actions, commandsData[2], commandsData[3], commandsData[4]);
                }
            }
        }
        else
        {
            if (commandsData.Length > 0)
            {
                if (recordType == RecordType.Screenshot)
                {
                    if (int.TryParse(commandsData[0], out int x) &&
                        int.TryParse(commandsData[1], out int y) &&
                        int.TryParse(commandsData[2], out int w) &&
                        int.TryParse(commandsData[3], out int h))
                    {
                        response.Image = recorder.ScreenCapture(x, y, w, h);
                    }
                }
                else if (recordType == RecordType.ScreenshotMobile)
                {
                    response.Image = VisualAction.GetScreenshot(commandsData[0]);
                }
                else if (recordType == RecordType.Start)
                {
                    string tempFolder = Path.GetTempPath() + "\\ats_recorder";
                    long   freeSpace  = 0;
                    try
                    {
                        DriveInfo drive = new DriveInfo(new FileInfo(tempFolder).Directory.Root.FullName);
                        freeSpace = drive.AvailableFreeSpace;
                    }
                    catch { }

                    if (freeSpace > 100000000)
                    {
                        try
                        {
                            if (Directory.Exists(tempFolder))
                            {
                                DirectoryInfo folder = new DirectoryInfo(tempFolder);
                                foreach (FileInfo file in folder.EnumerateFiles())
                                {
                                    file.Delete();
                                }
                            }
                            else
                            {
                                Directory.CreateDirectory(tempFolder);
                            }
                        }
                        catch { }

                        string id          = commandsData[0];
                        string fullName    = commandsData[1];
                        string description = commandsData[2];
                        string author      = commandsData[3];
                        string groups      = commandsData[4];
                        string prereq      = commandsData[5];

                        response.atsvFilePath = tempFolder + "\\" + fullName;

                        _ = int.TryParse(commandsData[6], out int videoQuality);

                        recorder.Start(tempFolder, id, fullName, description, author, groups, prereq, videoQuality, commandsData[7]);
                    }
                    else
                    {
                        response.ErrorCode    = -50;
                        response.ErrorMessage = "Not enough space available on disk : " + (freeSpace / 1024 / 1024) + " Mo";
                    }
                }
                else if (recordType == RecordType.Create)
                {
                    string actionType = commandsData[0];

                    _ = int.TryParse(commandsData[1], out int line);

                    string script = commandsData[2];

                    _ = long.TryParse(commandsData[3], out long timeLine);

                    string channelName = commandsData[4];

                    double[] channelDimmension = new double[] { 0, 0, 1, 1 };
                    _ = double.TryParse(commandsData[5], out channelDimmension[0]);
                    _ = double.TryParse(commandsData[6], out channelDimmension[1]);
                    _ = double.TryParse(commandsData[7], out channelDimmension[2]);
                    _ = double.TryParse(commandsData[8], out channelDimmension[3]);

                    _ = bool.TryParse(commandsData[9], out bool sync);
                    _ = bool.TryParse(commandsData[10], out bool stop);

                    recorder.Create(actionType, line, script, timeLine, channelName, channelDimmension, sync, stop);
                }
                else if (recordType == RecordType.CreateMobile)
                {
                    string actionType = commandsData[0];

                    _ = int.TryParse(commandsData[1], out int line);

                    string script = commandsData[2];

                    _ = long.TryParse(commandsData[6], out long timeLine);

                    string channelName = commandsData[4];

                    double[] channelDimmension = new double[] { 0, 0, 1, 1 };
                    _ = double.TryParse(commandsData[5], out channelDimmension[0]);
                    _ = double.TryParse(commandsData[6], out channelDimmension[1]);
                    _ = double.TryParse(commandsData[7], out channelDimmension[2]);
                    _ = double.TryParse(commandsData[8], out channelDimmension[3]);

                    string url = commandsData[9];

                    _ = bool.TryParse(commandsData[10], out bool sync);
                    _ = bool.TryParse(commandsData[11], out bool stop);

                    recorder.CreateMobile(actionType, line, script, timeLine, channelName, channelDimmension, url, sync, stop);
                }
                else if (recordType == RecordType.Image)
                {
                    double[] screenRect = new double[] { 0, 0, 1, 1 };
                    _ = double.TryParse(commandsData[0], out screenRect[0]);
                    _ = double.TryParse(commandsData[1], out screenRect[1]);
                    _ = double.TryParse(commandsData[2], out screenRect[2]);
                    _ = double.TryParse(commandsData[3], out screenRect[3]);

                    _ = bool.TryParse(commandsData[4], out bool isRef);

                    recorder.AddImage(screenRect, isRef);
                }
                else if (recordType == RecordType.ImageMobile)
                {
                    double[] screenRect = new double[] { 0, 0, 1, 1 };
                    _ = double.TryParse(commandsData[0], out screenRect[0]);
                    _ = double.TryParse(commandsData[1], out screenRect[1]);
                    _ = double.TryParse(commandsData[2], out screenRect[2]);
                    _ = double.TryParse(commandsData[3], out screenRect[3]);

                    _ = bool.TryParse(commandsData[4], out bool isRef);
                    recorder.AddImage(commandsData[5], screenRect, isRef);
                }
                else if (recordType == RecordType.Value)
                {
                    recorder.AddValue(commandsData[0]);
                }
                else if (recordType == RecordType.Data)
                {
                    recorder.AddData(commandsData[0], commandsData[1]);
                }
                else if (recordType == RecordType.Status)
                {
                    _ = int.TryParse(commandsData[0], out int error);
                    _ = long.TryParse(commandsData[1], out long duration);

                    recorder.Status(error, duration);
                }
                else if (recordType == RecordType.Element)
                {
                    double[] elementBound = new double[] { 0, 0, 0, 0 };
                    _ = double.TryParse(commandsData[0], out elementBound[0]);
                    _ = double.TryParse(commandsData[1], out elementBound[1]);
                    _ = double.TryParse(commandsData[2], out elementBound[2]);
                    _ = double.TryParse(commandsData[3], out elementBound[3]);

                    _ = long.TryParse(commandsData[4], out long searchDuration);

                    _ = int.TryParse(commandsData[5], out int numElements);

                    string searchCriterias = "";
                    if (commandsData.Length > 6)
                    {
                        searchCriterias = commandsData[6];
                    }

                    string   tag          = "*";
                    string[] citeriasData = searchCriterias.Split(',');
                    if (citeriasData.Length > 0)
                    {
                        tag = citeriasData[0];
                        if (citeriasData.Length == 1)
                        {
                            searchCriterias += "(no-criterias)";
                        }
                    }

                    recorder.AddElement(elementBound, searchDuration, numElements, searchCriterias, tag);
                }
                else if (recordType == RecordType.Position)
                {
                    recorder.AddPosition(commandsData[0], commandsData[1], commandsData[2], commandsData[3]);
                }
            }
        }
    }
Exemple #6
0
    public WindowExecution(WindowType type, string[] commandsData, ActionKeyboard keyboard, VisualRecorder recorder, DesktopManager desktop) : base()
    {
        DesktopWindow window = null;

        if (type == WindowType.Close || type == WindowType.Handle || type == WindowType.State || type == WindowType.Keys)
        {
            _      = int.TryParse(commandsData[0], out int handle);
            window = desktop.GetWindowByHandle(handle);
            if (window != null)
            {
                if (type == WindowType.State)
                {
                    executor = new StateExecutor(window, response, commandsData[1]);
                }
                else if (type == WindowType.Keys)
                {
                    executor = new KeysExecutor(window, response, keyboard, commandsData[1]);
                }
                else if (type == WindowType.Close)
                {
                    executor = new CloseExecutor(window, response);
                }
                else if (type == WindowType.Handle)
                {
                    executor = new HandleExecutor(window, response);
                }
            }
        }
        else if (type == WindowType.ToFront)
        {
            if (commandsData.Length > 1)
            {
                _ = int.TryParse(commandsData[0], out int handle);
                _ = int.TryParse(commandsData[1], out int pid);

                window = desktop.GetWindowByHandle(handle);

                if (window == null)
                {
                    window = desktop.GetWindowIndexByPid(pid, 0);
                }

                recorder.CurrentPid = pid;
            }
            else
            {
                _ = int.TryParse(commandsData[0], out int pid);
                recorder.CurrentPid = pid;

                List <DesktopWindow> windows = desktop.GetOrderedWindowsByPid(pid);
                if (windows.Count > 0)
                {
                    window = windows[0];
                }
            }

            if (window != null)
            {
                window.ToFront();
            }
        }
        else if (type == WindowType.Url)
        {
            _      = int.TryParse(commandsData[0], out int handle);
            window = desktop.GetWindowByHandle(handle);

            if (window.isIE)
            {
                window.ToFront();

                AutomationElement win        = window.Element;
                AutomationElement addressBar = win.FindFirst(TreeScope.Descendants, win.ConditionFactory.ByControlType(ControlType.Pane).And(win.ConditionFactory.ByClassName("Address Band Root")));
                if (addressBar != null)
                {
                    addressBar.Focus();
                    AutomationElement edit = addressBar.FindFirstChild(addressBar.ConditionFactory.ByControlType(ControlType.Edit));

                    if (edit != null)
                    {
                        try
                        {
                            edit.Focus();
                            edit.Click();
                            if (edit.Patterns.Value.IsSupported)
                            {
                                edit.Patterns.Value.Pattern.SetValue(commandsData[1]);
                            }
                            Keyboard.Type(VirtualKeyShort.ENTER);
                        }
                        catch { }
                    }
                }
            }
            else
            {
                string fname = Environment.ExpandEnvironmentVariables(commandsData[1]);
                if (fname.StartsWith("file:///"))
                {
                    fname = fname.Substring(8);
                }

                try
                {
                    if (Directory.Exists(@fname))
                    {
                        window.ToFront();
                        keyboard.AddressBar(Path.GetFullPath(@fname));
                    }
                    else
                    {
                        response.SetError(UNREACHABLE_GOTO_URL, "directory not found : " + fname);
                    }
                }
                catch (Exception e)
                {
                    response.SetError(UNREACHABLE_GOTO_URL, "directory path not valid : " + fname + " (" + e.Message + ")");
                }
            }
        }
        else if (type == WindowType.Title)
        {
            if (commandsData[0].Equals("jx"))
            {
                window = desktop.GetJxWindowPid(commandsData[1]);
            }
            else
            {
                window = desktop.GetWindowByTitle(commandsData[0]);
            }
        }
        else if (type == WindowType.List)
        {
            _        = int.TryParse(commandsData[0], out int pid);
            executor = new ListExecutor(window, response, desktop.GetOrderedWindowsByPid(pid).ToArray());
        }
        else if (type == WindowType.Switch)
        {
            if (commandsData.Length > 1)
            {
                _      = int.TryParse(commandsData[0], out int pid);
                _      = int.TryParse(commandsData[1], out int index);
                window = desktop.GetWindowIndexByPid(pid, index);

                if (window == null)
                {
                    _      = int.TryParse(commandsData[2], out int handle);
                    window = desktop.GetWindowByHandle(handle);
                }
            }
            else
            {
                _      = int.TryParse(commandsData[0], out int handle);
                window = desktop.GetWindowByHandle(handle);
            }

            if (window != null)
            {
                window.ToFront();
            }
        }
        else if (type == WindowType.Move || type == WindowType.Resize)
        {
            _ = int.TryParse(commandsData[0], out int handle);
            _ = int.TryParse(commandsData[1], out int value1);
            _ = int.TryParse(commandsData[2], out int value2);

            window = desktop.GetWindowByHandle(handle);
            if (window != null)
            {
                if (type == WindowType.Move)
                {
                    executor = new MoveExecutor(window, response, value1, value2);
                }
                else
                {
                    executor = new ResizeExecutor(window, response, value1, value2);
                }
            }
        }

        if (executor == null)
        {
            executor = new EmptyExecutor(window, response);
        }
    }
Exemple #7
0
 public VisualRecorder()
 {
     maxQualityEncoder                    = VisualRecorder.GetEncoder(ImageFormat.Png);
     maxQualityEncoderParameters          = new EncoderParameters(1);
     maxQualityEncoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 100L);
 }
Exemple #8
0
    public DesktopRequest(int cmdType, int cmdSubType, string[] cmdData, ActionKeyboard keyboard, VisualRecorder recorder, DesktopData[] capabilities, DesktopManager desktop, bool keyDown = false)
    {
        CommandType type = (CommandType)cmdType;

        if (type == CommandType.Driver)
        {
            execution = new DriverExecution(cmdSubType, cmdData, capabilities, desktop);
        }
        else if (type == CommandType.Mouse)
        {
            execution = new MouseExecution(cmdSubType, cmdData, desktop);
        }
        else if (type == CommandType.Keyboard)
        {
            execution = new KeyboardExecution(cmdSubType, cmdData, keyboard, keyDown);
        }
        else if (type == CommandType.Window)
        {
            execution = new WindowExecution((WindowType)cmdSubType, cmdData, keyboard, recorder, desktop);
        }
        else if (type == CommandType.Record)
        {
            execution = new RecordExecution(cmdSubType, cmdData, recorder);
        }
        else if (type == CommandType.Element)
        {
            execution = new ElementExecution(cmdSubType, cmdData, desktop);
        }
        else
        {
            execution = new AtsExecution(errorCode, true, errorMessage);
        }
    }