public FormViewer() { InitializeComponent(); IAutomation automation = new Automation(new ExcelFileParser(), new ExcelReporter(new ExcelFileParser()), @"E:\demo_new\dotnetabt\codeduiabt\sample"); UIAActionManager actionManager = new UIAActionManager(automation); actionManager.WaitTime = new TimeSpan(0, 0, 1); IInterface iff = new Interface(automation.Parser.NewInstance); iff.FileName = "Calculator.xls"; windowsViewer1.ActionManager = actionManager; windowsViewer1.CurrentInterface = iff; windowsViewer1.WindowsRefreshed += windowsViewer1_WindowsRefreshed; propertiesViewer1.CurrentInterface = iff; }
/// <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(); if (actLineRaw.ActionName.Length == 0) continue; // 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.Keywords.ActionUseInterface) { if (!Interfaces.ContainsKey(actLine.Arguments[Constants.Keywords.KeywordInterface].ToLower())) { IInterface newInterface = new Interface(Parser.NewInstance); newInterface.FileName = actLine.Arguments[Constants.Keywords.KeywordInterface] + Parser.FileExtension; Interfaces.Add(newInterface.Name, newInterface); } } // the action is 'run script' else if (actLine.ActionName == Constants.Keywords.ActionStartScript) { Script newScript = new Script(Parser.NewInstance); 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 { IAction 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); } }