/// <summary>
        /// get an UIA action for the line
        /// </summary>
        /// <param name="actLine">the action line</param>
        /// <returns>the UIA action</returns>
        public override Action getAction(ActionLine actLine)
        {
            Window  targetWindow  = null;
            IUIItem targetControl = null;

            if (!Actions.ContainsKey(actLine.ActionName))
            {
                throw new Exception(Constants.Messages.Error_Executing_NoAction);
            }
            if (actLine.WindowName != null && !Parent.Interfaces.ContainsKey(actLine.WindowName))
            {
                throw new Exception(Constants.Messages.Error_Matching_Window_NoDefinition);
            }
            //if (actLine.WindowName != null )
            //  throw new Exception(Constants.Messages.Error_Matching_Window_NoDefinition);

            // search for the target control
            //Dictionary<string, string> Key = Parent.Interfaces.Values;
            if (actLine.WindowName != null)
            {
                targetWindow = FindWindow(Parent.Interfaces[actLine.WindowName].Properties);
            }
            if (actLine.ControlName != null)
            {
                targetControl = FindControl(targetWindow, Parent.Interfaces[actLine.WindowName].Controls[actLine.ControlName]);
            }
            // prepare the action
            UIAAction action = Actions[actLine.ActionName] as UIAAction;

            action.Window  = targetWindow;
            action.Control = targetControl;
            action.Params  = actLine.Arguments;

            return(action);
        }
示例#2
0
        protected override void ProcessData()
        {
            base.ProcessData();

            this.Name = "Script.xls";
            string duongdan = Parser.pathworkingdir + Constants.Directory.ScriptDir;

            string path = duongdan + Name;

            this.PathFile = path;

            //--------minh diem cai interface co bao nhieu cot

            SourceLine _SourlineScript = new SourceLine();

            Parser.getopen(path);
            int cot = Parser.ColumnCount;

            Parser.pathlines = path;
            int dong = Parser.CountRow(path);

            //----------------------------------------------------


            ActionLines = new List <ActionLine>();
            for (int j = 1; j <= dong; j++)
            {
                if (_SourlineScript.CountColmsv(path) > 0)
                {
                    ActionLine actLine = new ActionLine();
                    actLine.ActionName = Parser.ValueCell(path, j - 1, 0).ToLower();

                    for (int i = 1; i < cot; i++)
                    {
                        string[] pairs = Parser.ValueCell(path, j - 1, i).Split(Constants.PropertyDelimeter.ToCharArray(), 2);
                        if (pairs.Length != 2)
                        {
                            continue;
                        }
                        if (Constants.KeywordWindow.Equals(pairs[0], StringComparison.CurrentCultureIgnoreCase))
                        {
                            actLine.WindowName = pairs[1];
                        }
                        else if (Constants.KeywordControl.Equals(pairs[0], StringComparison.CurrentCultureIgnoreCase))
                        {
                            actLine.ControlName = pairs[1].ToLower();
                        }
                        else
                        {
                            actLine.Arguments[pairs[0]] = pairs[1];
                        }
                    }

                    ActionLines.Add(actLine);
                }
            }
        }
示例#3
0
        /// <summary>
        /// get corresponding Action object from all Action Managers
        /// </summary>
        /// <param name="actLine">the action line</param>
        /// <returns>the found action</returns>
        ///
        public Action getAction(ActionLine actLine)
        {
            int    i      = 0;
            Action action = null;

            while (action == null && i < ActionManagers.Count)
            {
                action = ActionManagers[i++].getAction(actLine);
            }

            return(action);
        }
示例#4
0
        protected override void ProcessData()
        {
            base.ProcessData();

            this.Name = "s1.xls";
            string duongdan = Parser.pathworkingdir + Constants.Directory.ScriptDir;

            string path = duongdan + Name;
            this.PathFile = path;

            //--------minh diem cai interface co bao nhieu cot

            SourceLine _SourlineScript = new SourceLine();
            Parser.getopen(path);
            int cot = Parser.ColumnCount;
            Parser.pathlines = path;
            int dong = Parser.CountRow(path);

            //----------------------------------------------------

            ActionLines = new List<ActionLine>();
            for (int j = 1; j <= dong; j++)
            {
                if (_SourlineScript.CountColmsv(path) > 0)
                {
                    ActionLine actLine = new ActionLine();
                    actLine.ActionName = Parser.ValueCell(path, j - 1, 0).ToLower();

                    for (int i = 1; i < cot; i++)
                    {

                        string[] pairs = Parser.ValueCell(path, j - 1, i).Split(Constants.PropertyDelimeter.ToCharArray(), 2);
                        if (pairs.Length != 2)
                        {
                            continue;
                        }
                        if (Constants.KeywordWindow.Equals(pairs[0], StringComparison.CurrentCultureIgnoreCase))
                            actLine.WindowName = pairs[1].ToLower();
                        else if (Constants.KeywordControl.Equals(pairs[0], StringComparison.CurrentCultureIgnoreCase))
                            actLine.ControlName = pairs[1].ToLower();
                        else
                            actLine.Arguments[pairs[0].ToLower()] = pairs[1];

                    }

                    ActionLines.Add(actLine);
                }
            }
        }
        private ActionLine ManipulateData(ActionLine actLine)
        {
            ActionLine newLine = new ActionLine();

            newLine.ActionName  = actLine.ActionName;
            newLine.WindowName  = CheckForVariable(actLine.WindowName);
            newLine.ControlName = CheckForVariable(actLine.ControlName);

            foreach (string key in actLine.Arguments.Keys)
            {
                newLine.Arguments[key] = CheckForVariable(actLine.Arguments[key]);
            }

            return(newLine);
        }
