Ejemplo n.º 1
0
        public override StringBuilder Convert(string fullFileName = "")
        {
            //_HACK safe to delete
            #region ---TEST ONLY: Compiler will  automatically erase this in RELEASE mode and it will not run if Global.GlobalTestMode is not set to TestMode.Simulation
#if OVERRIDE || DEBUG
            System.Diagnostics.Debug.WriteLine("HACK-TEST -Convert");

            if (string.IsNullOrEmpty(fullFileName))
            {
                fullFileName = DefaultSourceFolder + "test.xml";
            }
#endif
            #endregion //////////////END TEST

            string xml      = File.ReadAllText(fullFileName);
            var    catalog1 = xml.ParseXML <TestCase>();

            string myScript = string.Empty;
            //get first
            var sel = catalog1;//.FirstOrDefault();

            MyActions = new List <CodeceptAction>();
            var length = sel.selenese.Count();
            for (int i = 0; i < length; i++)
            {
                var t = sel.selenese[i];
                Console.WriteLine(string.Format("{0}  {1}  {2}", t.command, t.target, t.value));

                var script = Codecept.Script(t, this);

                myScript += script;

                //create codeceptActions
                CodeceptAction action = new CodeceptAction
                {
                    target  = t.target,
                    command = t.command,
                    value   = t.value,
                    Script  = script.Trim(),
                    OrderNo = i
                };
                MyActions.Add(action);
            }//end for

            //LogApplication.Agent.LogInfo(myScript);
            System.Diagnostics.Debug.WriteLine(Environment.NewLine + myScript);
            StringBuilder result = new StringBuilder();
            return(result);
        }
Ejemplo n.º 2
0
        public StringBuilder ReadJsonTestFile(string fullFileName = "")
        {
            MyActions = new List <CodeceptAction>();
            string json = File.ReadAllText(fullFileName);

            string[] split  = json.Split(new string[] { "Scenario(" }, StringSplitOptions.None);
            var      target = split[1];

            string[] splitByLine = target.Split('\n');
            var      length      = splitByLine.Count();

            string myScript = string.Empty;

            for (int i = 0; i < length; i++)
            {
                string line = splitByLine[i].Trim();
                if (line.StartsWith("I."))
                {
                    var myLine = line.Substring(2);
                    myScript += myLine;

                    //create codeceptActions
                    CodeceptAction action = new CodeceptAction
                    {
                        Script  = myLine.Trim(),
                        OrderNo = i
                    };
                    MyActions.Add(action);
                }
                else if (line.Trim() == "});")
                {
                    break;
                }
            }

            //LogApplication.Agent.LogInfo(myScript);
            Console.WriteLine(Environment.NewLine + myScript);
            StringBuilder result = new StringBuilder(myScript);

            return(result);
        }
Ejemplo n.º 3
0
        public override StringBuilder ReadXmlFile(string fullFileName = "")
        {
            try
            {
                //Load default??
                #region ---if null file found...


                Console.WriteLine("HACK-TEST -Convert");

                if (string.IsNullOrEmpty(fullFileName))
                {
                    fullFileName = DefaultSourceFolder + "test.xml";
                }


                #endregion //////////////END TEST

                string xml      = File.ReadAllText(fullFileName);
                var    catalog1 = xml.ParseXML <TestCase>();

                string myScript = string.Empty;
                //get first
                var sel = catalog1;//.FirstOrDefault();

                MyActions = new List <CodeceptAction>();
                var length = sel.selenese.Count();
                for (int i = 0; i < length; i++)
                {
                    var t = sel.selenese[i];
                    Console.WriteLine(string.Format("{0}  {1}  {2}", t.command, t.target, t.value));

                    var script = Codecept.Script(t, this);

                    myScript += script;

                    //create codeceptActions
                    CodeceptAction action = new CodeceptAction
                    {
                        target  = t.target,
                        command = t.command,
                        value   = t.value,
                        Script  = script.Trim(),
                        OrderNo = i
                    };
                    MyActions.Add(action);
                }//end for

                //LogApplication.Agent.LogInfo(myScript);
                Console.WriteLine(Environment.NewLine + myScript);
                StringBuilder result = new StringBuilder();
                return(result);
            }
            catch (Exception err)
            {
                LogApplication.Agent.LogError(err);
                // throw;
            }

            //error or null
            return(new StringBuilder());
        }
Ejemplo n.º 4
0
        public StringBuilder InsertVariables(string fullFileName, Dictionary <string, string> variables)
        {
            string json = File.ReadAllText(fullFileName);

            string[] split  = json.Split(new string[] { "Scenario(" }, StringSplitOptions.None);
            var      target = split[1];

            string[] splitByLine = target.Split('\n');
            var      length      = splitByLine.Count();

            string myScript = string.Empty;

            for (int i = 0; i < length; i++)
            {
                string line = splitByLine[i].Trim();
                if (line.StartsWith("I."))
                {
                    var myLine = line;//;.Substring(2);

                    //create psuedo codeceptActions dont save this
                    CodeceptAction thisAction = new CodeceptAction
                    {
                        Script  = myLine.Trim(),
                        OrderNo = i
                    };

                    //cross check database variables ex script delimitter:  'var input_1_1 ='
                    foreach (var dic in variables)
                    {
                        //TIP: SPLIT
                        string   delimitter  = string.Format("var {0} =", dic.Key);
                        string[] splitScript = thisAction.Script.Split(new string[] { delimitter }, StringSplitOptions.None);

                        if (splitScript.Length > 1)
                        {
                            var leftPart = splitScript[1];

                            //change value .. " '*****@*****.**';"    I.waitForElement('[id="inputEmail1"]',45);I.retry({ retries: 3, maxTimeout: 3000 }).fillField({id:'inputEmail1'}, input_1_1);I.wait(1);'
                            //string[] splitScript2 = leftPart.Split(';');
                            var leftPart2 = leftPart.Substring(0, leftPart.IndexOf(';')); //splitScript2[1];//" '*****@*****.**'"

                            var delimitter2 = delimitter + leftPart2;                     //var input_1_1 = '*****@*****.**'

                            string[] splitScript2 = thisAction.Script.Split(new string[] { delimitter2 }, StringSplitOptions.None);

                            //var origScript = splitScript2[0] + delimitter2 + splitScript2[1];
                            var newExpresson = string.Format("var {0} = '{1}'", dic.Key, dic.Value);

                            var newScript = splitScript2[0] + newExpresson + splitScript2[1];

                            myLine = newScript;
                        }
                    }
                    myScript += myLine;
                }
                else if (line.Trim() == "});")
                {
                    break;
                }
            }

            //reinsert from template..
            ConfigManager config               = new ConfigManager();
            var           codeCeptConfigPath   = config.GetValue("CodeceptTestTemplate");
            var           codeCeptTestTemplate = File.ReadAllText(codeCeptConfigPath);

            codeCeptTestTemplate = codeCeptTestTemplate.Replace("##steps##", myScript);

            //LogApplication.Agent.LogInfo(myScript);
            Console.WriteLine(Environment.NewLine + myScript);
            StringBuilder result = new StringBuilder(codeCeptTestTemplate);

            return(result);
        }