Ejemplo n.º 1
0
        public override void Execute(ReportInfo RI)
        {
            try
            {
                ActScript act      = new ActScript();
                string    FileName = ScriptFileName.Replace(@"~\", SolutionFolder);
                if (string.IsNullOrEmpty(SolutionFolder))
                {
                    Errors = "Script path not provided.";
                    Status = eRunSetActionStatus.Failed;
                    return;
                }
                if (!System.IO.File.Exists(FileName))
                {
                    Errors = "File Not found: " + FileName;
                    Status = eRunSetActionStatus.Failed;
                    return;
                }

                act.ScriptName            = FileName;
                act.ScriptInterpreterType = ActScript.eScriptInterpreterType.VBS;
                act.Execute();
                this.Errors = act.Error;
            }
            catch (Exception ex)
            {
                Errors = ex.Message.ToString();
                Status = eRunSetActionStatus.Failed;
            }
        }
Ejemplo n.º 2
0
        public void BASHFileArgTest()
        {
            if (isOSWindows)
            {
                return;
            }
            //Arrange
            ActScript actScript = new ActScript()
            {
                ScriptName    = "BASHWithArgs.sh",
                ScriptCommand = ActScript.eScriptAct.Script
            };

            actScript.AddOrUpdateInputParamValueAndCalculatedValue("v1", "Shell");
            actScript.AddOrUpdateInputParamValueAndCalculatedValue("v2", "You");
            actScript.ScriptInterpreterType = ActScript.eScriptInterpreterType.SH;
            actScript.ScriptPath            = TestResources.GetTestResourcesFolder(@"Files");
            actScript.AddNewReturnParams    = true;

            //Act
            actScript.Execute();

            //Assert
            Assert.AreEqual(actScript.ReturnValues.Count, 2);
            Assert.AreEqual(string.Join(',', actScript.ActReturnValues.Select(x => x.Param).ToList()), "Value,Thanks");
            Assert.AreEqual(string.Join(',', actScript.ActReturnValues.Select(x => x.Actual).ToList()), "Shell,You");
        }
Ejemplo n.º 3
0
        public void VBSSum2ArgsTest()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }
            //Arrange
            ActScript actScript = new ActScript()
            {
                ScriptName    = "VBSSum2Args.vbs",
                ScriptCommand = ActScript.eScriptAct.Script
            };

            actScript.AddOrUpdateInputParamValueAndCalculatedValue("Var1", "56");
            actScript.AddOrUpdateInputParamValueAndCalculatedValue("Var2", "77");
            actScript.ScriptInterpreterType = ActScript.eScriptInterpreterType.VBS;
            actScript.ScriptPath            = TestResources.GetTestResourcesFolder(@"Files");
            actScript.AddNewReturnParams    = true;

            //Act
            actScript.Execute();

            //Assert
            Assert.AreEqual(actScript.ReturnValues.Count, 3);
            Assert.AreEqual(string.Join(',', actScript.ActReturnValues.Select(x => x.Param).ToList()), "Var1,Var2,sum");
            Assert.AreEqual(string.Join(',', actScript.ActReturnValues.Select(x => x.Actual).ToList()), "56,77,133");
        }
Ejemplo n.º 4
0
        public override string GetCommandText(ActScript act)
        {
            string cmd = "";

            switch (act.ScriptCommand)
            {
            case ActScript.eScriptAct.FreeCommand:
                return(act.GetInputParamCalculatedValue("p1"));

            case ActScript.eScriptAct.Script:
            {
                foreach (var p in act.InputValues)
                {
                    if (!string.IsNullOrEmpty(p.Value))
                    {
                        cmd += " " + p.ValueForDriver;
                    }
                }
                return(cmd);
            }

            default:
                Reporter.ToUser(eUserMsgKey.UnknownConsoleCommand, act.ScriptCommand);
                return("Error - unknown command");
            }
        }