示例#6
0
        /// <summary>
        /// create an action for the line
        /// </summary>
        /// <param name="actLine">the action line</param>
        /// <returns>the action</returns>
        public override IAction getAction(ActionLine actLine)
        {
            Window  targetWindow  = null;
            IUIItem targetControl = null;

            if (!Actions.ContainsKey(actLine.ActionName))
            {
                return(null);
            }
            if (actLine.WindowName != null && !Parent.Interfaces.ContainsKey(actLine.WindowName))
            {
                throw new Exception(Constants.Messages.Error_Matching_Window_NoDefinition);
            }

            // search for the target control
            if (actLine.WindowName != null)
            {
                targetWindow = FindWindow(Parent.Interfaces[actLine.WindowName].Properties);
                if (targetWindow != null && actLine.ControlName != null)
                {
                    if (!Parent.Interfaces[actLine.WindowName].Controls.ContainsKey(actLine.ControlName))
                    {
                        throw new Exception(Constants.Messages.Error_Matching_Control_NoDefinition);
                    }

                    targetControl = FindControl(targetWindow, Parent.Interfaces[actLine.WindowName].Controls[actLine.ControlName]);
                }
            }

            // prepare the action
            UIAAction action = Actions[actLine.ActionName] as UIAAction;

            action.Window  = targetWindow;
            action.Control = targetControl;
            action.Params  = actLine.Arguments;

            return(action);
        }
        /// <summary>
        /// write an error to the report
        /// </summary>
        /// <param name="actLine">the error action line</param>
        /// <param name="why">the reason</param>
        public void WriteError(ActionLine actLine, string why)
        {
            SourceLine line = new SourceLine();

            for (int i = 0; i < Indent + 1; i++)
            {
                line.Columns.Add(string.Empty);
            }

            line.Columns.Add(actLine.ActionName);
            if (actLine.WindowName != null || actLine.ControlName != null)
            {
                line.Columns.Add(actLine.WindowName != null ? actLine.WindowName : string.Empty);
                line.Columns.Add(actLine.ControlName != null ? actLine.ControlName : string.Empty);
            }
            foreach (string key in actLine.Arguments.Keys)
            {
                line.Columns.Add(key + Constants.PropertyDelimeter + actLine.Arguments[key]);
            }
            line.Columns.Add(Constants.ReportText.ErrorLinePrefix + why);

            Lines.Add(line);
        }
        /// <summary>
        /// write a line to the report
        /// </summary>
        /// <param name="actLine">information about the action</param>
        /// <param name="result">result of the action</param>
        public void WriteLine(ActionLine actLine, ActionResult result)
        {
            SourceLine line = new SourceLine();

            for (int i = 0; i < Indent + 1; i++)
            {
                line.Columns.Add(string.Empty);
            }

            line.Columns.Add(actLine.ActionName);
            if (actLine.WindowName != null || actLine.ControlName != null)
            {
                line.Columns.Add(actLine.WindowName != null ? actLine.WindowName : string.Empty);
                line.Columns.Add(actLine.ControlName != null ? actLine.ControlName : string.Empty);
            }
            foreach (string key in actLine.Arguments.Keys)
            {
                line.Columns.Add(key + Constants.PropertyDelimeter + actLine.Arguments[key]);
            }
            line.Columns.Add(result != ActionResult.NORET ? result.ToString() : string.Empty);

            if (result == ActionResult.PASSED || result == ActionResult.FAILED)
            {
                TotalCheck++;
                if (result == ActionResult.PASSED)
                {
                    TotalPassed++;
                }
            }
            else if (result == ActionResult.WARNING)
            {
                TotalWarning++;
            }

            Lines.Add(line);
        }
 /// <summary>
 /// create an action for the line
 /// </summary>
 /// <param name="actLine">the action line</param>
 /// <returns>the action</returns>
 ///
 public abstract Action getAction(ActionLine actLine);
