public override void RunCommand(object sender)
        {
            var lengthToWait = v_LengthToWait.ConvertToUserVariable(sender);
            var waitUntil    = int.Parse(lengthToWait);
            var endDateTime  = DateTime.Now.AddSeconds(waitUntil);

            IntPtr hWnd = IntPtr.Zero;

            while (DateTime.Now < endDateTime)
            {
                string windowName = v_WindowName.ConvertToUserVariable(sender);
                hWnd = User32Functions.FindWindow(windowName);

                if (hWnd != IntPtr.Zero) //If found
                {
                    break;
                }

                System.Threading.Thread.Sleep(1000);
            }

            if (hWnd == IntPtr.Zero)
            {
                throw new Exception("Window was not found in the allowed time!");
            }
        }
        public override void RunCommand(object sender)
        {
            var    engine     = (AutomationEngineInstance)sender;
            string windowName = v_WindowName.ConvertUserVariableToString(engine);
            var    timeout    = int.Parse(v_Timeout.ConvertUserVariableToString(engine));

            var endDateTime = DateTime.Now.AddSeconds(timeout);

            IntPtr hWnd = IntPtr.Zero;

            while (DateTime.Now < endDateTime)
            {
                hWnd = User32Functions.FindWindow(windowName);

                if (hWnd != IntPtr.Zero)                 //If found
                {
                    break;
                }

                Thread.Sleep(1000);
            }

            if (hWnd == IntPtr.Zero)
            {
                throw new Exception("Window was not found in the allowed time!");
            }
        }
Exemple #3
0
        private void pbRecord_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;


            this.searchParameters = new DataTable();
            this.searchParameters.Columns.Add("Enabled");
            this.searchParameters.Columns.Add("Parameter Name");
            this.searchParameters.Columns.Add("Parameter Value");
            this.searchParameters.TableName = DateTime.Now.ToString("UIASearchParamTable" + DateTime.Now.ToString("MMddyy.hhmmss"));


            //clear all
            searchParameters.Rows.Clear();

            //get window name and find window
            string windowName = cboWindowTitle.Text;
            IntPtr hWnd       = User32Functions.FindWindow(windowName);

            //check if window is found
            if (hWnd != IntPtr.Zero)
            {
                //set window state and move to 0,0
                User32Functions.SetWindowState(hWnd, User32Functions.WindowState.SW_SHOWNORMAL);
                User32Functions.SetForegroundWindow(hWnd);
                User32Functions.SetWindowPosition(hWnd, 0, 0);

                //start global hook and wait for left mouse down event
                User32Functions.GlobalHook.StartElementCaptureHook();
                User32Functions.GlobalHook.MouseEvent += GlobalHook_MouseEvent;
            }
        }
Exemple #4
0
        public async override Task RunCommand(object sender)
        {
            var    engine     = (IAutomationEngineInstance)sender;
            string windowName = (string)await v_WindowName.EvaluateCode(engine);

            var timeout = (int)await v_Timeout.EvaluateCode(engine);

            var    timeToEnd = DateTime.Now.AddSeconds(timeout);
            IntPtr hWnd      = IntPtr.Zero;

            while (DateTime.Now < timeToEnd)
            {
                if (engine.IsCancellationPending)
                {
                    break;
                }
                hWnd = User32Functions.FindWindow(windowName);

                if (hWnd != IntPtr.Zero)                 //If found
                {
                    break;
                }
                engine.ReportProgress($"Window '{windowName}' Not Yet Found... {(timeToEnd - DateTime.Now).Minutes}m, {(timeToEnd - DateTime.Now).Seconds}s remain");
                Thread.Sleep(1000);
            }

            if (hWnd == IntPtr.Zero)
            {
                throw new Exception($"Window '{windowName}' was not found in the allowed time!");
            }
        }
        public override void RunCommand(object sender)
        {
            var    engine     = (IAutomationEngineInstance)sender;
            string windowName = v_WindowName.ConvertUserVariableToString(engine);
            var    timeout    = int.Parse(v_Timeout.ConvertUserVariableToString(engine));

            var endDateTime = DateTime.Now.AddSeconds(timeout);

            IntPtr hWnd = IntPtr.Zero;

            while (DateTime.Now < endDateTime)
            {
                if (engine.IsCancellationPending)
                {
                    break;
                }
                hWnd = User32Functions.FindWindow(windowName);

                if (hWnd != IntPtr.Zero)                 //If found
                {
                    break;
                }
                engine.ReportProgress($"Window '{windowName}' Not Yet Found... " + (endDateTime - DateTime.Now).Minutes + "m, " + (endDateTime - DateTime.Now).Seconds + "s remain");
                Thread.Sleep(1000);
            }

            if (hWnd == IntPtr.Zero)
            {
                throw new Exception($"Window '{windowName}' was not found in the allowed time!");
            }
        }
        private void pbRecord_Click(object sender, EventArgs e)
        {
            // this.WindowState = FormWindowState.Minimized;

            if (!chkStopOnClick.Checked)
            {
                lblDescription.Text = $"Recording.  Press F2 to stop recording!";
                MoveFormToBottomRight(this);
                this.TopMost = true;
            }
            else
            {
                this.WindowState = FormWindowState.Minimized;
            }

            this.Size = new Size(540, 156);


            this.searchParameters = new DataTable();
            this.searchParameters.Columns.Add("Enabled");
            this.searchParameters.Columns.Add("Parameter Name");
            this.searchParameters.Columns.Add("Parameter Value");
            this.searchParameters.TableName = DateTime.Now.ToString("UIASearchParamTable" + DateTime.Now.ToString("MMddyy.hhmmss"));


            //clear all
            searchParameters.Rows.Clear();

            //get window name and find window
            string windowName = cboWindowTitle.Text;
            IntPtr hWnd       = User32Functions.FindWindow(windowName);

            //check if window is found
            if (hWnd != IntPtr.Zero)
            {
                //set window state and move to 0,0
                User32Functions.SetWindowState(hWnd, User32Functions.WindowState.SW_SHOWNORMAL);
                User32Functions.SetForegroundWindow(hWnd);
                User32Functions.SetWindowPosition(hWnd, 0, 0);

                //start global hook and wait for left mouse down event
                User32Functions.GlobalHook.StartEngineCancellationHook(Keys.F2);
                User32Functions.GlobalHook.HookStopped += GlobalHook_HookStopped;
                User32Functions.GlobalHook.StartElementCaptureHook(chkStopOnClick.Checked);
                User32Functions.GlobalHook.MouseEvent += GlobalHook_MouseEvent;
            }
        }
        private void pbRecord_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;

            //clear all
            searchParameters.Rows.Clear();

            //get window name and find window
            string windowName = cboWindowTitle.Text;
            IntPtr hWnd       = User32Functions.FindWindow(windowName);

            //check if window is found
            if (hWnd != IntPtr.Zero)
            {
                //set window state and move to 0,0
                User32Functions.SetWindowState(hWnd, User32Functions.WindowState.SW_SHOWNORMAL);
                User32Functions.SetForegroundWindow(hWnd);
                User32Functions.SetWindowPosition(hWnd, 0, 0);

                //start global hook and wait for left mouse down event
                User32Functions.GlobalHook.StartElementCaptureHook();
                User32Functions.GlobalHook.MouseEvent += GlobalHook_MouseEvent;
            }
        }