Ejemplo n.º 5
0
        public void RunScriptAPlusB()
        {
            // Arrange
            ActScript v = new ActScript();

            v.ScriptInterpreterType = ActScript.eScriptInterpreterType.VBS;
            v.AddNewReturnParams    = true;
            v.ScriptCommand         = ActScript.eScriptAct.Script;
            v.AddOrUpdateInputParamCalculatedValue("p1", "5");
            v.AddOrUpdateInputParamCalculatedValue("p2", "7");

            v.ScriptName = "APlusB.vbs";
            v.ScriptPath = TestResources.GetTestResourcesFolder("");

            //Act
            v.Execute();

            //Assert
            Assert.AreEqual(v.Error, null);
            Assert.AreEqual(v.ReturnValues[0].Param, "TXT");
            Assert.AreEqual(v.ReturnValues[0].Actual, "5 + 7 = 12");

            Assert.AreEqual(v.ReturnValues[1].Param, "Total");
            Assert.AreEqual(v.ReturnValues[1].Actual, "12");
        }
Ejemplo n.º 6
0
        public void RunScriptAPlusBBAT()
        {
            if (!isOSWindows)
            {
                return;
            }
            // Arrange
            ActScript v = new ActScript();

            v.ScriptInterpreterType = ActScript.eScriptInterpreterType.BAT;
            v.AddNewReturnParams    = true;
            v.ScriptCommand         = ActScript.eScriptAct.Script;
            v.AddOrUpdateInputParamCalculatedValue("p1", "5");
            v.AddOrUpdateInputParamCalculatedValue("p2", "7");

            v.ScriptName = "BatchScriptWithArgs.bat";
            v.ScriptPath = TestResources.GetTestResourcesFolder("Files");

            //Act
            v.Execute();

            //Assert
            Assert.AreEqual(v.Error, null);

            Assert.AreEqual(v.ReturnValues[0].Param, "Result");
            Assert.AreEqual(v.ReturnValues[0].Actual, "12");
        }
Ejemplo n.º 7
0
        public void BATFile1ArgTest()
        {
            if (!isOSWindows)
            {
                return;
            }
            //Arrange
            ActScript actScript = new ActScript()
            {
                ScriptName    = "BATReturnParam.bat",
                ScriptCommand = ActScript.eScriptAct.Script
            };

            actScript.AddOrUpdateInputParamValueAndCalculatedValue("Param", "BatFile");
            actScript.ScriptInterpreterType = ActScript.eScriptInterpreterType.BAT;
            actScript.ScriptPath            = TestResources.GetTestResourcesFolder(@"Files");
            actScript.AddNewReturnParams    = true;

            //Act
            actScript.Execute();

            //Assert
            Assert.AreEqual(actScript.ReturnValues.Count, 2);
            Assert.AreEqual(string.Join(',', actScript.ActReturnValues.Select(x => x.Param).ToList()), "Hello ,Arg ");
            Assert.AreEqual(string.Join(',', actScript.ActReturnValues.Select(x => x.Actual).ToList()), " hello world, BatFile");
        }
Ejemplo n.º 8
0
        public void ResetActionList()
        {
            a1.Acts.Clear();

            ActWebAPISoap actWebAPISoap = new ActWebAPISoap();

            actWebAPISoap.ItemName = "Action1";
            actWebAPISoap.ActInputValues.Add(new Amdocs.Ginger.Repository.ActInputValue()
            {
                Param = ActWebAPIBase.Fields.EndPointURL, Value = "bla bli bla VTFInsideList bla bla bla"
            });
            actWebAPISoap.ActReturnValues.Add(new Amdocs.Ginger.Repository.ActReturnValue()
            {
                Param = "ReturnValue1", Expected = "I expect you to VTFInsideList behave"
            });
            actWebAPISoap.Active = true;
            a1.Acts.Add(actWebAPISoap);

            ActClearAllVariables actClearAllVariables = new ActClearAllVariables();

            actClearAllVariables.ItemName     = "Action2";
            actClearAllVariables.VariableName = "My Variable is VTFStringField";
            a1.Acts.Add(actClearAllVariables);

            ActScript actScript = new ActScript();

            actScript.ItemName      = "Action3";
            actScript.ScriptCommand = ActScript.eScriptAct.FreeCommand;
            actScript.Wait          = 13132424;
            a1.Acts.Add(actScript);

            mApplicationAPIModels.Clear();

            ApplicationAPIModel applicationAPIModel = new ApplicationAPIModel();

            applicationAPIModel.APIType     = ApplicationAPIUtils.eWebApiType.SOAP;
            applicationAPIModel.EndpointURL = "VTF";
            applicationAPIModel.DoNotFailActionOnBadRespose = true;
            applicationAPIModel.AppModelParameters.Add(new AppModelParameter()
            {
                PlaceHolder = "VTF", Path = "VTF/Path/Path/Path", OptionalValuesList = new ObservableList <OptionalValue>()
                {
                    new OptionalValue()
                    {
                        Value = "VTF1"
                    }, new OptionalValue()
                    {
                        Value = "VTF2"
                    }
                }
            });
            applicationAPIModel.HttpHeaders.Add(new APIModelKeyValue()
            {
                Param = "Content-Type", Value = "Applicaiton/VTF"
            });
            mApplicationAPIModels.Add(applicationAPIModel);
        }