示例#10
0
 /// <summary>
 /// create an action for the line
 /// </summary>
 /// <param name="actLine">the action line</param>
 /// <returns>the action</returns>
 /// 
 public abstract Action getAction(ActionLine actLine);
示例#11
0
        /// <summary>
        /// execute the script
        /// </summary>
        private void Run()
        {
            IReporter reporter = Reporter.NewInstance;

            reporter.BeginReport("path");
            while (Scripts.Count > 0)
            {
                CurrentScript = Scripts.Pop();

                // begin new section in report
                if (CurrentScript.CurrentLineNumber == 0)
                {
                    reporter.BeginScript(CurrentScript.Name);
                }

                // loop for each line of current script
                while (CurrentScript.HasNextLine)
                {
                    ActionLine actLine = CurrentScript.Next();

                    if (actLine.ActionName == Constants.ActionUseInterface)
                    {
                        Interface newInterface = new Interface(Parser);
                        newInterface.PathFile = actLine.Arguments[Constants.KeywordInterface] + Parser.FileExtension;
                        Interfaces.Add(newInterface.Name, newInterface);
                    }
                    else if (actLine.ActionName == Constants.ActionStartScript)
                    {
                        Script newScript = new Script(Parser);
                        newScript.PathFile = actLine.Arguments[Constants.KeywordScript] + Parser.FileExtension;
                        Scripts.Push(CurrentScript);
                        CurrentScript = newScript;

                        // begin new section in report
                        reporter.BeginScript(CurrentScript.Name);
                    }
                    else
                    {
                        Action action = getAction(actLine);
                        if (action == null)
                        {
                            throw new InvalidOperationException("No action named '" + actLine.ActionName + "'");
                        }
                        if (!action.IsValid())
                        {
                            throw new InvalidOperationException("Invalid arguments for action named '" + actLine.ActionName + "'");
                        }

                        int ret = action.Execute();
                        action.Reset();

                        // write result of executing to report
                        reporter.WriteLine();
                    }
                }

                // end section in report
                if (CurrentScript.CurrentLineNumber > 0)
                {
                    reporter.EndScript();
                }
            }
        }
示例#12
0
        /// <summary>
        /// get an UIA action for the line
        /// </summary>
        /// <param name="actLine">the action line</param>
        /// <returns>the UIA action</returns>
        public override Action getAction(ActionLine actLine)
        {
            Window targetWindow = null;
            IUIItem targetControl = null;

            if (!Actions.ContainsKey(actLine.ActionName))
                throw new Exception(Constants.Messages.Error_Executing_NoAction);
            if (actLine.WindowName != null && !Parent.Interfaces.ContainsKey(actLine.WindowName))
                throw new Exception(Constants.Messages.Error_Matching_Window_NoDefinition);
            /*if (actLine.WindowName != null )
                throw new Exception(Constants.Messages.Error_Matching_Window_NoDefinition);*/

            // search for the target control
            //Dictionary<string, string> Key = Parent.Interfaces.Values;
            if (actLine.WindowName != null)
                targetWindow = FindWindow(Parent.Interfaces[actLine.WindowName].Properties);
            if (actLine.ControlName != null)
                targetControl = FindControl(targetWindow, Parent.Interfaces[actLine.WindowName].Controls[actLine.ControlName]);
            // prepare the action
            UIAAction action = Actions[actLine.ActionName] as UIAAction;
            action.Window = targetWindow;
            action.Control = targetControl;
            action.Params = actLine.Arguments;

            return action;
        }
