コード例 #1
0
        public void ProcessCodeLine(string CodeLine)
        {
            ConvertedCodeLine CCL = new ConvertedCodeLine();

            CCL.CodeLine = CodeLine;
            CCL.Status   = ConvertedCodeLine.eStatus.Unknown;
            CodeLine     = CodeLine.Trim();
            string CodeLineUpper = CodeLine.ToUpper();

            if (CodeLine.StartsWith("'"))
            {
                // do nothing this is comment
                CCL.Converted = "' Comment";
                CCL.Status    = ConvertedCodeLine.eStatus.Ignored;
            }
            else if (CodeLine.Length == 0)
            {
                // do nothing this is empty line
                CCL.Converted = "Empty Line";
                CCL.Status    = ConvertedCodeLine.eStatus.Ignored;
            }
            else if (CodeLineUpper == "END IF" || CodeLineUpper == "ELSE" || CodeLineUpper == "END FUNCTION" || CodeLineUpper == "EXIT FUNCTION" || CodeLineUpper == "END SUB")
            {
                // do nothing
                CCL.Converted = "Ignored (End if/Else/End Function/Sub)";
                CCL.Status    = ConvertedCodeLine.eStatus.Ignored;
            }
            else
            {
                ProcessActions(CCL);
                mCCL.Add(CCL);
            }
        }
コード例 #2
0
        private int FetchBusPosition(string[] BusCodeLines)
        {
            int    pos = 0;
            string BusLineUpper;

            foreach (string BusLine in BusCodeLines)
            {
                pos++;
                ConvertedCodeLine BusCCL = new ConvertedCodeLine();
                BusLineUpper = BusLine.ToUpper();
                if (BusLineUpper.Contains("FUNCTION") || BusLineUpper.Contains("SUB"))
                {
                    return(pos);
                }
            }
            return(pos);
        }
コード例 #3
0
        private void ProcessScript()
        {
            string line;

            System.IO.StreamReader file = new System.IO.StreamReader(ScriptFileTextBox.Text);

            while ((line = file.ReadLine()) != null)
            {
                if ((line.StartsWith("Function") || line.StartsWith("Sub")) || (line.StartsWith("Public") || line.StartsWith("Private")))
                {
                    string fName = ProcessNewFunction(line);

                    //if Gui Function is Like fGuiLogin()
                    if (fName.Contains("()"))
                    {
                        fName = fName.Replace("()", "");
                    }
                    //If Gui function has input params like fGuiLogin(UserName,Pwd)
                    if (fName.Contains("("))
                    {
                        int    pos       = fName.IndexOf("(");
                        int    len       = fName.Length;
                        string midString = fName.Substring(pos);
                        fName = fName.Replace(midString, "");
                    }

                    if (ListOfSelectedGuis.Contains(fName))
                    {
                        ConvertedCodeLine CL = new ConvertedCodeLine();
                        CL.CodeLine = line;
                        CreateActivity(fName, CL);
                        while (!line.Contains("End Function") || line.Contains("End Sub"))
                        {
                            ProcessCodeLine(line);
                            line = file.ReadLine().ToString();
                        }
                    }
                }
            }
            ResultsDataGrid.DataSourceList = mCCL;
        }
コード例 #4
0
        //Create Activity for each function/Sub identified in script
        void CreateActivity(string ActivityName, ConvertedCodeLine CCL)
        {
            //Create a New Activity with the Function/Sub Name
            Activity a = new Activity();

            a.Description = GingerDicser.GetTermResValue(eTermResKey.Activity) + " Created for " + ActivityName + " function ";
            if (ActivityName.Contains("fGui"))
            {
                ActivityName = ActivityName.Replace("fGui", "");
            }
            if (ActivityName.Contains("_"))
            {
                ActivityName = ActivityName.Replace("_", " ");
            }

            ActivityName = Regex.Replace(ActivityName, "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", "$1 ");

            a.ActivityName = ActivityName;
            mBusinessFlow.Activities.Add(a);
            mBusinessFlow.CurrentActivity = a;
            CCL.Converted = "New Activity - " + ActivityName;
            CCL.Status    = ConvertedCodeLine.eStatus.ConvertedToScript;
        }