Exemple #8
0
        private void pbRecord_Click(object sender, EventArgs e)
        {
            // this.WindowState = FormWindowState.Minimized;
            if (!_isRecording)
            {
                _isRecording = true;

                SearchParameters = NewSearchParameterDataTable();

                //clear all
                SearchParameters.Rows.Clear();

                //get window name and find window
                WindowName = cboWindowTitle.Text;
                IntPtr hWnd = User32Functions.FindWindow(WindowName);

                if (IsRecordingSequence && _isFirstRecordClick)
                {
                    _isFirstRecordClick  = false;
                    _sequenceCommandList = new List <ScriptCommand>();

                    frmThickAppElementRecorderSettings settingsForm = new frmThickAppElementRecorderSettings();
                    settingsForm.ShowDialog();

                    if (settingsForm.DialogResult == DialogResult.OK)
                    {
                        _parameterSettings = settingsForm.ParameterSettingsDT;
                        settingsForm.Dispose();
                    }
                    else
                    {
                        _isRecording        = false;
                        _isFirstRecordClick = true;

                        lblDescription.Text = "Instructions: Select the target window name from the drop-down " +
                                              "list and click the record button. Once recording has started, click " +
                                              "the element in the target application that you want to capture.";

                        //remove wait for left mouse down event
                        GlobalHook.MouseEvent   -= GlobalHook_MouseEvent;
                        GlobalHook.KeyDownEvent -= GlobalHook_KeyDownEvent;
                        GlobalHook.HookStopped  -= GlobalHook_HookStopped;

                        settingsForm.Dispose();
                        return;
                    }

                    dynamic activateWindowCommand = TypeMethods.CreateTypeInstance(_container, "ActivateWindowCommand");
                    activateWindowCommand.v_WindowName = WindowName;
                    _sequenceCommandList.Add(activateWindowCommand);
                }

                //check if window is found
                if (hWnd != IntPtr.Zero)
                {
                    //set window state and move to 0,0
                    User32Functions.ActivateWindow(WindowName);
                    User32Functions.SetWindowPosition(hWnd, 0, 0);

                    //start global hook and wait for left mouse down event
                    GlobalHook.StartEngineCancellationHook(Keys.F2);
                    GlobalHook.HookStopped += GlobalHook_HookStopped;
                    GlobalHook.StartElementCaptureHook(chkStopOnClick.Checked, _container);
                    GlobalHook.MouseEvent   += GlobalHook_MouseEvent;
                    GlobalHook.KeyDownEvent += GlobalHook_KeyDownEvent;
                }

                if (!chkStopOnClick.Checked)
                {
                    lblDescription.Text = _recordingMessage;
                    MoveFormToBottomRight(this);
                }
                else
                {
                    WindowState = FormWindowState.Minimized;
                }
            }
            else
            {
                _isRecording = false;
                if (!chkStopOnClick.Checked)
                {
                    lblDescription.Text = "Recording has stopped. Press F2 to save and close.";
                }
            }
        }
        public bool DetermineStatementTruth(object sender)
        {
            var engine = (AutomationEngineInstance)sender;

            bool ifResult = false;

            if (v_IfActionType == "Value Compare")
            {
                string value1 = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value1"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string operand = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                   where rw.Field <string>("Parameter Name") == "Operand"
                                   select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string value2 = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value2"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());

                value1 = value1.ConvertUserVariableToString(engine);
                value2 = value2.ConvertUserVariableToString(engine);

                decimal cdecValue1, cdecValue2;

                switch (operand)
                {
                case "is equal to":
                    ifResult = (value1 == value2);
                    break;

                case "is not equal to":
                    ifResult = (value1 != value2);
                    break;

                case "is greater than":
                    cdecValue1 = Convert.ToDecimal(value1);
                    cdecValue2 = Convert.ToDecimal(value2);
                    ifResult   = (cdecValue1 > cdecValue2);
                    break;

                case "is greater than or equal to":
                    cdecValue1 = Convert.ToDecimal(value1);
                    cdecValue2 = Convert.ToDecimal(value2);
                    ifResult   = (cdecValue1 >= cdecValue2);
                    break;

                case "is less than":
                    cdecValue1 = Convert.ToDecimal(value1);
                    cdecValue2 = Convert.ToDecimal(value2);
                    ifResult   = (cdecValue1 < cdecValue2);
                    break;

                case "is less than or equal to":
                    cdecValue1 = Convert.ToDecimal(value1);
                    cdecValue2 = Convert.ToDecimal(value2);
                    ifResult   = (cdecValue1 <= cdecValue2);
                    break;
                }
            }
            else if (v_IfActionType == "Date Compare")
            {
                string value1 = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value1"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string operand = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                   where rw.Field <string>("Parameter Name") == "Operand"
                                   select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string value2 = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value2"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());

                value1 = value1.ConvertUserVariableToString(engine);
                value2 = value2.ConvertUserVariableToString(engine);

                DateTime dt1, dt2;
                dt1 = DateTime.Parse(value1);
                dt2 = DateTime.Parse(value2);
                switch (operand)
                {
                case "is equal to":
                    ifResult = (dt1 == dt2);
                    break;

                case "is not equal to":
                    ifResult = (dt1 != dt2);
                    break;

                case "is greater than":
                    ifResult = (dt1 > dt2);
                    break;

                case "is greater than or equal to":
                    ifResult = (dt1 >= dt2);
                    break;

                case "is less than":
                    ifResult = (dt1 < dt2);
                    break;

                case "is less than or equal to":
                    ifResult = (dt1 <= dt2);
                    break;
                }
            }
            else if (v_IfActionType == "Variable Compare")
            {
                string value1 = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value1"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string operand = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                   where rw.Field <string>("Parameter Name") == "Operand"
                                   select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string value2 = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value2"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string caseSensitive = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                         where rw.Field <string>("Parameter Name") == "Case Sensitive"
                                         select rw.Field <string>("Parameter Value")).FirstOrDefault());

                value1 = value1.ConvertUserVariableToString(engine);
                value2 = value2.ConvertUserVariableToString(engine);

                if (caseSensitive == "No")
                {
                    value1 = value1.ToUpper();
                    value2 = value2.ToUpper();
                }

                switch (operand)
                {
                case "contains":
                    ifResult = (value1.Contains(value2));
                    break;

                case "does not contain":
                    ifResult = (!value1.Contains(value2));
                    break;

                case "is equal to":
                    ifResult = (value1 == value2);
                    break;

                case "is not equal to":
                    ifResult = (value1 != value2);
                    break;
                }
            }
            else if (v_IfActionType == "Variable Has Value")
            {
                string variableName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Variable Name"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault());

                var actualVariable = variableName.ConvertUserVariableToString(engine).Trim();

                if (!string.IsNullOrEmpty(actualVariable))
                {
                    ifResult = true;
                }
                else
                {
                    ifResult = false;
                }
            }
            else if (v_IfActionType == "Variable Is Numeric")
            {
                string variableName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Variable Name"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault());

                var actualVariable = variableName.ConvertUserVariableToString(engine).Trim();

                var numericTest = decimal.TryParse(actualVariable, out decimal parsedResult);

                if (numericTest)
                {
                    ifResult = true;
                }
                else
                {
                    ifResult = false;
                }
            }
            else if (v_IfActionType == "Error Occured")
            {
                //get line number
                string userLineNumber = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                          where rw.Field <string>("Parameter Name") == "Line Number"
                                          select rw.Field <string>("Parameter Value")).FirstOrDefault());

                //convert to variable
                string variableLineNumber = userLineNumber.ConvertUserVariableToString(engine);

                //convert to int
                int lineNumber = int.Parse(variableLineNumber);

                //determine if error happened
                if (engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).Count() > 0)
                {
                    var error = engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).FirstOrDefault();
                    error.ErrorMessage.StoreInUserVariable(engine, "Error.Message");
                    error.LineNumber.ToString().StoreInUserVariable(engine, "Error.Line");
                    error.StackTrace.StoreInUserVariable(engine, "Error.StackTrace");

                    ifResult = true;
                }
                else
                {
                    ifResult = false;
                }
            }
            else if (v_IfActionType == "Error Did Not Occur")
            {
                //get line number
                string userLineNumber = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                          where rw.Field <string>("Parameter Name") == "Line Number"
                                          select rw.Field <string>("Parameter Value")).FirstOrDefault());

                //convert to variable
                string variableLineNumber = userLineNumber.ConvertUserVariableToString(engine);

                //convert to int
                int lineNumber = int.Parse(variableLineNumber);

                //determine if error happened
                if (engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).Count() == 0)
                {
                    ifResult = true;
                }
                else
                {
                    var error = engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).FirstOrDefault();
                    error.ErrorMessage.StoreInUserVariable(engine, "Error.Message");
                    error.LineNumber.ToString().StoreInUserVariable(engine, "Error.Line");
                    error.StackTrace.StoreInUserVariable(engine, "Error.StackTrace");

                    ifResult = false;
                }
            }
            else if (v_IfActionType == "Window Name Exists")
            {
                //get user supplied name
                string windowName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                      where rw.Field <string>("Parameter Name") == "Window Name"
                                      select rw.Field <string>("Parameter Value")).FirstOrDefault());
                //variable translation
                string variablizedWindowName = windowName.ConvertUserVariableToString(engine);

                //search for window
                IntPtr windowPtr = User32Functions.FindWindow(variablizedWindowName);

                //conditional
                if (windowPtr != IntPtr.Zero)
                {
                    ifResult = true;
                }
            }
            else if (v_IfActionType == "Active Window Name Is")
            {
                string windowName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                      where rw.Field <string>("Parameter Name") == "Window Name"
                                      select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string variablizedWindowName = windowName.ConvertUserVariableToString(engine);

                var currentWindowTitle = User32Functions.GetActiveWindowTitle();

                if (currentWindowTitle == variablizedWindowName)
                {
                    ifResult = true;
                }
            }
            else if (v_IfActionType == "File Exists")
            {
                string fileName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                    where rw.Field <string>("Parameter Name") == "File Path"
                                    select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string trueWhenFileExists = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                              where rw.Field <string>("Parameter Name") == "True When"
                                              select rw.Field <string>("Parameter Value")).FirstOrDefault());

                var userFileSelected = fileName.ConvertUserVariableToString(engine);

                bool existCheck = false;
                if (trueWhenFileExists == "It Does Exist")
                {
                    existCheck = true;
                }

                if (File.Exists(userFileSelected) == existCheck)
                {
                    ifResult = true;
                }
            }
            else if (v_IfActionType == "Folder Exists")
            {
                string folderName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                      where rw.Field <string>("Parameter Name") == "Folder Path"
                                      select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string trueWhenFileExists = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                              where rw.Field <string>("Parameter Name") == "True When"
                                              select rw.Field <string>("Parameter Value")).FirstOrDefault());

                var userFolderSelected = folderName.ConvertUserVariableToString(engine);

                bool existCheck = false;
                if (trueWhenFileExists == "It Does Exist")
                {
                    existCheck = true;
                }

                if (Directory.Exists(folderName) == existCheck)
                {
                    ifResult = true;
                }
            }
            else if (v_IfActionType == "Web Element Exists")
            {
                string instanceName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Selenium Instance Name"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string parameterName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                         where rw.Field <string>("Parameter Name") == "Element Search Parameter"
                                         select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string searchMethod = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Element Search Method"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string trueWhenElementExists = (from rw in v_IfActionParameterTable.AsEnumerable()
                                                where rw.Field <string>("Parameter Name") == "True When"
                                                select rw.Field <string>("Parameter Value")).FirstOrDefault();


                SeleniumElementActionCommand newElementActionCommand = new SeleniumElementActionCommand();
                newElementActionCommand.v_SeleniumSearchType = searchMethod;
                newElementActionCommand.v_InstanceName       = instanceName.ConvertUserVariableToString(engine);
                bool elementExists = newElementActionCommand.ElementExists(sender, searchMethod, parameterName);
                ifResult = elementExists;

                if (trueWhenElementExists == "It Does Not Exist")
                {
                    ifResult = !ifResult;
                }
            }
            else if (v_IfActionType == "GUI Element Exists")
            {
                string windowName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                      where rw.Field <string>("Parameter Name") == "Window Name"
                                      select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));

                string elementSearchParam = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                              where rw.Field <string>("Parameter Name") == "Element Search Parameter"
                                              select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));

                string elementSearchMethod = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                               where rw.Field <string>("Parameter Name") == "Element Search Method"
                                               select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));

                string trueWhenElementExists = (from rw in v_IfActionParameterTable.AsEnumerable()
                                                where rw.Field <string>("Parameter Name") == "True When"
                                                select rw.Field <string>("Parameter Value")).FirstOrDefault();

                UIAutomationCommand newUIACommand = new UIAutomationCommand();
                newUIACommand.v_WindowName = windowName;
                newUIACommand.v_UIASearchParameters.Rows.Add(true, elementSearchMethod, elementSearchParam);
                var handle = newUIACommand.SearchForGUIElement(sender, windowName);

                if (handle is null)
                {
                    ifResult = false;
                }
                else
                {
                    ifResult = true;
                }

                if (trueWhenElementExists == "It Does Not Exist")
                {
                    ifResult = !ifResult;
                }
            }
            else if (v_IfActionType == "Image Element Exists")
            {
                string imageName = (from rw in v_IfActionParameterTable.AsEnumerable()
                                    where rw.Field <string>("Parameter Name") == "Captured Image"
                                    select rw.Field <string>("Parameter Value")).FirstOrDefault();
                double accuracy;
                try
                {
                    accuracy = double.Parse((from rw in v_IfActionParameterTable.AsEnumerable()
                                             where rw.Field <string>("Parameter Name") == "Accuracy (0-1)"
                                             select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));
                    if (accuracy > 1 || accuracy < 0)
                    {
                        throw new ArgumentOutOfRangeException("Accuracy value is out of range (0-1)");
                    }
                }
                catch (Exception)
                {
                    throw new InvalidDataException("Accuracy value is invalid");
                }

                string trueWhenImageExists = (from rw in v_IfActionParameterTable.AsEnumerable()
                                              where rw.Field <string>("Parameter Name") == "True When"
                                              select rw.Field <string>("Parameter Value")).FirstOrDefault();

                var imageVariable = imageName.ConvertUserVariableToObject(engine);

                Bitmap capturedImage;
                if (imageVariable != null && imageVariable is Bitmap)
                {
                    capturedImage = (Bitmap)imageVariable;
                }
                else
                {
                    throw new ArgumentException("Provided Argument is not a 'Bitmap' Image");
                }

                SurfaceAutomationCommand surfaceACommand = new SurfaceAutomationCommand();
                var element = surfaceACommand.FindImageElement(capturedImage, accuracy);
                CommandControls.ShowAllForms();

                if (element != null)
                {
                    ifResult = true;
                }
                else
                {
                    ifResult = false;
                }

                if (trueWhenImageExists == "It Does Not Exist")
                {
                    ifResult = !ifResult;
                }
            }
            else
            {
                throw new Exception("If type not recognized!");
            }

            return(ifResult);
        }
        public override void RunCommand(object sender, Core.Script.ScriptAction parentCommand)
        {
            var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;



            bool ifResult = false;


            if (v_IfActionType == "Value")
            {
                string value1 = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value1"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string operand = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                   where rw.Field <string>("Parameter Name") == "Operand"
                                   select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string value2 = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value2"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());

                value1 = value1.ConvertToUserVariable(sender);
                value2 = value2.ConvertToUserVariable(sender);



                decimal cdecValue1, cdecValue2;

                switch (operand)
                {
                case "is equal to":
                    ifResult = (value1 == value2);
                    break;

                case "is not equal to":
                    ifResult = (value1 != value2);
                    break;

                case "is greater than":
                    cdecValue1 = Convert.ToDecimal(value1);
                    cdecValue2 = Convert.ToDecimal(value2);
                    ifResult   = (cdecValue1 > cdecValue2);
                    break;

                case "is greater than or equal to":
                    cdecValue1 = Convert.ToDecimal(value1);
                    cdecValue2 = Convert.ToDecimal(value2);
                    ifResult   = (cdecValue1 >= cdecValue2);
                    break;

                case "is less than":
                    cdecValue1 = Convert.ToDecimal(value1);
                    cdecValue2 = Convert.ToDecimal(value2);
                    ifResult   = (cdecValue1 < cdecValue2);
                    break;

                case "is less than or equal to":
                    cdecValue1 = Convert.ToDecimal(value1);
                    cdecValue2 = Convert.ToDecimal(value2);
                    ifResult   = (cdecValue1 <= cdecValue2);
                    break;
                }
            }
            else if (v_IfActionType == "Date Compare")
            {
                string value1 = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value1"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string operand = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                   where rw.Field <string>("Parameter Name") == "Operand"
                                   select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string value2 = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value2"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());

                value1 = value1.ConvertToUserVariable(sender);
                value2 = value2.ConvertToUserVariable(sender);



                DateTime dt1, dt2;
                dt1 = DateTime.Parse(value1);
                dt2 = DateTime.Parse(value2);
                switch (operand)
                {
                case "is equal to":
                    ifResult = (dt1 == dt2);
                    break;

                case "is not equal to":
                    ifResult = (dt1 != dt2);
                    break;

                case "is greater than":
                    ifResult = (dt1 > dt2);
                    break;

                case "is greater than or equal to":
                    ifResult = (dt1 >= dt2);
                    break;

                case "is less than":
                    ifResult = (dt1 < dt2);
                    break;

                case "is less than or equal to":
                    ifResult = (dt1 <= dt2);
                    break;
                }
            }
            else if (v_IfActionType == "Variable Compare")
            {
                string value1 = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value1"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string operand = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                   where rw.Field <string>("Parameter Name") == "Operand"
                                   select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string value2 = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value2"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string caseSensitive = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                         where rw.Field <string>("Parameter Name") == "Case Sensitive"
                                         select rw.Field <string>("Parameter Value")).FirstOrDefault());

                value1 = value1.ConvertToUserVariable(sender);
                value2 = value2.ConvertToUserVariable(sender);

                if (caseSensitive == "No")
                {
                    value1 = value1.ToUpper();
                    value2 = value2.ToUpper();
                }



                switch (operand)
                {
                case "contains":
                    ifResult = (value1.Contains(value2));
                    break;

                case "does not contain":
                    ifResult = (!value1.Contains(value2));
                    break;

                case "is equal to":
                    ifResult = (value1 == value2);
                    break;

                case "is not equal to":
                    ifResult = (value1 != value2);
                    break;
                }
            }
            else if (v_IfActionType == "Variable Has Value")
            {
                string variableName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Variable Name"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault());

                var actualVariable = variableName.ConvertToUserVariable(sender).Trim();

                if (!string.IsNullOrEmpty(actualVariable))
                {
                    ifResult = true;
                }
                else
                {
                    ifResult = false;
                }
            }
            else if (v_IfActionType == "Variable Is Numeric")
            {
                string variableName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Variable Name"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault());

                var actualVariable = variableName.ConvertToUserVariable(sender).Trim();

                var numericTest = decimal.TryParse(actualVariable, out decimal parsedResult);

                if (numericTest)
                {
                    ifResult = true;
                }
                else
                {
                    ifResult = false;
                }
            }
            else if (v_IfActionType == "Error Occured")
            {
                //get line number
                string userLineNumber = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                          where rw.Field <string>("Parameter Name") == "Line Number"
                                          select rw.Field <string>("Parameter Value")).FirstOrDefault());

                //convert to variable
                string variableLineNumber = userLineNumber.ConvertToUserVariable(sender);

                //convert to int
                int lineNumber = int.Parse(variableLineNumber);

                //determine if error happened
                if (engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).Count() > 0)
                {
                    var error = engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).FirstOrDefault();
                    error.ErrorMessage.StoreInUserVariable(sender, "Error.Message");
                    error.LineNumber.ToString().StoreInUserVariable(sender, "Error.Line");
                    error.StackTrace.StoreInUserVariable(sender, "Error.StackTrace");

                    ifResult = true;
                }
                else
                {
                    ifResult = false;
                }
            }
            else if (v_IfActionType == "Error Did Not Occur")
            {
                //get line number
                string userLineNumber = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                          where rw.Field <string>("Parameter Name") == "Line Number"
                                          select rw.Field <string>("Parameter Value")).FirstOrDefault());

                //convert to variable
                string variableLineNumber = userLineNumber.ConvertToUserVariable(sender);

                //convert to int
                int lineNumber = int.Parse(variableLineNumber);

                //determine if error happened
                if (engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).Count() == 0)
                {
                    ifResult = true;
                }
                else
                {
                    var error = engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).FirstOrDefault();
                    error.ErrorMessage.StoreInUserVariable(sender, "Error.Message");
                    error.LineNumber.ToString().StoreInUserVariable(sender, "Error.Line");
                    error.StackTrace.StoreInUserVariable(sender, "Error.StackTrace");

                    ifResult = false;
                }
            }
            else if (v_IfActionType == "Window Name Exists")
            {
                //get user supplied name
                string windowName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                      where rw.Field <string>("Parameter Name") == "Window Name"
                                      select rw.Field <string>("Parameter Value")).FirstOrDefault());
                //variable translation
                string variablizedWindowName = windowName.ConvertToUserVariable(sender);

                //search for window
                IntPtr windowPtr = User32Functions.FindWindow(variablizedWindowName);

                //conditional
                if (windowPtr != IntPtr.Zero)
                {
                    ifResult = true;
                }
            }
            else if (v_IfActionType == "Active Window Name Is")
            {
                string windowName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                      where rw.Field <string>("Parameter Name") == "Window Name"
                                      select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string variablizedWindowName = windowName.ConvertToUserVariable(sender);

                var currentWindowTitle = User32Functions.GetActiveWindowTitle();

                if (currentWindowTitle == variablizedWindowName)
                {
                    ifResult = true;
                }
            }
            else if (v_IfActionType == "File Exists")
            {
                string fileName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                    where rw.Field <string>("Parameter Name") == "File Path"
                                    select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string trueWhenFileExists = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                              where rw.Field <string>("Parameter Name") == "True When"
                                              select rw.Field <string>("Parameter Value")).FirstOrDefault());

                var userFileSelected = fileName.ConvertToUserVariable(sender);

                bool existCheck = false;
                if (trueWhenFileExists == "It Does Exist")
                {
                    existCheck = true;
                }


                if (System.IO.File.Exists(userFileSelected) == existCheck)
                {
                    ifResult = true;
                }
            }
            else if (v_IfActionType == "Folder Exists")
            {
                string folderName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                      where rw.Field <string>("Parameter Name") == "Folder Path"
                                      select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string trueWhenFileExists = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                              where rw.Field <string>("Parameter Name") == "True When"
                                              select rw.Field <string>("Parameter Value")).FirstOrDefault());

                var userFolderSelected = folderName.ConvertToUserVariable(sender);

                bool existCheck = false;
                if (trueWhenFileExists == "It Does Exist")
                {
                    existCheck = true;
                }


                if (System.IO.Directory.Exists(folderName) == existCheck)
                {
                    ifResult = true;
                }
            }
            else if (v_IfActionType == "Web Element Exists")
            {
                string parameterName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                         where rw.Field <string>("Parameter Name") == "Element Search Parameter"
                                         select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string searchMethod = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Element Search Method"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault());

                SeleniumBrowserElementActionCommand_cn newElementActionCommand = new SeleniumBrowserElementActionCommand_cn();
                newElementActionCommand.v_SeleniumSearchType = searchMethod;
                bool elementExists = newElementActionCommand.ElementExists(sender, searchMethod, parameterName);
                ifResult = elementExists;
            }
            else if (v_IfActionType == "GUI Element Exists")
            {
                string windowName = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                      where rw.Field <string>("Parameter Name") == "Window Name"
                                      select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertToUserVariable(sender));

                string elementSearchParam = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                              where rw.Field <string>("Parameter Name") == "Element Search Parameter"
                                              select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertToUserVariable(sender));

                string elementSearchMethod = ((from rw in v_IfActionParameterTable.AsEnumerable()
                                               where rw.Field <string>("Parameter Name") == "Element Search Method"
                                               select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertToUserVariable(sender));


                UIAutomationCommand_cn newUIACommand = new UIAutomationCommand_cn();
                newUIACommand.v_WindowName = windowName;
                newUIACommand.v_UIASearchParameters.Rows.Add(true, elementSearchMethod, elementSearchParam);
                var handle = newUIACommand.SearchForGUIElement(sender, windowName);

                if (handle is null)
                {
                    ifResult = false;
                }
                else
                {
                    ifResult = true;
                }
            }
            else
            {
                throw new Exception("If type not recognized!");
            }



            int startIndex, endIndex, elseIndex;

            if (parentCommand.AdditionalScriptCommands.Any(item => item.ScriptCommand is Core.Automation.Commands.ElseCommand))
            {
                elseIndex = parentCommand.AdditionalScriptCommands.FindIndex(a => a.ScriptCommand is Core.Automation.Commands.ElseCommand);

                if (ifResult)
                {
                    startIndex = 0;
                    endIndex   = elseIndex;
                }
                else
                {
                    startIndex = elseIndex + 1;
                    endIndex   = parentCommand.AdditionalScriptCommands.Count;
                }
            }
            else if (ifResult)
            {
                startIndex = 0;
                endIndex   = parentCommand.AdditionalScriptCommands.Count;
            }
            else
            {
                return;
            }

            for (int i = startIndex; i < endIndex; i++)
            {
                if ((engine.IsCancellationPending) || (engine.CurrentLoopCancelled))
                {
                    return;
                }

                engine.ExecuteCommand(parentCommand.AdditionalScriptCommands[i]);
            }
        }
