Ejemplo n.º 1
0
        /// <summary>
        /// Executes Test Cases
        /// </summary>
        public void Execute(Dictionary <String, String> browserConfig,
                            String testCaseId,
                            String iterationId,
                            Report.Iteration iteration,
                            Dictionary <String, String> testData,
                            Report.Engine reportEngine)
        {
            try
            {
                this.Driver     = Util.GetDriver(browserConfig);
                this.Reporter   = iteration;
                this.TestCaseId = testCaseId;
                this.TestDataId = iterationId;
                this.TestData   = testData;

                if (browserConfig["target"] == "local")
                {
                    var wmi = new ManagementObjectSearcher("select * from Win32_OperatingSystem").Get().Cast <ManagementObject>().First();

                    this.Reporter.Browser.PlatformName    = String.Format("{0} {1}", ((string)wmi["Caption"]).Trim(), (string)wmi["OSArchitecture"]);
                    this.Reporter.Browser.PlatformVersion = ((string)wmi["Version"]);
                    this.Reporter.Browser.BrowserName     = Driver.Capabilities.BrowserName;
                    this.Reporter.Browser.BrowserVersion  = Driver.Capabilities.Version;
                }
                else
                {
                    this.Reporter.Browser.PlatformName    = browserConfig.ContainsKey("os") ? browserConfig["os"] : browserConfig["device"];
                    this.Reporter.Browser.PlatformVersion = browserConfig.ContainsKey("os_version") ? browserConfig["os_version"] : browserConfig.ContainsKey("realMobile") ? "Real" : "Emulator";
                    this.Reporter.Browser.BrowserName     = browserConfig.ContainsKey("browser") ? browserConfig["browser"] : "Safari";
                    this.Reporter.Browser.BrowserVersion  = browserConfig.ContainsKey("browser_version") ? browserConfig["browser_version"] : "";
                }

                // By now, I get all needed stuff
                // Let Page get reference to Driver, Reporter
                //PrepareSeed();
//Extent Experimental
                // Does Seed having anything?
                if (this.Reporter.Chapter.Steps.Count == 0)
                {
                    this.Reporter.Chapters.RemoveAt(0);
                }
                this.Reporter.StartTime = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local, TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"));
                ExecuteTestCase();
            }
            catch (Exception ex)
            {
                this.Reporter.Chapter.Step.Action.IsSuccess = false;
                //reportEngine.Extent.Add(new Report.ExtentReport {TestCaseId = testCaseId , PublishedReportPath = String.Format("{0} {1} {2}.html", iteration.Browser.TestCase.Title, iteration.Browser.Title, iteration.Title)});
                reportEngine.MetTelExceptions.Add(new Report.ExceptionReport {
                    ExceptionDetails = ex, PublishedReportPath = String.Format("{0} {1} {2}.html", iteration.Browser.TestCase.Title, iteration.Browser.Title, iteration.Title), TestCaseId = testCaseId
                });
                this.Reporter.Chapter.Step.Action.Extra = "Exception Message :<font color=red>" + ex.Message + "</font><br/>" + ex.InnerException + ex.StackTrace;
            }
            finally
            {
                try
                {
                    this.Reporter.IsCompleted = true;

                    // If current iteration is a failure, get screenshot
                    if (!Reporter.IsSuccess)
                    {
                        ITakesScreenshot iTakeScreenshot = Driver;
                        this.Reporter.Screenshot = iTakeScreenshot.GetScreenshot().AsBase64EncodedString;
                    }
                    else
                    {
                        ITakesScreenshot iTakeScreenshot = Driver;
                        this.Reporter.Screenshot = iTakeScreenshot.GetScreenshot().AsBase64EncodedString;
                    }
                    this.Reporter.EndTime = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local, TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"));

                    lock (reportEngine)
                    {
                        reportEngine.PublishIteration(this.Reporter);
                        reportEngine.PublishExtent(this.Reporter);
                        reportEngine.Summarize(false);
                    }


                    Driver.Quit();
                }
                catch (Exception e)
                {
                    //throw new Exception("Exception is : " + e);
                    //ITakesScreenshot iTakeScreenshot = Driver;
                    //this.Reporter.Screenshot = iTakeScreenshot.GetScreenshot().AsBase64EncodedString;
                    this.Reporter.EndTime = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local, TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"));
                    reportEngine.Extent.Add(new Report.ExtentReport {
                        TestCaseId = testCaseId, PublishedReportPath = String.Format("{0} {1} {2}.html", iteration.Browser.TestCase.Title, iteration.Browser.Title, iteration.Title)
                    });
                    lock (reportEngine)
                    {
                        reportEngine.PublishIteration(this.Reporter);
                        reportEngine.PublishExtent(this.Reporter);
                        reportEngine.Summarize(false);
                    }
                    Driver.Quit();
                }
            }
        }