示例#13
0
        /// <summary>
        /// get corresponding Action object from all Action Managers
        /// </summary>
        /// <param name="actLine">the action line</param>
        /// <returns>the found action</returns>
        /// 
        public Action getAction(ActionLine actLine)
        {
            int i = 0;
            Action action = null;
            while (action == null && i < ActionManagers.Count)
                action = ActionManagers[i++].getAction(actLine);

            return action;
        }
        /// <summary>
        /// execute the script
        /// </summary>
        //private void Run()
        //{
        //    IReporter reporter = Reporter.NewInstance;

        //    reporter.BeginReport("path");
        //    while (Scripts.Count > 0)
        //    {
        //        CurrentScript = Scripts.Pop();

        //        // begin new section in report
        //        if (CurrentScript.CurrentLineNumber == 0)
        //            reporter.BeginScript(CurrentScript.Name);

        //        // loop for each line of current script
        //        while (CurrentScript.HasNextLine)
        //        {
        //            ActionLine actLine = CurrentScript.Next();

        //            if (actLine.ActionName == Constants.ActionUseInterface)
        //            {

        //                Interface newInterface = new Interface(Parser);
        //                newInterface.PathFile = actLine.Arguments[Constants.KeywordInterface] + Parser.FileExtension;
        //                Interfaces.Add(newInterface.Name, newInterface);
        //            }
        //            else if (actLine.ActionName == Constants.ActionStartScript)
        //            {
        //                Script newScript = new Script(Parser);
        //                newScript.PathFile = actLine.Arguments[Constants.KeywordScript] + Parser.FileExtension;
        //                Scripts.Push(CurrentScript);
        //                CurrentScript = newScript;

        //                // begin new section in report
        //                reporter.BeginScript(CurrentScript.Name);
        //            }
        //            else
        //            {
        //                Action action = getAction(actLine);
        //                if (action == null)
        //                    throw new InvalidOperationException("No action named '" + actLine.ActionName + "'");
        //                if (!action.IsValid())
        //                    throw new InvalidOperationException("Invalid arguments for action named '" + actLine.ActionName + "'");

        //                int ret = action.Execute();
        //                action.Reset();

        //                // write result of executing to report
        //                reporter.WriteLine();
        //            }
        //        }

        //        // end section in report
        //        if (CurrentScript.CurrentLineNumber > 0)
        //            reporter.EndScript();
        //    }
        //}

        /// <summary>
        /// execute the script
        /// </summary>
        private void Run(IReporter reporter)
        {
            while (Scripts.Count > 0 && !IsStopped)
            {
                // pop a script from stack
                CurrentScript = Scripts.Pop();

                // begin new section in report
                if (CurrentScript.CurrentLineNumber == 0)
                {
                    reporter.BeginScript(CurrentScript.Name);
                }

                // loop for each line of current script
                while (CurrentScript.HasNextLine && !IsStopped)
                {
                    // get a action line from script
                    ActionLine actLineRaw = CurrentScript.Next();

                    // manipulate action line with DataSet
                    ActionLine actLine = ManipulateData(actLineRaw);

                    // notify about action that is going to be performed
                    if (ActionPerforming != null)
                    {
                        string summary = actLine.ActionName;
                        if (actLine.WindowName != null)
                        {
                            summary += "\t[window:" + actLine.WindowName + "]";
                        }
                        if (actLine.ControlName != null)
                        {
                            summary += "\t[control:" + actLine.ControlName + "]";
                        }
                        foreach (string key in actLine.Arguments.Keys)
                        {
                            summary += "\t[" + key + ":" + actLine.Arguments[key] + "]";
                        }
                        ActionPerforming(summary);
                    }

                    // the action is 'use interface'
                    if (actLine.ActionName == Constants.ActionUseInterface)
                    {
                        if (!Interfaces.ContainsKey(actLine.Arguments[Constants.KeywordInterface].ToLower()))
                        {
                            Interface newInterface = new Interface(Parser);
                            //newInterface.FileName = actLine.Arguments[Constants.Keywords.KeywordInterface] + Parser.FileExtension;
                            Interfaces.Add(newInterface.Name, newInterface);
                        }
                    }
                    // the action is 'run script'
                    else if (actLine.ActionName == Constants.ActionStartScript)
                    {
                        Script newScript = new Script(Parser);
                        //newScript.FileName = actLine.Arguments[Constants.Keywords.KeywordScript] + Parser.FileExtension;

                        // push current script to stack and run new script
                        Scripts.Push(CurrentScript);
                        CurrentScript = newScript;

                        // begin new section in report
                        reporter.BeginScript(CurrentScript.Name);
                    }
                    else
                    {
                        try
                        {
                            Action action = getAction(actLine);
                            if (action == null)
                            {
                                throw new Exception(Constants.Messages.Error_Executing_NoAction);
                            }

                            if (!action.IsValid())
                            {
                                throw new Exception(Constants.Messages.Error_Executing_InvalidArg);
                            }

                            // execute the action
                            int ret = action.Execute();

                            // write result of executing to report
                            //  reporter.WriteLine(actLine, action.Result);

                            // reset the action state
                            action.Reset();
                        }
                        catch (Exception e)
                        {
                            //reporter.WriteError(actLine, e.Message);
                            // InteruptWithError(e.Message);
                        }
                    }

                    // if the automation is paused, just sleep
                    CheckPaused();

                    // check if user interupt the automation
                    if (!CheckStopped())
                    {
                        ProcessSpeed();
                    }
                }

                // if the automation is paused, just sleep
                CheckPaused();

                // check if user interupt the automation
                CheckStopped();

                // end section in report
                if (CurrentScript.CurrentLineNumber > 0)
                {
                    //reporter.EndScript(CurrentScript.Name);
                }
            }
        }