Exemplo n.º 1
0
        public override void RunCommand(object sender)
        {
            var engine = (AutomationEngineInstance)sender;
            var webURL = v_URL.ConvertUserVariableToString(engine);

            InternetExplorer newBrowserSession = new InternetExplorer();

            if (!string.IsNullOrEmpty(webURL.Trim()))
            {
                try
                {
                    newBrowserSession.Navigate(webURL);
                    WaitForReadyState(newBrowserSession);
                    newBrowserSession.Visible = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            //add app instance
            newBrowserSession.AddAppInstance(engine, v_InstanceName);

            //handle app instance tracking
            if (v_InstanceTracking == "Keep Instance Alive")
            {
                GlobalAppInstances.AddInstance(v_InstanceName, newBrowserSession);
            }
        }
Exemplo n.º 2
0
        public override void RunCommand(object sender)
        {
            var engine     = (Core.Automation.Engine.AutomationEngineInstance)sender;
            var driverPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Resources");

            OpenQA.Selenium.Chrome.ChromeDriverService driverService = OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService(driverPath);

            var newSeleniumSession = new OpenQA.Selenium.Chrome.ChromeDriver(driverService, new OpenQA.Selenium.Chrome.ChromeOptions());

            var instanceName = v_InstanceName.ConvertToUserVariable(sender);

            engine.AddAppInstance(instanceName, newSeleniumSession);


            //handle app instance tracking
            if (v_InstanceTracking == "Keep Instance Alive")
            {
                GlobalAppInstances.AddInstance(instanceName, newSeleniumSession);
            }

            //handle window type on startup - https://github.com/saucepleez/taskt/issues/22
            switch (v_BrowserWindowOption)
            {
            case "Maximize":
                newSeleniumSession.Manage().Window.Maximize();
                break;

            case "Normal":
            case "":
            default:
                break;
            }
        }
        public override void RunCommand(object sender)
        {
            var engine         = (Core.Automation.Engine.AutomationEngineInstance)sender;
            var driverPath     = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Resources");
            var seleniumEngine = v_EngineType.ConvertToUserVariable(sender);
            var instanceName   = v_InstanceName.ConvertToUserVariable(sender);

            OpenQA.Selenium.DriverService driverService;
            OpenQA.Selenium.IWebDriver    webDriver;

            if (seleniumEngine == "Chrome")
            {
                OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();

                if (!string.IsNullOrEmpty(v_SeleniumOptions))
                {
                    var convertedOptions = v_SeleniumOptions.ConvertToUserVariable(sender);
                    options.AddArguments(convertedOptions);
                }

                driverService = OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService(driverPath);
                webDriver     = new OpenQA.Selenium.Chrome.ChromeDriver((OpenQA.Selenium.Chrome.ChromeDriverService)driverService, options);
            }
            else
            {
                driverService = OpenQA.Selenium.IE.InternetExplorerDriverService.CreateDefaultService(driverPath);
                webDriver     = new OpenQA.Selenium.IE.InternetExplorerDriver((OpenQA.Selenium.IE.InternetExplorerDriverService)driverService, new OpenQA.Selenium.IE.InternetExplorerOptions());
            }


            //add app instance
            engine.AddAppInstance(instanceName, webDriver);


            //handle app instance tracking
            if (v_InstanceTracking == "Keep Instance Alive")
            {
                GlobalAppInstances.AddInstance(instanceName, webDriver);
            }

            //handle window type on startup - https://github.com/saucepleez/taskt/issues/22
            switch (v_BrowserWindowOption)
            {
            case "Maximize":
                webDriver.Manage().Window.Maximize();
                break;

            case "Normal":
            case "":
            default:
                break;
            }
        }
        public override void RunCommand(object sender)
        {
            var engine     = (AutomationEngineInstance)sender;
            var driverPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Resources");

            DriverService driverService;
            IWebDriver    webDriver;

            if (v_EngineType == "Chrome")
            {
                ChromeOptions options = new ChromeOptions();

                options.AddUserProfilePreference("download.prompt_for_download", true);

                if (!string.IsNullOrEmpty(v_SeleniumOptions))
                {
                    var convertedOptions = v_SeleniumOptions.ConvertUserVariableToString(engine);
                    options.AddArguments(convertedOptions);
                }

                driverService = ChromeDriverService.CreateDefaultService(driverPath);
                webDriver     = new ChromeDriver((ChromeDriverService)driverService, options);
            }
            else
            {
                driverService = InternetExplorerDriverService.CreateDefaultService(driverPath);
                webDriver     = new InternetExplorerDriver((InternetExplorerDriverService)driverService, new InternetExplorerOptions());
            }

            //add app instance
            webDriver.AddAppInstance(engine, v_InstanceName);

            //handle app instance tracking
            if (v_InstanceTracking == "Keep Instance Alive")
            {
                GlobalAppInstances.AddInstance(v_InstanceName, webDriver);
            }

            //handle window type on startup - https://github.com/saucepleez/taskt/issues/22
            switch (v_BrowserWindowOption)
            {
            case "Maximize":
                webDriver.Manage().Window.Maximize();
                break;

            case "Normal":
            case "":
            default:
                break;
            }
        }
Exemplo n.º 5
0
        public override void RunCommand(object sender)
        {
            var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;

            var instanceName = v_InstanceName.ConvertToUserVariable(sender);

            SHDocVw.InternetExplorer newBrowserSession = new SHDocVw.InternetExplorer();
            try
            {
                newBrowserSession.Navigate(v_URL.ConvertToUserVariable(sender));
                WaitForReadyState(newBrowserSession);
                newBrowserSession.Visible = true;
            }
            catch (Exception ex) { }

            //add app instance
            engine.AddAppInstance(instanceName, newBrowserSession);

            //handle app instance tracking
            if (v_InstanceTracking == "Keep Instance Alive")
            {
                GlobalAppInstances.AddInstance(instanceName, newBrowserSession);
            }
        }
Exemplo n.º 6
0
        public void ExecuteScript(string data, bool dataIsFile)
        {
            Core.Client.EngineBusy = true;


            try
            {
                CurrentStatus = EngineStatus.Running;

                //create stopwatch for metrics tracking
                sw = new System.Diagnostics.Stopwatch();
                sw.Start();

                //log starting
                ReportProgress("Bot Engine Started: " + DateTime.Now.ToString());

                //get automation script
                Core.Script.Script automationScript;
                if (dataIsFile)
                {
                    ReportProgress("Deserializing File");
                    engineLogger.Information("Script Path: " + data);
                    FileName         = data;
                    automationScript = Core.Script.Script.DeserializeFile(data);
                }
                else
                {
                    ReportProgress("Deserializing XML");
                    automationScript = Core.Script.Script.DeserializeXML(data);
                }

                if (serverSettings.ServerConnectionEnabled && taskModel == null)
                {
                    taskModel = HttpServerClient.AddTask(data);
                }
                else if (serverSettings.ServerConnectionEnabled && taskModel != null)
                {
                    taskModel = HttpServerClient.UpdateTask(taskModel.TaskID, "Running", "Running Server Assignment");
                }

                //track variables and app instances
                ReportProgress("Creating Variable List");


                //set variables if they were passed in
                if (VariableList != null)
                {
                    foreach (var var in VariableList)
                    {
                        var variableFound = automationScript.Variables.Where(f => f.VariableName == var.VariableName).FirstOrDefault();

                        if (variableFound != null)
                        {
                            variableFound.VariableValue = var.VariableValue;
                        }
                    }
                }


                VariableList = automationScript.Variables;


                ReportProgress("Creating App Instance Tracking List");
                //create app instances and merge in global instances
                this.AppInstances = new Dictionary <string, object>();
                var GlobalInstances = GlobalAppInstances.GetInstances();
                foreach (var instance in GlobalInstances)
                {
                    this.AppInstances.Add(instance.Key, instance.Value);
                }


                //execute commands
                foreach (var executionCommand in automationScript.Commands)
                {
                    if (IsCancellationPending)
                    {
                        ReportProgress("Cancelling Script");
                        ScriptFinished(ScriptFinishedEventArgs.ScriptFinishedResult.Cancelled);
                        return;
                    }

                    ExecuteCommand(executionCommand);
                }

                if (IsCancellationPending)
                {
                    //mark cancelled - handles when cancelling and user defines 1 parent command or else it will show successful
                    ScriptFinished(ScriptFinishedEventArgs.ScriptFinishedResult.Cancelled);
                }
                else
                {
                    //mark finished
                    ScriptFinished(ScriptFinishedEventArgs.ScriptFinishedResult.Successful);
                }
            }
            catch (Exception ex)
            {
                ScriptFinished(ScriptFinishedEventArgs.ScriptFinishedResult.Error, ex.ToString());
            }
        }
Exemplo n.º 7
0
        public override void RunCommand(object sender)
        {
            var engine           = (AutomationEngineInstance)sender;
            var convertedOptions = v_SeleniumOptions.ConvertUserVariableToString(engine);
            var vURL             = v_URL.ConvertUserVariableToString(engine);

            IWebDriver webDriver;

            switch (v_EngineType)
            {
            case "Chrome":
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.AddUserProfilePreference("download.prompt_for_download", true);

                if (!string.IsNullOrEmpty(convertedOptions.Trim()))
                {
                    chromeOptions.AddArguments(convertedOptions);
                }

                webDriver = new ChromeDriver(chromeOptions);
                break;

            case "Firefox":
                string firefoxExecutablePath = @"C:\Program Files\Mozilla Firefox\firefox.exe";
                if (!File.Exists(firefoxExecutablePath))
                {
                    throw new FileNotFoundException($"Could not locate '{firefoxExecutablePath}'");
                }

                FirefoxOptions firefoxOptions = new FirefoxOptions();
                firefoxOptions.BrowserExecutableLocation = firefoxExecutablePath;

                webDriver = new FirefoxDriver(firefoxOptions);
                break;

            case "Internet Explorer":
                InternetExplorerOptions ieOptions = new InternetExplorerOptions();
                ieOptions.IgnoreZoomLevel = true;

                webDriver = new InternetExplorerDriver(ieOptions);
                break;

            default:
                throw new Exception($"The selected engine type '{v_EngineType}' is not valid.");
            }

            //add app instance
            webDriver.AddAppInstance(engine, v_InstanceName);

            //handle app instance tracking
            if (v_InstanceTracking == "Keep Instance Alive")
            {
                GlobalAppInstances.AddInstance(v_InstanceName, webDriver);
            }

            switch (v_BrowserWindowOption)
            {
            case "Maximize":
                webDriver.Manage().Window.Maximize();
                break;

            case "Normal":
            case "":
            default:
                break;
            }

            if (!string.IsNullOrEmpty(vURL.Trim()) && vURL.Trim() != "https://")
            {
                try
                {
                    webDriver.Navigate().GoToUrl(vURL);
                }
                catch (Exception ex)
                {
                    if (!vURL.StartsWith("https://"))
                    {
                        webDriver.Navigate().GoToUrl("https://" + vURL);
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
        }
Exemplo n.º 8
0
        private void ExecuteScript(bool dataIsFile)
        {
            try
            {
                _currentStatus = EngineStatus.Running;

                //create stopwatch for metrics tracking
                _stopWatch = new Stopwatch();
                _stopWatch.Start();

                //log starting
                ReportProgress("Bot Engine Started: " + DateTime.Now.ToString());

                //get automation script
                Script automationScript;
                if (dataIsFile)
                {
                    ReportProgress("Deserializing File");
                    Log.Information("Script Path: " + AutomationEngineContext.FilePath);
                    FileName         = AutomationEngineContext.FilePath;
                    automationScript = Script.DeserializeFile(AutomationEngineContext);
                }
                else
                {
                    ReportProgress("Deserializing JSON");
                    automationScript = Script.DeserializeJsonString(AutomationEngineContext.FilePath);
                }

                ReportProgress("Creating Variable List");

                //set variables if they were passed in
                if (AutomationEngineContext.Variables != null)
                {
                    foreach (var var in AutomationEngineContext.Variables)
                    {
                        var variableFound = automationScript.Variables.Where(f => f.VariableName == var.VariableName).FirstOrDefault();

                        if (variableFound != null)
                        {
                            variableFound.VariableValue = var.VariableValue;
                        }
                    }
                }

                AutomationEngineContext.Variables = automationScript.Variables;

                //update ProjectPath variable
                var projectPathVariable = AutomationEngineContext.Variables.Where(v => v.VariableName == "ProjectPath").SingleOrDefault();
                if (projectPathVariable != null)
                {
                    projectPathVariable.VariableValue = AutomationEngineContext.ProjectPath;
                }
                else
                {
                    projectPathVariable = new ScriptVariable
                    {
                        VariableName  = "ProjectPath",
                        VariableType  = typeof(string),
                        VariableValue = AutomationEngineContext.ProjectPath
                    };
                    AutomationEngineContext.Variables.Add(projectPathVariable);
                }

                ReportProgress("Creating Argument List");

                //set arguments if they were passed in
                if (AutomationEngineContext.Arguments != null)
                {
                    foreach (var arg in AutomationEngineContext.Arguments)
                    {
                        var argumentFound = automationScript.Arguments.Where(f => f.ArgumentName == arg.ArgumentName).FirstOrDefault();

                        if (argumentFound != null)
                        {
                            argumentFound.ArgumentValue = arg.ArgumentValue;
                        }
                    }
                }

                AutomationEngineContext.Arguments = automationScript.Arguments;

                ReportProgress("Creating Element List");

                //set elements if they were passed in
                if (AutomationEngineContext.Elements != null)
                {
                    foreach (var elem in AutomationEngineContext.Elements)
                    {
                        var elementFound = automationScript.Elements.Where(f => f.ElementName == elem.ElementName).FirstOrDefault();

                        if (elementFound != null)
                        {
                            elementFound.ElementValue = elem.ElementValue;
                        }
                    }
                }

                AutomationEngineContext.Elements = automationScript.Elements;

                ReportProgress("Creating App Instance Tracking List");
                //create app instances and merge in global instances
                if (AutomationEngineContext.AppInstances == null)
                {
                    AutomationEngineContext.AppInstances = new Dictionary <string, object>();
                }
                var GlobalInstances = GlobalAppInstances.GetInstances();
                foreach (var instance in GlobalInstances)
                {
                    AutomationEngineContext.AppInstances[instance.Key] = instance.Value;
                }

                //execute commands
                ScriptAction startCommand = automationScript.Commands.Where(x => x.ScriptCommand.LineNumber <= AutomationEngineContext.StartFromLineNumber)
                                            .Last();

                int startCommandIndex = automationScript.Commands.FindIndex(x => x.ScriptCommand.LineNumber == startCommand.ScriptCommand.LineNumber);

                while (startCommandIndex < automationScript.Commands.Count)
                {
                    if (IsCancellationPending)
                    {
                        ReportProgress("Cancelling Script");
                        ScriptFinished(ScriptFinishedResult.Cancelled);
                        return;
                    }

                    ExecuteCommand(automationScript.Commands[startCommandIndex]);
                    startCommandIndex++;
                }

                if (IsCancellationPending)
                {
                    //mark cancelled - handles when cancelling and user defines 1 parent command or else it will show successful
                    ScriptFinished(ScriptFinishedResult.Cancelled);
                }
                else
                {
                    //mark finished
                    ScriptFinished(ScriptFinishedResult.Successful);
                }
            }
            catch (Exception ex)
            {
                ScriptFinished(ScriptFinishedResult.Error, ex.ToString());
            }
            if ((AutomationEngineContext.ScriptEngine != null && !AutomationEngineContext.ScriptEngine.IsChildEngine) || (IsServerExecution && !IsServerChildExecution))
            {
                AutomationEngineContext.EngineLogger.Dispose();
            }
        }
        private void ExecuteScript(string data, bool dataIsFile, string projectPath)
        {
            try
            {
                _currentStatus = EngineStatus.Running;

                //create stopwatch for metrics tracking
                _stopWatch = new Stopwatch();
                _stopWatch.Start();

                //log starting
                ReportProgress("Bot Engine Started: " + DateTime.Now.ToString());

                //get automation script
                Script automationScript;
                if (dataIsFile)
                {
                    ReportProgress("Deserializing File");
                    Log.Information("Script Path: " + data);
                    FileName         = data;
                    automationScript = Script.DeserializeFile(data);
                }
                else
                {
                    ReportProgress("Deserializing JSON");
                    automationScript = Script.DeserializeJsonString(data);
                }

                //track variables and app instances
                ReportProgress("Creating Variable List");

                //set variables if they were passed in
                if (VariableList != null)
                {
                    foreach (var var in VariableList)
                    {
                        var variableFound = automationScript.Variables.Where(f => f.VariableName == var.VariableName).FirstOrDefault();

                        if (variableFound != null)
                        {
                            variableFound.VariableValue = var.VariableValue;
                        }
                    }
                }

                VariableList = automationScript.Variables;

                //update ProjectPath variable
                var projectPathVariable = VariableList.Where(v => v.VariableName == "ProjectPath").SingleOrDefault();
                if (projectPathVariable != null)
                {
                    projectPathVariable.VariableValue = projectPath;
                }
                else
                {
                    projectPathVariable = new ScriptVariable
                    {
                        VariableName  = "ProjectPath",
                        VariableValue = projectPath
                    };
                    VariableList.Add(projectPathVariable);
                }

                //track elements
                ReportProgress("Creating Element List");

                //set elements if they were passed in
                if (ElementList != null)
                {
                    foreach (var elem in ElementList)
                    {
                        var elementFound = automationScript.Elements.Where(f => f.ElementName == elem.ElementName).FirstOrDefault();

                        if (elementFound != null)
                        {
                            elementFound.ElementValue = elem.ElementValue;
                        }
                    }
                }

                ElementList = automationScript.Elements;

                ReportProgress("Creating App Instance Tracking List");
                //create app instances and merge in global instances
                AppInstances = new Dictionary <string, object>();
                var GlobalInstances = GlobalAppInstances.GetInstances();
                foreach (var instance in GlobalInstances)
                {
                    AppInstances.Add(instance.Key, instance.Value);
                }

                //execute commands
                foreach (var executionCommand in automationScript.Commands)
                {
                    if (IsCancellationPending)
                    {
                        ReportProgress("Cancelling Script");
                        ScriptFinished(ScriptFinishedResult.Cancelled);
                        return;
                    }

                    ExecuteCommand(executionCommand);
                }

                if (IsCancellationPending)
                {
                    //mark cancelled - handles when cancelling and user defines 1 parent command or else it will show successful
                    ScriptFinished(ScriptFinishedResult.Cancelled);
                }
                else
                {
                    //mark finished
                    ScriptFinished(ScriptFinishedResult.Successful);
                }
            }
            catch (Exception ex)
            {
                ScriptFinished(ScriptFinishedResult.Error, ex.ToString());
            }
        }