예제 #1
0
        public string SaveAs(string sPath, int[,] iRange)
        {
            Stream      stream      = this.GetStream();
            LoadOptions loadOptions = new Aspose.Cells.LoadOptions(LoadFormat.Html);
            Workbook    workbook    = new Workbook(stream, loadOptions);
            Style       style       = SetStyle(workbook);
            Worksheet   worksheet   = workbook.Worksheets[0];
            Range       range       = worksheet.Cells.CreateRange(iRange[0, 0], iRange[0, 1], iRange[1, 0], iRange[1, 1]);

            range.SetStyle(style);
            workbook.Save(sPath, new XlsSaveOptions(SaveFormat.Excel97To2003));
            stream.Close();
            return(sPath);
        }
        public static bool FindTextInExcellFile(string fileFullPath, string text, ref CancellationTokenSource cts)
        {
            try
            {
                LoadOptions loadOptions = null;
                switch (new FileInfo(fileFullPath).Extension.ToLower())
                {
                case ".xls":
                    loadOptions = new LoadOptions(LoadFormat.Excel97To2003);
                    break;

                case ".xlsx":
                    loadOptions = new LoadOptions(LoadFormat.Xlsx);
                    break;
                }

                var wbExcel2007 = new Workbook(fileFullPath, loadOptions);
                foreach (var sheet in wbExcel2007.Worksheets)
                {
                    if (cts.IsCancellationRequested)
                    {
                        break;
                    }

                    foreach (Cell cell in sheet.Cells)
                    {
                        if (cts.IsCancellationRequested)
                        {
                            break;
                        }

                        if (cell.StringValue.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0)
                        {
                            return(true);
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(false);
            }

            return(false);
        }
예제 #3
0
        public void RunTest(String TestType)
        {
            try
            {
                Logger.createLogFile();
                ActualStartTime    = DateTime.Now.ToString("hh:mm:ss tt", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                CurrentProjectPath = ResultSheet.CurrentProjectPath();
                OutputfilePath     = ResultSheet.ResultFilePath_Name();
                Email_Outlook.sendEMailThroughOUTLOOK();
                ResultSheet.CreateExcelReport(OutputfilePath);
                BrowserDriverPath = CurrentProjectPath + "Mercer.US.Ben.Automation" + Path.DirectorySeparatorChar + "BrowserDrivers";

                switch (TestType)
                {
                case "Smoke":
                    ResourcePath = CurrentProjectPath + "Mercer.US.Ben.Automation" + Path.DirectorySeparatorChar + "Resources" + Path.DirectorySeparatorChar + "Smoke";
                    Logger.info("Framing Smoke test Rresource path :" + ResourcePath);
                    break;

                case "Regression":
                    ResourcePath = CurrentProjectPath + "Mercer.US.Ben.Automation" + Path.DirectorySeparatorChar + "Resources" + Path.DirectorySeparatorChar + "Regression";
                    Logger.info("Framing Regression test Resource path :" + ResourcePath);
                    break;
                }
                fileName = ResourcePath + Path.DirectorySeparatorChar + "MODULES.xlsx";
                Logger.info("Module sheet path is :" + fileName);

                //  ModuleList for loading various module names
                List <string> ModuleList  = new List <string>();
                List <string> BrowserType = new List <string>();
                {
                    //open Modules Excel sheet
                    Logger.info("Following Excel sheet loaded successfuly " + fileName);
                    FileStream MasterExcel = new FileStream(fileName, FileMode.Open);
                    Aspose.Cells.LoadOptions loadOptions = new Aspose.Cells.LoadOptions(LoadFormat.Xlsx);
                    Workbook  wb = new Workbook(MasterExcel, loadOptions);
                    Worksheet ws = wb.Worksheets[0];

                    // Number of Rows in Module Sheet
                    Row_count = ws.Cells.Rows.Count;
                    Logger.info("Total number of Modules listed in the modul execution sheet" + Row_count);

                    for (int i = 1; (i <= Row_count); i++)
                    {
                        if (((ws.Cells[i, 0]).StringValue).Equals("Y"))
                        {
                            //Getting Module names
                            string strModuleName = (ws.Cells[i, 1]).StringValue;
                            //strBrowserName = ;
                            BrowserType.Add(((ws.Cells[i, 2]).StringValue));
                            Logger.info("Selected Browser name is : " + ((ws.Cells[i, 2]).StringValue));
                            Logger.info("Currently loadding module is : " + strModuleName);
                            ModuleList.Add(strModuleName);
                        }
                    }
                }



                //For loop for Executing Various selected Modules
                for (int h = 0; h <= (ModuleList.Count) - 1; h++)
                {
                    Sheet_Name = ModuleList[h];
                    string strCurrentDataSheetName = ResourcePath + Path.DirectorySeparatorChar + ModuleList[h] + ".xlsx";
                    Logger.info("The following test data sheet loaded successfuly" + strCurrentDataSheetName);

                    List <string> Scenario_List            = new List <string>();
                    List <string> ScenarioDescription_List = new List <string>();
                    {
                        FileStream ModuleExcel = new FileStream(strCurrentDataSheetName, FileMode.Open);
                        Aspose.Cells.LoadOptions loadOptions_1 = new Aspose.Cells.LoadOptions(LoadFormat.Xlsx);
                        Workbook  wb_1 = new Workbook(ModuleExcel, loadOptions_1);
                        Worksheet ws_1 = wb_1.Worksheets[0];

                        int Row_count_1 = ws_1.Cells.Rows.Count;
                        Logger.info(" Total number of scenarios to be executed as per Test Data sheet" + Row_count_1);



                        //Loop for getting Scenario Names with Y
                        for (int a = 1; (a <= Row_count_1); a++)
                        {
                            if (((ws_1.Cells[a, 0]).StringValue).Equals("Y"))
                            {
                                Scenario_List.Add((ws_1.Cells[a, 1]).StringValue);
                                Logger.info("Current executable Scenario name :" + ((ws_1.Cells[a, 1]).StringValue));

                                ScenarioDescription_List.Add((ws_1.Cells[a, 2]).StringValue);
                                Logger.info("The Scenario Description is:" + ((ws_1.Cells[a, 2]).StringValue));
                            }
                        }

                        // for loop for  Iterating over Various Scenarios
                        for (int s = 0; s <= (Scenario_List.Count) - 1; s++)
                        {
                            String value = Scenario_List[s];
                            Scinario_Name = ScenarioDescription_List[s];
                            Logger.info("Navigating to sheet and taking function name into Function_Name_List  : " + value);

                            // start the Browser invoke code
                            //For opening Browser
                            Logger.info("Launching Browser window");

                            //Get the browser type to be executed
                            //browserconfig > Object containing browsersettings.config file values
                            XDocument browserconfig = XDocument.Load(CurrentProjectPath + "Mercer.Us.Ben.Automation" + Path.DirectorySeparatorChar + "BrowserSettings.config");
                            Browser_Type = browserconfig.Root.Element("BrowserSelection").Element("Browser").Attribute("Type").Value;

                            if (Browser_Type == null || Browser_Type == "")
                            {
                                Browser_Type = "InternetExplorer";
                                Logger.info("Default Browser Setting is not set in BrowserSettingConfig file so its taking Firefox as default browser");
                            }

                            if (BrowserType[h] != null || BrowserType[h] != "")
                            {
                                Browser_Type = BrowserType[h];
                            }

                            Logger.info("Current Module is execuing agains Browser as :" + Browser_Type);
                            switch (Browser_Type)
                            {
                            case "Firefox":

                                BrowserName = "Firefox";
                                //Attempt to start Firefox. Tries consumer Firefox first, then attempts ESR version.
                                FirefoxBinary  binary  = new FirefoxBinary(browserconfig.Root.Element("BrowserDriver").Element("Firefox").Attribute("Path").Value);
                                FirefoxProfile profile = new FirefoxProfile();

                                driver = new FirefoxDriver(binary, profile);
                                ICapabilities cap         = ((RemoteWebDriver)driver).Capabilities;
                                String        browserName = cap.BrowserName.ToString();
                                Console.WriteLine("*************" + browserName);
                                string version = cap.Version.ToString();
                                Console.WriteLine("*************" + version);

                                Logger.info("FireFox driver is loaded");
                                break;

                            case "InternetExplorer":
                                //driver = new InternetExplorerDriver(BrowserDriverPath);
                                //Logger.info("IE driver is selected");
                                BrowserName = "IE";
                                var options = new InternetExplorerOptions()
                                {
                                    EnsureCleanSession = Convert.ToBoolean(browserconfig.Root.Element("BrowserDriver")
                                                                           .Element("InternetExplorer").Attribute("EnsureCleanSession").Value),
                                    InitialBrowserUrl = browserconfig.Root.Element("BrowserDriver")
                                                        .Element("InternetExplorer").Attribute("InitialBrowserUrl").Value,
                                    IntroduceInstabilityByIgnoringProtectedModeSettings = Convert.ToBoolean(browserconfig.Root
                                                                                                            .Element("BrowserDriver").Element("InternetExplorer").Attribute("IgnoreProtectedMode").Value)
                                };
                                //Optional for Driver path---> browserconfig.Root.Element("BrowserDriver").Element("InternetExplorer").Attribute("Path").Value
                                driver = new InternetExplorerDriver(BrowserDriverPath, options);
                                Logger.info("IE driver is loaded");
                                break;

                            case "Chrome":
                                BrowserName = "Chrome";
                                Logger.info("Chrome driver is selected");
                                break;
                            }

                            //Navigating to sheet and taking function name into Function_Name_List
                            Worksheet worksheet = wb_1.Worksheets[value];
                            {
                                int Row_count_2 = worksheet.Cells.Rows.Count;
                                Logger.info("Getting row count of Test methods to be executed sheet: " + Row_count_2);

                                int col_Count_2 = worksheet.Cells.Columns.Count;
                                Logger.info("Getting column count of Test methods to be executed sheet: " + col_Count_2);

                                for (int j = 1; (j <= Row_count_2); j++)
                                {
                                    if (((worksheet.Cells[j, 0]).StringValue).Equals("Y"))
                                    {
                                        //Getting functionm names for getting test data
                                        //for Clearing the values of Dictionary for Each iteration
                                        values.Clear();
                                        FunctionName = (worksheet.Cells[j, 2]).StringValue;
                                        values.Add("Function_Name_Value", FunctionName);
                                        Logger.info("Current executing function name is : " + FunctionName);
                                        string ClassName = (worksheet.Cells[j, 1]).StringValue;
                                        values.Add("Class_Name", ClassName);
                                        Logger.info("Current executing class name is : " + ClassName);
                                        TestDescription = (worksheet.Cells[j, 3]).StringValue;
                                        Logger.info("Test scenario description is : " + TestDescription);

                                        for (int k = 7; k <= col_Count_2; k++)
                                        {
                                            string Test_Value = (worksheet.Cells[j, k]).StringValue;
                                            string Test_Data  = (worksheet.Cells[j + 1, k]).StringValue;

                                            if (Test_Value == null || Test_Value == "")
                                            {
                                                Logger.info("Getting out from the scenario test data collection list");
                                                break;
                                            }
                                            values.Add(Test_Value, Test_Data);
                                            Logger.info("The Parameter Name is : " + Test_Value + " and value is : " + Test_Data);
                                            string Exit_Test_Value = (worksheet.Cells[j, k + 1]).StringValue;
                                            if (Exit_Test_Value == null || Exit_Test_Value == "")
                                            {
                                                Logger.info("Getting out from the scenario execution list");
                                                break;
                                            }
                                        }
                                        // end Browser invoke code

                                        string ClassNameValue = values["Class_Name"];
                                        string MethodName     = values["Function_Name_Value"];

                                        Logger.info("the name of the class  : " + ClassNameValue);
                                        Logger.info("the name of the Function or Method Name  : " + MethodName);

                                        string TypeName = "Mercer.Us.Ben.Automation.Test_Methods.MBC." + ClassNameValue;
                                        Type   type     = Type.GetType(TypeName);
                                        //    ConstructorInfo ctor = type.GetConstructor(new[] { typeof(IWebDriver) });
                                        //    object instance = ctor.Invoke(new object[] { driver });
                                        object          classInstance = Activator.CreateInstance(type, null);
                                        MethodInfo      methodInfo    = type.GetMethod(MethodName);
                                        ParameterInfo[] parameters    = methodInfo.GetParameters();

                                        //Navigate to Method  //Reflection
                                        //result = (string)methodInfo.Invoke(instance, null);
                                        // methodInfo.Invoke(instance, null);
                                        Starttime = DateTime.Now.ToString("hh:mm:ss tt", System.Globalization.DateTimeFormatInfo.InvariantInfo);

                                        methodInfo.Invoke(classInstance, null);
                                        if (Constants.ApplicationLaunchFlag == false)
                                        {
                                            driver.Close();
                                            break;
                                        }
                                        Logger.info(" Status of the current execution");
                                    }
                                    j++;//loop increment for row
                                }
                            }
                        }
                        driver.Quit();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Test.Result("Page should be loaded", " Waiting for page load/Failed to page load", "Failed");
                Logger.error(e);
            }
            finally
            {
                ResultSheet.DesignChart(OutputfilePath, Passed, Failed, ActualStartTime, BrowserName);
                Email_Outlook.send_Report_EMailThroughOUTLOOK();
                Console.WriteLine("Test Execution is Completed");
            }
        }