コード例 #5
0
        private void ProcessActions(ConvertedCodeLine CCL)
        {
            string CodeLine         = CCL.CodeLine;
            string value            = "";
            string SetValueinObject = "";
            string varName          = "";
            string xpath            = "";
            string type             = "";

            if (CodeLine.Contains("WebEdit"))
            {
                if (CodeLine.Contains("WebEditTxtChange"))
                {
                    type             = "Edit Box";
                    SetValueinObject = GetStringBetween(CodeLine, ".WebEdit(\"", "\")");

                    varName = CodeLine.Substring(CodeLine.IndexOf("GlobalDictionary")).Replace("GlobalDictionary", "").Trim();
                    varName = varName.Replace("(", "").Replace(")", "");
                    value   = "{Var Name=" + varName + "}";

                    //Calling function to identify Locate By and Locate Value
                    xpath = ProcessLocateBy_Value(SetValueinObject);
                }

                // Add Action to biz flow
                ActGenElement act = new ActGenElement();
                act.Value            = value.Replace("\"", "").Replace("\"", "");
                act.GenElementAction = ActGenElement.eGenElementAction.SetValue;
                act.LocateBy         = eLocateBy.ByXPath;
                act.LocateValue      = xpath;
                act.Description      = "Set value in " + SetValueinObject + " " + type;
                mBusinessFlow.AddAct(act);
                CCL.Converted = "New Action - ActGenElement.SetValue : LocateValue=" + act.LocateValue + ", Value=" + act.Value;
                CCL.Status    = ConvertedCodeLine.eStatus.ConvertedToScript;
            }

            // Extract the WebEdit/WebCheckBox
            else if (CodeLine.Contains(".Set") || CodeLine.Contains(".set"))
            {
                if (CodeLine.Contains("WebEdit"))
                {
                    type             = "Edit Box";
                    SetValueinObject = GetStringBetween(CodeLine, ".WebEdit(\"", "\")");

                    //Calling function to identify Locate By and Locate Value
                    xpath = ProcessLocateBy_Value(SetValueinObject);
                }
                else if (CodeLine.Contains("WebCheckBox"))
                {
                    type             = "Check Box";
                    SetValueinObject = GetStringBetween(CodeLine, ".WebCheckBox(\"", "\")");

                    //Calling function to identify Locate By and Locate Value
                    xpath = ProcessLocateBy_Value(SetValueinObject);
                }

                // for Values to Set
                if (CodeLine.Contains("Set \""))  // For hard coded values
                {
                    value = GetStringBetween(CodeLine, "Set \"", CodeLine[CodeLine.Length - 1].ToString());
                }
                else if (CodeLine.Contains("GlobalDictionary"))
                {
                    varName = CodeLine.Substring(CodeLine.IndexOf("GlobalDictionary")).Replace("GlobalDictionary", "").Trim();
                    varName = varName.Replace("(", "").Replace(")", "");
                    value   = "{Var Name=" + varName + "}";
                }
                else if (CodeLine.Contains("Globaldictionary"))
                {
                    varName = CodeLine.Substring(CodeLine.IndexOf("Globaldictionary")).Replace("Globaldictionary", "").Trim();
                    varName = varName.Replace("(", "").Replace(")", "");
                    value   = "{Var Name=" + varName + "}";
                }
                else if (!CodeLine.Contains("GlobalDictionary") && !CodeLine.Contains("Globaldictionary"))  // for variables declared using Dim
                {
                    varName = CodeLine.Substring(CodeLine.IndexOf("Set")).Replace("Set", "").Trim();
                    value   = "{Var Name=" + varName + "}";
                    VariableString v = new VariableString();
                    v.Description = GingerDicser.GetTermResValue(eTermResKey.Variable) + " added by UFT Script";
                    v.Name        = varName;
                    v.Value       = value;
                    mBusinessFlow.AddVariable(v);
                }

                // Add Action to biz flow
                ActGenElement act = new ActGenElement();
                act.Value            = value.Replace("\"", "").Replace("\"", "");
                act.GenElementAction = ActGenElement.eGenElementAction.SetValue;
                act.LocateBy         = eLocateBy.ByXPath;
                act.LocateValue      = xpath;
                act.Description      = "Set value in " + SetValueinObject + " " + type;
                mBusinessFlow.AddAct(act);
                CCL.Converted = "New Action - ActGenElement.SetValue : LocateValue=" + act.LocateValue + ", Value=" + act.Value;
                CCL.Status    = ConvertedCodeLine.eStatus.ConvertedToScript;
            }

            // Extract the WebButton/Link/Image/WebELemnt
            else if (CodeLine.Contains(".Click") || CodeLine.Contains(".click"))
            {
                if (CodeLine.Contains("WebButton"))
                {
                    type             = "Button";
                    SetValueinObject = GetStringBetween(CodeLine, ".WebButton(\"", "\")");

                    //Calling function to identify Locate By and Locate Value
                    xpath = ProcessLocateBy_Value(SetValueinObject);
                }
                else if (CodeLine.Contains("Link"))
                {
                    type             = "Link";
                    SetValueinObject = GetStringBetween(CodeLine, ".Link(\"", "\")");

                    //Calling function to identify Locate By and Locate Value
                    xpath = ProcessLocateBy_Value(SetValueinObject);
                }
                else if (CodeLine.Contains("WebElement"))
                {
                    type             = "Web Element";
                    SetValueinObject = GetStringBetween(CodeLine, ".WebElement(\"", "\")");

                    //Calling function to identify Locate By and Locate Value
                    xpath = ProcessLocateBy_Value(SetValueinObject);
                }
                else if (CodeLine.Contains("Image"))
                {
                    type             = "Image";
                    SetValueinObject = GetStringBetween(CodeLine, ".Image(\"", "\")");

                    //Calling function to identify Locate By and Locate Value
                    xpath = ProcessLocateBy_Value(SetValueinObject);
                }

                // Add Action to biz flow
                ActGenElement act = new ActGenElement();
                act.Value            = "";
                act.LocateBy         = eLocateBy.ByXPath;
                act.LocateValue      = xpath;
                act.GenElementAction = ActGenElement.eGenElementAction.Click;
                act.Description      = "Click on " + SetValueinObject + " " + type;
                mBusinessFlow.AddAct(act);

                CCL.Converted = "New Action - ActGenElement.Click : LocateValue=" + act.LocateValue; // +", Value=" + act.Value;
                CCL.Status    = ConvertedCodeLine.eStatus.ConvertedToScript;
            }

            // Extract the WeBlist/WebRadiogroup
            else if (CodeLine.Contains(".Select") || CodeLine.Contains(".select"))
            {
                if (CodeLine.Contains("WebList"))
                {
                    type             = "List";
                    SetValueinObject = GetStringBetween(CodeLine, ".WebList(\"", "\")");

                    //Calling function to identify Locate By and Locate Value
                    xpath = ProcessLocateBy_Value(SetValueinObject);
                }
                else if (CodeLine.Contains("WebRadiogroup"))
                {
                    type             = "Radio Group";
                    SetValueinObject = GetStringBetween(CodeLine, ".WebRadiogroup(\"", "\")");

                    //Calling function to identify Locate By and Locate Value
                    xpath = ProcessLocateBy_Value(SetValueinObject);
                }

                //For Values to Set
                if (CodeLine.Contains("Select \""))  // For hard coded values
                {
                    value = GetStringBetween(CodeLine, "Select \"", CodeLine[CodeLine.Length - 1].ToString());
                }
                else if (CodeLine.Contains("GlobalDictionary"))
                {
                    varName = CodeLine.Substring(CodeLine.IndexOf("GlobalDictionary")).Replace("GlobalDictionary", "").Trim();
                    varName = varName.Replace("(", "").Replace(")", "");
                    value   = "{Var Name=" + varName + "}";
                }
                else if (CodeLine.Contains("Globaldictionary"))
                {
                    varName = CodeLine.Substring(CodeLine.IndexOf("Globaldictionary")).Replace("Globaldictionary", "").Trim();
                    varName = varName.Replace("(", "").Replace(")", "");
                    value   = "{Var Name=" + varName + "}";
                }
                else
                {
                    varName = CodeLine.Substring(CodeLine.IndexOf("Select ")).Replace("Select ", "").Trim();
                    value   = "{Var Name=" + varName + "}";
                    VariableString v = new VariableString();
                    v.Description = GingerDicser.GetTermResValue(eTermResKey.Variable) + " added by UFT Script";
                    v.Name        = varName;
                    v.Value       = value;
                    mBusinessFlow.AddVariable(v);
                }

                // Add Action to biz flow
                ActGenElement act = new ActGenElement();
                act.Value            = value;
                act.LocateBy         = eLocateBy.ByXPath;
                act.LocateValue      = xpath;
                act.GenElementAction = ActGenElement.eGenElementAction.SetValue;
                act.Description      = "Select value from " + SetValueinObject + " " + type;
                mBusinessFlow.AddAct(act);
                CCL.Converted = "New Action - ActGenElement.SetValue : LocateValue=" + act.LocateValue + ", Value=" + act.Value;
                CCL.Status    = ConvertedCodeLine.eStatus.ConvertedToScript;
            }

            // Extract the URL to Navigate to
            else if (CodeLine.Contains("Navigate"))
            {
                // Extract the URL
                string URL = GetStringBetween(CodeLine, ".Navigate(\"", "\")");

                // Add Action to biz flow
                ActGotoURL act = new ActGotoURL();
                act.Value       = URL;
                act.Description = "Navigate to URL";
                mBusinessFlow.AddAct(act);
                CCL.Converted = "New Action - ActGotoURL : " + URL;
                CCL.Status    = ConvertedCodeLine.eStatus.ConvertedToScript;
            }

            // Extract the URL launched using SystemUtil.Run
            else if (CodeLine.Contains("SystemUtil.Run") && CodeLine.Contains("iexplore.exe"))
            {
                // Extract the URL
                string URL = GetStringBetween(CodeLine, "iexplore.exe\",\"", "\"");

                // Add Action to biz flow
                ActGotoURL act = new ActGotoURL();
                act.Value       = URL;
                act.Description = "Navigate to URL";
                mBusinessFlow.AddAct(act);
                CCL.Converted = "New Action - ActGotoURL : " + URL;
                CCL.Status    = ConvertedCodeLine.eStatus.ConvertedToScript;
            }
            else if (CodeLine.Contains("fDBCheck") || CodeLine.Contains("fDBActivities")) //ASAP function
            {
                // Temp until we read the SQL from common.xls
                ActDBValidation act = new ActDBValidation();
                act.Description = "DB Action-Configure Manually";
                mBusinessFlow.AddAct(act);
                CCL.Converted = "New Action - DB Action ";
                CCL.Status    = ConvertedCodeLine.eStatus.ConvertedToScript;
            }
        }