Exemple #11
0
        public static bool DetermineStatementTruth(IAutomationEngineInstance engine, string ifActionType, DataTable IfActionParameterTable)
        {
            bool ifResult = false;

            if (ifActionType == "Value Compare")
            {
                string value1 = ((from rw in IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value1"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string operand = ((from rw in IfActionParameterTable.AsEnumerable()
                                   where rw.Field <string>("Parameter Name") == "Operand"
                                   select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string value2 = ((from rw in IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value2"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());

                value1 = value1.ConvertUserVariableToString(engine);
                value2 = value2.ConvertUserVariableToString(engine);

                decimal cdecValue1, cdecValue2;

                switch (operand)
                {
                case "is equal to":
                    ifResult = (value1 == value2);
                    break;

                case "is not equal to":
                    ifResult = (value1 != value2);
                    break;

                case "is greater than":
                    cdecValue1 = Convert.ToDecimal(value1);
                    cdecValue2 = Convert.ToDecimal(value2);
                    ifResult   = (cdecValue1 > cdecValue2);
                    break;

                case "is greater than or equal to":
                    cdecValue1 = Convert.ToDecimal(value1);
                    cdecValue2 = Convert.ToDecimal(value2);
                    ifResult   = (cdecValue1 >= cdecValue2);
                    break;

                case "is less than":
                    cdecValue1 = Convert.ToDecimal(value1);
                    cdecValue2 = Convert.ToDecimal(value2);
                    ifResult   = (cdecValue1 < cdecValue2);
                    break;

                case "is less than or equal to":
                    cdecValue1 = Convert.ToDecimal(value1);
                    cdecValue2 = Convert.ToDecimal(value2);
                    ifResult   = (cdecValue1 <= cdecValue2);
                    break;
                }
            }
            else if (ifActionType == "Date Compare")
            {
                string value1 = ((from rw in IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value1"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string operand = ((from rw in IfActionParameterTable.AsEnumerable()
                                   where rw.Field <string>("Parameter Name") == "Operand"
                                   select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string value2 = ((from rw in IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value2"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());

                DateTime dt1, dt2;

                dynamic input1 = value1.ConvertUserVariableToString(engine);

                if (input1 == value1 && input1.StartsWith("{") && input1.EndsWith("}"))
                {
                    input1 = value1.ConvertUserVariableToObject(engine, typeof(object));
                }

                if (input1 is DateTime)
                {
                    dt1 = (DateTime)input1;
                }
                else if (input1 is string)
                {
                    dt1 = DateTime.Parse((string)input1);
                }
                else
                {
                    throw new InvalidDataException("Value1 is not a valid DateTime");
                }

                dynamic input2 = value2.ConvertUserVariableToString(engine);

                if (input2 == value2 && input2.StartsWith("{") && input2.EndsWith("}"))
                {
                    input2 = value2.ConvertUserVariableToObject(engine, typeof(object));
                }

                if (input2 is DateTime)
                {
                    dt2 = (DateTime)input2;
                }
                else if (input2 is string)
                {
                    dt2 = DateTime.Parse((string)input2);
                }
                else
                {
                    throw new InvalidDataException("Value2 is not a valid DateTime");
                }

                switch (operand)
                {
                case "is equal to":
                    ifResult = (dt1 == dt2);
                    break;

                case "is not equal to":
                    ifResult = (dt1 != dt2);
                    break;

                case "is greater than":
                    ifResult = (dt1 > dt2);
                    break;

                case "is greater than or equal to":
                    ifResult = (dt1 >= dt2);
                    break;

                case "is less than":
                    ifResult = (dt1 < dt2);
                    break;

                case "is less than or equal to":
                    ifResult = (dt1 <= dt2);
                    break;
                }
            }
            else if (ifActionType == "Variable Compare")
            {
                string value1 = ((from rw in IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value1"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string operand = ((from rw in IfActionParameterTable.AsEnumerable()
                                   where rw.Field <string>("Parameter Name") == "Operand"
                                   select rw.Field <string>("Parameter Value")).FirstOrDefault());
                string value2 = ((from rw in IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Value2"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string caseSensitive = ((from rw in IfActionParameterTable.AsEnumerable()
                                         where rw.Field <string>("Parameter Name") == "Case Sensitive"
                                         select rw.Field <string>("Parameter Value")).FirstOrDefault());

                value1 = value1.ConvertUserVariableToString(engine);
                value2 = value2.ConvertUserVariableToString(engine);

                if (caseSensitive == "No")
                {
                    value1 = value1.ToUpper();
                    value2 = value2.ToUpper();
                }

                switch (operand)
                {
                case "contains":
                    ifResult = (value1.Contains(value2));
                    break;

                case "does not contain":
                    ifResult = (!value1.Contains(value2));
                    break;

                case "is equal to":
                    ifResult = (value1 == value2);
                    break;

                case "is not equal to":
                    ifResult = (value1 != value2);
                    break;
                }
            }
            else if (ifActionType == "Variable Has Value")
            {
                string variableName = ((from rw in IfActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Variable Name"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault());

                var actualVariable = variableName.ConvertUserVariableToObject(engine, typeof(object));

                if (actualVariable != null)
                {
                    ifResult = true;
                }
                else
                {
                    ifResult = false;
                }
            }
            else if (ifActionType == "Variable Is Numeric")
            {
                string variableName = ((from rw in IfActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Variable Name"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault());

                var actualVariable = variableName.ConvertUserVariableToString(engine).Trim();

                var numericTest = decimal.TryParse(actualVariable, out decimal parsedResult);

                if (numericTest)
                {
                    ifResult = true;
                }
                else
                {
                    ifResult = false;
                }
            }
            else if (ifActionType == "Error Occured")
            {
                //get line number
                string userLineNumber = ((from rw in IfActionParameterTable.AsEnumerable()
                                          where rw.Field <string>("Parameter Name") == "Line Number"
                                          select rw.Field <string>("Parameter Value")).FirstOrDefault());

                //convert to variable
                string variableLineNumber = userLineNumber.ConvertUserVariableToString(engine);

                //convert to int
                int lineNumber = int.Parse(variableLineNumber);

                //determine if error happened
                if (engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).Count() > 0)
                {
                    var error = engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).FirstOrDefault();
                    error.ErrorMessage.StoreInUserVariable(engine, "Error.Message", typeof(string));
                    error.LineNumber.ToString().StoreInUserVariable(engine, "Error.Line", typeof(string));
                    error.StackTrace.StoreInUserVariable(engine, "Error.StackTrace", typeof(string));

                    ifResult = true;
                }
                else
                {
                    ifResult = false;
                }
            }
            else if (ifActionType == "Error Did Not Occur")
            {
                //get line number
                string userLineNumber = ((from rw in IfActionParameterTable.AsEnumerable()
                                          where rw.Field <string>("Parameter Name") == "Line Number"
                                          select rw.Field <string>("Parameter Value")).FirstOrDefault());

                //convert to variable
                string variableLineNumber = userLineNumber.ConvertUserVariableToString(engine);

                //convert to int
                int lineNumber = int.Parse(variableLineNumber);

                //determine if error happened
                if (engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).Count() == 0)
                {
                    ifResult = true;
                }
                else
                {
                    var error = engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).FirstOrDefault();
                    error.ErrorMessage.StoreInUserVariable(engine, "Error.Message", typeof(string));
                    error.LineNumber.ToString().StoreInUserVariable(engine, "Error.Line", typeof(string));
                    error.StackTrace.StoreInUserVariable(engine, "Error.StackTrace", typeof(string));

                    ifResult = false;
                }
            }
            else if (ifActionType == "Window Name Exists")
            {
                //get user supplied name
                string windowName = ((from rw in IfActionParameterTable.AsEnumerable()
                                      where rw.Field <string>("Parameter Name") == "Window Name"
                                      select rw.Field <string>("Parameter Value")).FirstOrDefault());
                //variable translation
                string variablizedWindowName = windowName.ConvertUserVariableToString(engine);

                //search for window
                IntPtr windowPtr = User32Functions.FindWindow(variablizedWindowName);

                //conditional
                if (windowPtr != IntPtr.Zero)
                {
                    ifResult = true;
                }
            }
            else if (ifActionType == "Active Window Name Is")
            {
                string windowName = ((from rw in IfActionParameterTable.AsEnumerable()
                                      where rw.Field <string>("Parameter Name") == "Window Name"
                                      select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string variablizedWindowName = windowName.ConvertUserVariableToString(engine);

                var currentWindowTitle = User32Functions.GetActiveWindowTitle();

                if (currentWindowTitle == variablizedWindowName)
                {
                    ifResult = true;
                }
            }
            else if (ifActionType == "File Exists")
            {
                string fileName = ((from rw in IfActionParameterTable.AsEnumerable()
                                    where rw.Field <string>("Parameter Name") == "File Path"
                                    select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string trueWhenFileExists = ((from rw in IfActionParameterTable.AsEnumerable()
                                              where rw.Field <string>("Parameter Name") == "True When"
                                              select rw.Field <string>("Parameter Value")).FirstOrDefault());

                var userFileSelected = fileName.ConvertUserVariableToString(engine);

                bool existCheck = false;
                if (trueWhenFileExists == "It Does Exist")
                {
                    existCheck = true;
                }

                if (File.Exists(userFileSelected) == existCheck)
                {
                    ifResult = true;
                }
            }
            else if (ifActionType == "Folder Exists")
            {
                string folderName = ((from rw in IfActionParameterTable.AsEnumerable()
                                      where rw.Field <string>("Parameter Name") == "Folder Path"
                                      select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string trueWhenFileExists = ((from rw in IfActionParameterTable.AsEnumerable()
                                              where rw.Field <string>("Parameter Name") == "True When"
                                              select rw.Field <string>("Parameter Value")).FirstOrDefault());

                var userFolderSelected = folderName.ConvertUserVariableToString(engine);

                bool existCheck = false;
                if (trueWhenFileExists == "It Does Exist")
                {
                    existCheck = true;
                }

                if (Directory.Exists(userFolderSelected) == existCheck)
                {
                    ifResult = true;
                }
            }
            else if (ifActionType == "Web Element Exists")
            {
                string instanceName = ((from rw in IfActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Selenium Instance Name"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string parameterName = ((from rw in IfActionParameterTable.AsEnumerable()
                                         where rw.Field <string>("Parameter Name") == "Element Search Parameter"
                                         select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string searchMethod = ((from rw in IfActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Element Search Method"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string timeout = ((from rw in IfActionParameterTable.AsEnumerable()
                                   where rw.Field <string>("Parameter Name") == "Timeout (Seconds)"
                                   select rw.Field <string>("Parameter Value")).FirstOrDefault());

                string trueWhenElementExists = (from rw in IfActionParameterTable.AsEnumerable()
                                                where rw.Field <string>("Parameter Name") == "True When"
                                                select rw.Field <string>("Parameter Value")).FirstOrDefault();

                bool elementExists = ElementExists(engine, instanceName, searchMethod, parameterName, "Find Element", int.Parse(timeout));
                ifResult = elementExists;

                if (trueWhenElementExists == "It Does Not Exist")
                {
                    ifResult = !ifResult;
                }
            }
            else if (ifActionType == "GUI Element Exists")
            {
                string windowName = ((from rw in IfActionParameterTable.AsEnumerable()
                                      where rw.Field <string>("Parameter Name") == "Window Name"
                                      select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));

                string elementSearchParam = ((from rw in IfActionParameterTable.AsEnumerable()
                                              where rw.Field <string>("Parameter Name") == "Element Search Parameter"
                                              select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));

                string elementSearchMethod = ((from rw in IfActionParameterTable.AsEnumerable()
                                               where rw.Field <string>("Parameter Name") == "Element Search Method"
                                               select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));

                string trueWhenElementExists = (from rw in IfActionParameterTable.AsEnumerable()
                                                where rw.Field <string>("Parameter Name") == "True When"
                                                select rw.Field <string>("Parameter Value")).FirstOrDefault();

                string timeout = (from rw in IfActionParameterTable.AsEnumerable()
                                  where rw.Field <string>("Parameter Name") == "Timeout (Seconds)"
                                  select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine);

                //set up search parameter table
                var uiASearchParameters = new DataTable();
                uiASearchParameters.Columns.Add("Enabled");
                uiASearchParameters.Columns.Add("Parameter Name");
                uiASearchParameters.Columns.Add("Parameter Value");
                uiASearchParameters.Rows.Add(true, elementSearchMethod, elementSearchParam);

                int vTimeout             = int.Parse(timeout);
                AutomationElement handle = null;
                var timeToEnd            = DateTime.Now.AddSeconds(vTimeout);
                while (timeToEnd >= DateTime.Now)
                {
                    try
                    {
                        handle = SearchForGUIElement(engine, uiASearchParameters, windowName);
                        break;
                    }
                    catch (Exception)
                    {
                        engine.ReportProgress("Element Not Yet Found... " + (timeToEnd - DateTime.Now).Seconds + "s remain");
                        Thread.Sleep(500);
                    }
                }

                if (handle is null)
                {
                    ifResult = false;
                }
                else
                {
                    ifResult = true;
                }

                if (trueWhenElementExists == "It Does Not Exist")
                {
                    ifResult = !ifResult;
                }
            }
            else if (ifActionType == "Image Element Exists")
            {
                string imageName = (from rw in IfActionParameterTable.AsEnumerable()
                                    where rw.Field <string>("Parameter Name") == "Captured Image Variable"
                                    select rw.Field <string>("Parameter Value")).FirstOrDefault();
                double accuracy;
                try
                {
                    accuracy = double.Parse((from rw in IfActionParameterTable.AsEnumerable()
                                             where rw.Field <string>("Parameter Name") == "Accuracy (0-1)"
                                             select rw.Field <string>("Parameter Value")).FirstOrDefault().ConvertUserVariableToString(engine));
                    if (accuracy > 1 || accuracy < 0)
                    {
                        throw new ArgumentOutOfRangeException("Accuracy value is out of range (0-1)");
                    }
                }
                catch (Exception)
                {
                    throw new InvalidDataException("Accuracy value is invalid");
                }

                string trueWhenImageExists = (from rw in IfActionParameterTable.AsEnumerable()
                                              where rw.Field <string>("Parameter Name") == "True When"
                                              select rw.Field <string>("Parameter Value")).FirstOrDefault();

                var imageVariable = imageName.ConvertUserVariableToObject(engine, typeof(Bitmap));

                Bitmap capturedImage;
                if (imageVariable != null && imageVariable is Bitmap)
                {
                    capturedImage = (Bitmap)imageVariable;
                }
                else
                {
                    throw new ArgumentException("Provided Argument is not a 'Bitmap' Image");
                }

                var element = FindImageElement(capturedImage, accuracy);
                FormsHelper.ShowAllForms();

                if (element != null)
                {
                    ifResult = true;
                }
                else
                {
                    ifResult = false;
                }

                if (trueWhenImageExists == "It Does Not Exist")
                {
                    ifResult = !ifResult;
                }
            }
            else if (ifActionType == "App Instance Exists")
            {
                string instanceName = (from rw in IfActionParameterTable.AsEnumerable()
                                       where rw.Field <string>("Parameter Name") == "Instance Name"
                                       select rw.Field <string>("Parameter Value")).FirstOrDefault();


                string trueWhenImageExists = (from rw in IfActionParameterTable.AsEnumerable()
                                              where rw.Field <string>("Parameter Name") == "True When"
                                              select rw.Field <string>("Parameter Value")).FirstOrDefault();

                ifResult = instanceName.InstanceExists(engine);

                if (trueWhenImageExists == "It Does Not Exist")
                {
                    ifResult = !ifResult;
                }
            }
            else
            {
                throw new Exception("If type not recognized!");
            }

            return(ifResult);
        }
Exemple #12
0
        public async static Task <bool> DetermineStatementTruth(IAutomationEngineInstance engine, string ifActionType, DataTable IfActionParameterTable, string condition = "false")
        {
            bool ifResult = false;

            if (ifActionType == null)
            {
                ifResult = (bool)await condition.EvaluateCode(engine);
            }
            else
            {
                switch (ifActionType)
                {
                case "Number Compare":
                    string num1 = ((from rw in IfActionParameterTable.AsEnumerable()
                                    where rw.Field <string>("Parameter Name") == "Number1"
                                    select rw.Field <string>("Parameter Value")).FirstOrDefault());
                    string numOperand = ((from rw in IfActionParameterTable.AsEnumerable()
                                          where rw.Field <string>("Parameter Name") == "Operand"
                                          select rw.Field <string>("Parameter Value")).FirstOrDefault());
                    string num2 = ((from rw in IfActionParameterTable.AsEnumerable()
                                    where rw.Field <string>("Parameter Name") == "Number2"
                                    select rw.Field <string>("Parameter Value")).FirstOrDefault());

                    var cdecValue1 = Convert.ToDecimal(await num1.EvaluateCode(engine));
                    var cdecValue2 = Convert.ToDecimal(await num2.EvaluateCode(engine));

                    switch (numOperand)
                    {
                    case "is equal to":
                        ifResult = cdecValue1 == cdecValue2;
                        break;

                    case "is not equal to":
                        ifResult = cdecValue1 != cdecValue2;
                        break;

                    case "is greater than":
                        ifResult = cdecValue1 > cdecValue2;
                        break;

                    case "is greater than or equal to":
                        ifResult = cdecValue1 >= cdecValue2;
                        break;

                    case "is less than":
                        ifResult = cdecValue1 < cdecValue2;
                        break;

                    case "is less than or equal to":
                        ifResult = cdecValue1 <= cdecValue2;
                        break;
                    }
                    break;

                case "Date Compare":
                    string date1 = ((from rw in IfActionParameterTable.AsEnumerable()
                                     where rw.Field <string>("Parameter Name") == "Date1"
                                     select rw.Field <string>("Parameter Value")).FirstOrDefault());
                    string dateOperand = ((from rw in IfActionParameterTable.AsEnumerable()
                                           where rw.Field <string>("Parameter Name") == "Operand"
                                           select rw.Field <string>("Parameter Value")).FirstOrDefault());
                    string date2 = ((from rw in IfActionParameterTable.AsEnumerable()
                                     where rw.Field <string>("Parameter Name") == "Date2"
                                     select rw.Field <string>("Parameter Value")).FirstOrDefault());

                    var dt1 = (DateTime)await date1.EvaluateCode(engine);

                    var dt2 = (DateTime)await date2.EvaluateCode(engine);

                    switch (dateOperand)
                    {
                    case "is equal to":
                        ifResult = dt1 == dt2;
                        break;

                    case "is not equal to":
                        ifResult = dt1 != dt2;
                        break;

                    case "is greater than":
                        ifResult = dt1 > dt2;
                        break;

                    case "is greater than or equal to":
                        ifResult = dt1 >= dt2;
                        break;

                    case "is less than":
                        ifResult = dt1 < dt2;
                        break;

                    case "is less than or equal to":
                        ifResult = dt1 <= dt2;
                        break;
                    }
                    break;

                case "Text Compare":
                    string text1 = ((from rw in IfActionParameterTable.AsEnumerable()
                                     where rw.Field <string>("Parameter Name") == "Text1"
                                     select rw.Field <string>("Parameter Value")).FirstOrDefault());
                    string textOperand = ((from rw in IfActionParameterTable.AsEnumerable()
                                           where rw.Field <string>("Parameter Name") == "Operand"
                                           select rw.Field <string>("Parameter Value")).FirstOrDefault());
                    string text2 = ((from rw in IfActionParameterTable.AsEnumerable()
                                     where rw.Field <string>("Parameter Name") == "Text2"
                                     select rw.Field <string>("Parameter Value")).FirstOrDefault());

                    string caseSensitive = ((from rw in IfActionParameterTable.AsEnumerable()
                                             where rw.Field <string>("Parameter Name") == "Case Sensitive"
                                             select rw.Field <string>("Parameter Value")).FirstOrDefault());

                    text1 = (string)await text1.EvaluateCode(engine);

                    text2 = (string)await text2.EvaluateCode(engine);

                    if (caseSensitive == "No")
                    {
                        text1 = text1.ToUpper();
                        text2 = text2.ToUpper();
                    }

                    switch (textOperand)
                    {
                    case "contains":
                        ifResult = text1.Contains(text2);
                        break;

                    case "does not contain":
                        ifResult = !text1.Contains(text2);
                        break;

                    case "is equal to":
                        ifResult = text1 == text2;
                        break;

                    case "is not equal to":
                        ifResult = text1 != text2;
                        break;
                    }
                    break;

                case "Has Value":
                    string variableName = ((from rw in IfActionParameterTable.AsEnumerable()
                                            where rw.Field <string>("Parameter Name") == "Variable Name"
                                            select rw.Field <string>("Parameter Value")).FirstOrDefault());

                    dynamic actualVariable = variableName.EvaluateCode(engine);

                    if (actualVariable.Result != null)
                    {
                        ifResult = true;
                    }
                    else
                    {
                        ifResult = false;
                    }
                    break;

                case "Is Numeric":
                    string isNumericVariableName = ((from rw in IfActionParameterTable.AsEnumerable()
                                                     where rw.Field <string>("Parameter Name") == "Variable Name"
                                                     select rw.Field <string>("Parameter Value")).FirstOrDefault());

                    ifResult = decimal.TryParse((await isNumericVariableName.EvaluateCode(engine)).ToString(), out decimal decimalResult);
                    break;

                case "Error Occured":
                    //get line number
                    string userLineNumber = ((from rw in IfActionParameterTable.AsEnumerable()
                                              where rw.Field <string>("Parameter Name") == "Line Number"
                                              select rw.Field <string>("Parameter Value")).FirstOrDefault());

                    //convert to int
                    int lineNumber = (int)await userLineNumber.EvaluateCode(engine);

                    //determine if error happened
                    if (engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).Count() > 0)
                    {
                        var error = engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).FirstOrDefault();
                        error.ErrorMessage.SetVariableValue(engine, "Error.Message");
                        error.LineNumber.ToString().SetVariableValue(engine, "Error.Line");
                        error.StackTrace.SetVariableValue(engine, "Error.StackTrace");

                        ifResult = true;
                    }
                    else
                    {
                        ifResult = false;
                    }
                    break;

                case "Error Did Not Occur":
                    //get line number
                    string userLineNumber2 = ((from rw in IfActionParameterTable.AsEnumerable()
                                               where rw.Field <string>("Parameter Name") == "Line Number"
                                               select rw.Field <string>("Parameter Value")).FirstOrDefault());
                    //convert to int
                    int lineNumber2 = (int)await userLineNumber2.EvaluateCode(engine);

                    //determine if error happened
                    if (engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber2).Count() == 0)
                    {
                        ifResult = true;
                    }
                    else
                    {
                        var error = engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber2).FirstOrDefault();
                        error.ErrorMessage.SetVariableValue(engine, "Error.Message");
                        error.LineNumber.ToString().SetVariableValue(engine, "Error.Line");
                        error.StackTrace.SetVariableValue(engine, "Error.StackTrace");

                        ifResult = false;
                    }
                    break;

                case "Window Name Exists":
                    //get user supplied name
                    string windowName = ((from rw in IfActionParameterTable.AsEnumerable()
                                          where rw.Field <string>("Parameter Name") == "Window Name"
                                          select rw.Field <string>("Parameter Value")).FirstOrDefault());
                    //variable translation
                    string variablizedWindowName = (string)await windowName.EvaluateCode(engine);

                    //search for window
                    IntPtr windowPtr = User32Functions.FindWindow(variablizedWindowName);

                    //conditional
                    if (windowPtr != IntPtr.Zero)
                    {
                        ifResult = true;
                    }
                    break;

                case "Active Window Name Is":
                    string activeWindowName = ((from rw in IfActionParameterTable.AsEnumerable()
                                                where rw.Field <string>("Parameter Name") == "Window Name"
                                                select rw.Field <string>("Parameter Value")).FirstOrDefault());

                    string variablizedActiveWindowName = (string)await activeWindowName.EvaluateCode(engine);

                    var currentWindowTitle = User32Functions.GetActiveWindowTitle();

                    if (currentWindowTitle == variablizedActiveWindowName)
                    {
                        ifResult = true;
                    }
                    break;

                case "File Exists":
                    string fileName = ((from rw in IfActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "File Path"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault());

                    string trueWhenFileExists = ((from rw in IfActionParameterTable.AsEnumerable()
                                                  where rw.Field <string>("Parameter Name") == "True When"
                                                  select rw.Field <string>("Parameter Value")).FirstOrDefault());

                    var userFileSelected = (string)await fileName.EvaluateCode(engine);

                    bool fileExistCheck = false;
                    if (trueWhenFileExists == "It Does Exist")
                    {
                        fileExistCheck = true;
                    }

                    if (File.Exists(userFileSelected) == fileExistCheck)
                    {
                        ifResult = true;
                    }
                    break;

                case "Folder Exists":
                    string folderName = ((from rw in IfActionParameterTable.AsEnumerable()
                                          where rw.Field <string>("Parameter Name") == "Folder Path"
                                          select rw.Field <string>("Parameter Value")).FirstOrDefault());

                    string trueWhenFolderExists = ((from rw in IfActionParameterTable.AsEnumerable()
                                                    where rw.Field <string>("Parameter Name") == "True When"
                                                    select rw.Field <string>("Parameter Value")).FirstOrDefault());

                    var userFolderSelected = (string)await folderName.EvaluateCode(engine);

                    bool folderExistCheck = false;
                    if (trueWhenFolderExists == "It Does Exist")
                    {
                        folderExistCheck = true;
                    }

                    if (Directory.Exists(userFolderSelected) == folderExistCheck)
                    {
                        ifResult = true;
                    }
                    break;

                case "Selenium Web Element Exists":
                    string instanceName = ((from rw in IfActionParameterTable.AsEnumerable()
                                            where rw.Field <string>("Parameter Name") == "Selenium Instance Name"
                                            select rw.Field <string>("Parameter Value")).FirstOrDefault());

                    OBAppInstance instance = (OBAppInstance)await instanceName.EvaluateCode(engine);

                    string parameterName = ((from rw in IfActionParameterTable.AsEnumerable()
                                             where rw.Field <string>("Parameter Name") == "Element Search Parameter"
                                             select rw.Field <string>("Parameter Value")).FirstOrDefault());

                    string searchMethod = ((from rw in IfActionParameterTable.AsEnumerable()
                                            where rw.Field <string>("Parameter Name") == "Element Search Method"
                                            select rw.Field <string>("Parameter Value")).FirstOrDefault());

                    string timeoutStr = ((from rw in IfActionParameterTable.AsEnumerable()
                                          where rw.Field <string>("Parameter Name") == "Timeout (Seconds)"
                                          select rw.Field <string>("Parameter Value")).FirstOrDefault());

                    int timeout = (int)await timeoutStr.EvaluateCode(engine);

                    string trueWhenElementExists = (from rw in IfActionParameterTable.AsEnumerable()
                                                    where rw.Field <string>("Parameter Name") == "True When"
                                                    select rw.Field <string>("Parameter Value")).FirstOrDefault();

                    bool elementExists = await ElementExists(engine, instance, searchMethod, parameterName, "Find Element", timeout);

                    ifResult = elementExists;

                    if (trueWhenElementExists == "It Does Not Exist")
                    {
                        ifResult = !ifResult;
                    }
                    break;

                case "GUI Element Exists":
                    string guiWindowName = (from rw in IfActionParameterTable.AsEnumerable()
                                            where rw.Field <string>("Parameter Name") == "Window Name"
                                            select rw.Field <string>("Parameter Value")).FirstOrDefault();
                    windowName = (string)await guiWindowName.EvaluateCode(engine);

                    string elementSearchParam = (from rw in IfActionParameterTable.AsEnumerable()
                                                 where rw.Field <string>("Parameter Name") == "Element Search Parameter"
                                                 select rw.Field <string>("Parameter Value")).FirstOrDefault();
                    elementSearchParam = (string)await elementSearchParam.EvaluateCode(engine);

                    string elementSearchMethod = (from rw in IfActionParameterTable.AsEnumerable()
                                                  where rw.Field <string>("Parameter Name") == "Element Search Method"
                                                  select rw.Field <string>("Parameter Value")).FirstOrDefault();
                    elementSearchMethod = (string)await elementSearchMethod.EvaluateCode(engine);

                    string trueWhenGUIElementExists = (from rw in IfActionParameterTable.AsEnumerable()
                                                       where rw.Field <string>("Parameter Name") == "True When"
                                                       select rw.Field <string>("Parameter Value")).FirstOrDefault();

                    string timeoutString = (from rw in IfActionParameterTable.AsEnumerable()
                                            where rw.Field <string>("Parameter Name") == "Timeout (Seconds)"
                                            select rw.Field <string>("Parameter Value")).FirstOrDefault();

                    //set up search parameter table
                    var uiASearchParameters = new DataTable();
                    uiASearchParameters.Columns.Add("Enabled");
                    uiASearchParameters.Columns.Add("Parameter Name");
                    uiASearchParameters.Columns.Add("Parameter Value");
                    uiASearchParameters.Rows.Add(true, elementSearchMethod, elementSearchParam);

                    int vTimeout = (int)await timeoutString.EvaluateCode(engine);

                    AutomationElement handle = null;
                    var timeToEnd            = DateTime.Now.AddSeconds(vTimeout);
                    while (timeToEnd >= DateTime.Now)
                    {
                        try
                        {
                            handle = await SearchForGUIElement(engine, uiASearchParameters, windowName);

                            break;
                        }
                        catch (Exception)
                        {
                            engine.ReportProgress("Element Not Yet Found... " + (timeToEnd - DateTime.Now).Seconds + "s remain");
                            Thread.Sleep(500);
                        }
                    }

                    if (handle is null)
                    {
                        ifResult = false;
                    }
                    else
                    {
                        ifResult = true;
                    }

                    if (trueWhenGUIElementExists == "It Does Not Exist")
                    {
                        ifResult = !ifResult;
                    }
                    break;

                case "Image Element Exists":
                    string imageName = (from rw in IfActionParameterTable.AsEnumerable()
                                        where rw.Field <string>("Parameter Name") == "Captured Image Variable"
                                        select rw.Field <string>("Parameter Value")).FirstOrDefault();
                    string accuracyString;
                    double accuracy;
                    try
                    {
                        accuracyString = (from rw in IfActionParameterTable.AsEnumerable()
                                          where rw.Field <string>("Parameter Name") == "Accuracy (0-1)"
                                          select rw.Field <string>("Parameter Value")).FirstOrDefault();
                        accuracy = (double)await accuracyString.EvaluateCode(engine);

                        if (accuracy > 1 || accuracy < 0)
                        {
                            throw new ArgumentOutOfRangeException("Accuracy value is out of range (0-1)");
                        }
                    }
                    catch (Exception)
                    {
                        throw new InvalidDataException("Accuracy value is invalid");
                    }

                    string trueWhenImageExists = (from rw in IfActionParameterTable.AsEnumerable()
                                                  where rw.Field <string>("Parameter Name") == "True When"
                                                  select rw.Field <string>("Parameter Value")).FirstOrDefault();

                    var capturedImage = (Bitmap)await imageName.EvaluateCode(engine);

                    string imageTimeoutString = (from rw in IfActionParameterTable.AsEnumerable()
                                                 where rw.Field <string>("Parameter Name") == "Timeout (Seconds)"
                                                 select rw.Field <string>("Parameter Value")).FirstOrDefault();
                    int imageTimeout = (int)await imageTimeoutString.EvaluateCode(engine);

                    var element = FindImageElement(capturedImage, accuracy, engine, DateTime.Now.AddSeconds(imageTimeout));
                    FormsHelper.ShowAllForms(engine.EngineContext.IsDebugMode);

                    if (element != null)
                    {
                        ifResult = true;
                    }
                    else
                    {
                        ifResult = false;
                    }

                    if (trueWhenImageExists == "It Does Not Exist")
                    {
                        ifResult = !ifResult;
                    }
                    break;

                case "App Instance Exists":
                    string appInstanceName = (from rw in IfActionParameterTable.AsEnumerable()
                                              where rw.Field <string>("Parameter Name") == "Instance Name"
                                              select rw.Field <string>("Parameter Value")).FirstOrDefault();


                    string trueWhenAppInstanceExists = (from rw in IfActionParameterTable.AsEnumerable()
                                                        where rw.Field <string>("Parameter Name") == "True When"
                                                        select rw.Field <string>("Parameter Value")).FirstOrDefault();

                    var appInstanceObj = (OBAppInstance)await appInstanceName.EvaluateCode(engine);

                    if (appInstanceObj == null)
                    {
                        ifResult = false;
                    }
                    else
                    {
                        ifResult = appInstanceObj.Value.InstanceExists();
                    }

                    if (trueWhenAppInstanceExists == "It Does Not Exist")
                    {
                        ifResult = !ifResult;
                    }
                    break;

                default:
                    throw new Exception("If type not recognized!");
                }
            }
            return(ifResult);
        }