Ejemplo n.º 9
0
        public void FreeCommand()
        {
            ActScript v = new ActScript();

            v.ScriptInterpreterType = ActScript.eScriptInterpreterType.VBS;
            v.ScriptCommand         = ActScript.eScriptAct.FreeCommand;
            v.AddOrUpdateInputParamValue("Free Command", "Wscript.echo \"Hello\"");

            v.Execute();

            //Assert.AreEqual(v.ReturnValues[0].Actual, "5");
        }
Ejemplo n.º 10
0
        public void ExecuteActScriptAction(string ScriptFileName, string SolutionFolder)
        {
            //TODO: Remove from here and execute it in actual RunSetActionScript.cs (Not perticularly tested)
            ActScript act      = new ActScript();
            string    FileName = ScriptFileName.Replace(@"~\", SolutionFolder);

            Ginger.Run.RunSetActions.RunSetActionScript actionScript = new RunSetActionScript();
            actionScript.VerifySolutionFloder(SolutionFolder, FileName);

            act.ScriptName            = FileName;
            act.ScriptInterpreterType = ActScript.eScriptInterpreterType.VBS;
            act.Execute();
            //this.Errors = act.Error;
        }
Ejemplo n.º 11
0
        public void FreeCommandVBS()
        {
            ActScript v = new ActScript();

            v.ScriptInterpreterType = ActScript.eScriptInterpreterType.VBS;
            v.ScriptCommand         = ActScript.eScriptAct.FreeCommand;
            v.AddNewReturnParams    = true;
            v.AddOrUpdateInputParamCalculatedValue("Free Command", "NumberB=10\r\nNumberA=20\r\nDim Result\r\nResult= int(NumberA) + int(NumberB)\r\nWscript.Echo \"Add=\" & Result");

            v.Execute();

            Assert.AreEqual(v.Error, null);
            Assert.AreEqual(v.ReturnValues[0].Actual.Contains("Add=30"), true);
        }
Ejemplo n.º 12
0
        //public string GenerateReportForREportTemplate(string ReportTemplateName, object RIf, object RTs )
        //{
        //    ReportInfo RI = (ReportInfo)RIf;
        //    ReportTemplate RT = (ReportTemplate)RTs;
        //    ReportPage RP = new ReportPage(RI, RT.Xaml);
        //    string FileName = Path.GetTempPath() + ReportTemplateName + ".rtf";

        //    if (System.IO.File.Exists(FileName))
        //        FileName = Path.GetTempPath() + " " + DateTime.Now.ToString("dMMMyyyy_HHmmss_fff") + "_" + ReportTemplateName + ".rtf";

        //    GC.Collect();
        //    RP.SaveReport(FileName);

        //    string PDFFileName = FileName.Replace(".rtf", ".pdf");

        //    RTFtoPDF.Convert(FileName, PDFFileName);

        //    return PDFFileName;
        //}

        public void ExecuteActScriptAction(string ScriptFileName, string SolutionFolder)
        {
            //TODO: Remove from here and execute it in actual RunSetActionScript.cs (Not perticularly tested)
            ActScript act = new ActScript();
            //string FileName = ScriptFileName.Replace(@"~\", SolutionFolder);
            string FileName = amdocs.ginger.GingerCoreNET.WorkSpace.Instance.SolutionRepository.ConvertSolutionRelativePath(ScriptFileName);

            Ginger.Run.RunSetActions.RunSetActionScript actionScript = new RunSetActionScript();
            actionScript.VerifySolutionFloder(SolutionFolder, FileName);

            act.ScriptName            = FileName;
            act.ScriptInterpreterType = ActScript.eScriptInterpreterType.VBS;
            act.Execute();
            //this.Errors = act.Error;
        }
Ejemplo n.º 13
0
        [TestMethod]  //[Timeout(60000)]
        public void FreeCommandBAT()
        {
            // Arrange
            ActScript v = new ActScript();

            v.ScriptInterpreterType = ActScript.eScriptInterpreterType.BAT;
            v.ScriptCommand         = ActScript.eScriptAct.FreeCommand;
            v.AddNewReturnParams    = true;
            v.AddOrUpdateInputParamCalculatedValue("Free Command", "@echo off \r\nSET /A a = 5 \r\nSET /A b = 10 \r\nSET /A c = %a% + %b% \r\necho Add=%c% ");

            //Act
            v.Execute();

            //Assert
            Assert.AreEqual(v.Error, null);
            Assert.AreEqual(v.ReturnValues[0].Actual.Contains("Add=15"), true);
        }
Ejemplo n.º 14
0
 public void Execute(IReportInfo RI)
 {
     try
     {
         ActScript act      = new ActScript();
         string    FileName = WorkSpace.Instance.Solution.SolutionOperations.ConvertSolutionRelativePath(RunSetActionScript.ScriptFileName);
         VerifySolutionFloder(RunSetActionScript.SolutionFolder, FileName);
         act.ScriptName            = FileName;
         act.ScriptInterpreterType = (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
             ? ActScript.eScriptInterpreterType.VBS : ActScript.eScriptInterpreterType.SH;
         act.Execute();
     }
     catch (Exception ex)
     {
         RunSetActionScript.Errors = ex.Message.ToString();
         RunSetActionScript.Status = eRunSetActionStatus.Failed;
     }
 }
Ejemplo n.º 15
0
        public void ActScriptTestWithIndexZero()
        {
            //Arrange
            ActScript actScript = new ActScript();

            actScript.ScriptInterpreter  = ActScript.eScriptInterpreterType.VBS.ToString();
            actScript.ScriptCommand      = ActScript.eScriptAct.Script;
            actScript.ScriptName         = TestResources.GetTestResourcesFile(@"Script\ScriptWithGingerOutputIndexZero.vbs");
            actScript.Active             = true;
            actScript.AddNewReturnParams = true;

            //Act
            mGR.RunAction(actScript);

            //Assert
            Assert.AreEqual(eRunStatus.Passed, actScript.Status, "Action Status");
            Assert.AreEqual(2, actScript.ReturnValues.Count);
            Assert.AreEqual("OK", actScript.ReturnValues[0].Actual);
        }
        public ActScriptEditPage(GingerCore.Actions.ActScript Act)
        {
            InitializeComponent();
            this.f = Act;
            GingerCore.General.FillComboFromEnumObj(ScriptActComboBox, Act.ScriptCommand);
            GingerCore.General.FillComboFromEnumObj(ScriptInterpreterComboBox, Act.ScriptInterpreterType);

            GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(ScriptInterpreterComboBox, ComboBox.SelectedValueProperty, Act, nameof(ActScript.ScriptInterpreterType));
            GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(ScriptActComboBox, ComboBox.SelectedValueProperty, Act, nameof(ActScript.ScriptCommand));
            GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(ScriptNameComboBox, ComboBox.SelectedValueProperty, Act, nameof(ActScript.ScriptName));

            ScriptNameComboBox.SelectionChanged += ScriptNameComboBox_SelectionChanged;

            ScriptInterPreter.FileExtensions.Add(".exe");
            ScriptInterPreter.Init(Act, nameof(ActScript.ScriptInterpreter), true);
            f.ScriptPath = SHFilesPath;

            var comboEnumItem = ScriptInterpreterComboBox.Items.Cast <GingerCore.GeneralLib.ComboEnumItem>().Where(x => x.text == ActScript.eScriptInterpreterType.JS.ToString()).FirstOrDefault();

            ScriptInterpreterComboBox.Items.Remove(comboEnumItem);//Removed JS from UI
        }
Ejemplo n.º 17
0
        public static string ExecuteVBSEval(string Expr)
        {
            //Create temp vbs file
            string fileName = "";

            try
            {
                fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".vbs";
            }catch (Exception)
            {
                //this to overcome speical IT settings which doesn't allow local personal folders
                fileName = "" + Environment.GetFolderPath(Environment.SpecialFolder.InternetCache) + @"\" + Guid.NewGuid().ToString() + ".vbs" + "";
            }
            string s = "Dim v" + Environment.NewLine;

            s += "v=" + Expr.Replace("\r\n", "vbCrLf").Replace("\n", "vbCrLf").Replace("\r", "vbCrLf") + Environment.NewLine;
            s += "Wscript.echo v" + Environment.NewLine;
            System.IO.File.WriteAllText(fileName, s);
            //Execute
            ActScript scr = new ActScript();

            scr.AddNewReturnParams = true;
            scr.ScriptCommand      = ActScript.eScriptAct.Script;
            scr.ScriptName         = fileName;

            scr.Execute();

            //Delete the temp vbs file
            System.IO.File.Delete(fileName);

            //Return the result
            string result = scr.ReturnValues[0].Actual;

            if (result != null)
            {
                result = result.Trim();
            }

            return(result);
        }
Ejemplo n.º 18
0
        public void ActScriptTestWithoutOutput()
        {
            if (!isOSWindows)
            {
                return;
            }
            //with index=-1
            //Arrange
            ActScript actScript = new ActScript();

            actScript.ScriptInterpreter  = ActScript.eScriptInterpreterType.VBS.ToString();
            actScript.ScriptCommand      = ActScript.eScriptAct.Script;
            actScript.ScriptName         = TestResources.GetTestResourcesFile(Path.Combine(@"Files", @"ScriptWithoutOutput.vbs"));
            actScript.Active             = true;
            actScript.AddNewReturnParams = true;

            //Act
            mGR.RunAction(actScript);

            //Assert
            Assert.AreEqual(eRunStatus.Passed, actScript.Status, "Action Status");
            Assert.AreEqual(1, actScript.ReturnValues.Count);
            Assert.AreEqual("\n\nHello\nSNO=1\n\n", actScript.ReturnValues[0].Actual);
        }
Ejemplo n.º 19
0
        public override void RunAction(Act act)
        {
            //TODO: add func to Act + Enum for switch
            string actClass = act.GetType().ToString();

            //TODO: avoid hard coded string...
            actClass = actClass.Replace("GingerCore.Actions.", "");
            switch (actClass)
            {
            case "ActVBScript":
                ActScript ACC = (ActScript)act;
                mActVBS = (ActScript)act;
                string command = GetCommandText(ACC);
                act.ExInfo = command;
                if (command.StartsWith("GINGER_RC="))
                {
                    //This is FTP command and we already have the result
                    act.AddOrUpdateReturnParamActual("GINGER_RC", command.Replace("GINGER_RC=", ""));
                }
                else
                {
                    string sRC = "";
                    //Send the command via driver
                    if (ACC.ScriptCommand == ActScript.eScriptAct.Script)
                    {
                        //TODO: externalize static const for ~~~GINGER_RC_END~~~ and all hard coded multi use strings
                        sRC = RunScript(command);
                    }
                    else
                    {
                        sRC = RunScript(command);
                    }
                    sRC = sRC.Replace("\r", "");
                    string[] RCValues = sRC.Split('\n');
                    foreach (string RCValue in RCValues)
                    {
                        if (RCValue.Length > 0)     // Ignore empty lines
                        {
                            string Param;
                            string Value;
                            int    i = RCValue.IndexOf('=');
                            if (i > 0)
                            {
                                Param = RCValue.Substring(0, i);
                                //the rest is the value
                                Value = RCValue.Substring(Param.Length + 1);
                            }
                            else
                            {
                                // in case of bad RC not per Ginger style we show it as "?" with value
                                Param = "???";
                                Value = RCValue;
                            }
                            act.AddOrUpdateReturnParamActual(Param, Value);
                        }
                    }
                }
                break;

            default:
                throw new Exception("Action unknown/not implemented for the Driver: " + this.GetType().ToString());
            }
        }
Ejemplo n.º 20
0
 // Get the action command to be send to the specific derived driver
 public abstract string GetCommandText(ActScript act);