コード例 #6
0
        public void ConvertButton_Click(object sender, RoutedEventArgs e)
        {
            //Extract Objects from XML repository
            ProcessUFTObjectRepository();

            mBusinessFlow.Activities = new ObservableList <Activity>();

            if (ListOfSelectedGuis.Count != 0)
            {
                //Identify actions from Script
                ProcessScript();
            }
            else //if BUS function does not contain any GUI functions, process BUS function to see if any Actions can be retrieved
            {
                //Create an Activity with the BUS function Name
                ConvertedCodeLine Bus = new ConvertedCodeLine();
                CreateActivity("MyTestActivity", Bus);

                int    Pos          = 0;
                string BusLineUpper = "";

                //Fetch the Entire BUS script
                string[] BusCodeLines = System.IO.File.ReadAllLines(ScriptFileTextBox.Text);

                //Fetch the position of Bus function the BUS script
                Pos = FetchBusPosition(BusCodeLines);
                if (Pos != 0)
                {
                    //Loop through the Specific bus Function
                    // force the position to be at 1
                    Pos = 0;
                    for (int i = Pos; i < BusCodeLines.Count(); i++)
                    {
                        BusLineUpper = BusCodeLines[i].ToUpper();
                        ConvertedCodeLine BusCCL = new ConvertedCodeLine();
                        BusCCL.CodeLine = BusCodeLines[i];
                        ProcessCodeLine_QTP(BusCCL);
                    }
                }
            }

            //Auto Check all the cgk box for Guis
            if (mCCL != null)
            {
                for (int i = 0; i < mCCL.Count; i++)
                {
                    mCCL[i].Checked = true;
                }

                ResultsDataGrid.Title = "Converted Code Line Status";

                //to Show only Converted Script as default
                FilterComboBox.SelectedValue = "ConvertedtoScript";
                IEnumerable <ConvertedCodeLine>    FilterdCCLs;
                ObservableList <ConvertedCodeLine> CCLs = new ObservableList <ConvertedCodeLine>();
                FilterdCCLs = from x in mCCL where x.Status == ConvertedCodeLine.eStatus.ConvertedToScript select x;

                foreach (ConvertedCodeLine CCL in FilterdCCLs)
                {
                    CCLs.Add(CCL);
                }

                ResultsDataGrid.DataSourceList = CCLs;
                ResultsDataGrid.Refresh();
            }

            //Show script conversion status
            ShowStats();

            //Create Variables for each of the Parameter in the selected flow
            CreateVariables();
        }