コード例 #1
0
            public SingleAssert(string ele, string exp, string act, string op, params string[] takescreenshot)
            {
                element  = ele.Trim().ToLower();
                expected = exp.Trim().ToLower();
                actual   = act.Trim().ToLower();

                if (op.ToLower().Equals("equals"))
                {
                    Failed = !(actual.Equals(expected));
                }
                else if (op.ToLower().Equals("contains"))
                {
                    Failed = !(actual.Contains(expected));
                }

                if (Failed == true)
                {
                    string report_msg = element + " Expected : " + expected + " , Actual : " + actual;
                    log.Info("Failed Message : " + report_msg);
                    ExtentTestManager.GetTest().Log(Status.Fail, report_msg);
                    //take screenshot is use for api and will not take screen shot when test fail, api test pass value 'yes'
                    if (takescreenshot.Length == 0)
                    {
                        screenshotpath = util.TakeScreenshot(driver);
                        Console.WriteLine("Path : " + screenshotpath);
                        ExtentTestManager.GetTest().Log(Status.Fail, "Screenshot: \n", MediaEntityBuilder.CreateScreenCaptureFromPath(screenshotpath).Build());
                    }
                    //ExtentTestManager.GetTest().Log(Status.Fail, MarkupHelper.CreateLabel(TestContext.CurrentContext.Test.Name + " :: " + Status.Fail, ExtentColor.Red));
                }
                else if (Failed == false)
                {
                    Report.Pass("Element Name: " + element + " Expected :" + expected + " Actual :" + actual);
                }
            }
コード例 #2
0
        private void PrintReport()
        {
            string imgpath;

            var    status     = TestContext.CurrentContext.Result.Outcome.Status;
            var    stacktrace = TestContext.CurrentContext.Result.StackTrace;
            var    message    = TestContext.CurrentContext.Result.Message;
            Status logstatus;

            if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
            {
                logstatus = Status.Fail; // red cross sign before test step
                Console.WriteLine("Message : " + TestContext.CurrentContext.Result.Message);
                log.Error(TestContext.CurrentContext.Test.MethodName + " Test case fail");
                ExtentTestManager.GetTest().Log(logstatus, stacktrace + "\n" + message);
                if (is_soft_assert == false)
                {
                    if (ConfigurationManager.AppSettings["TestStatScrnshot"].ToLower() == "failed" || ConfigurationManager.AppSettings["TestStatScrnshot"].ToLower() == "both")
                    {
                        imgpath = util.TakeScreenshot(driver);
                        log.Info("Screenshot taken for failed test case : " + imgpath);
                        ExtentTestManager.GetTest().Log(logstatus, "Screenshot: \n", MediaEntityBuilder.CreateScreenCaptureFromPath(imgpath).Build());
                    }
                }
                ExtentTestManager.GetTest().Log(logstatus, MarkupHelper.CreateLabel(TestContext.CurrentContext.Test.Name + " :: " + logstatus, ExtentColor.Red));
                util.WriteToFile(TestContext.CurrentContext.Test.FullName);
            }
            else if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Passed)
            {
                logstatus = Status.Pass;
                log.Info(TestContext.CurrentContext.Test.Name + "  Test case pass");
                if (is_soft_assert == false)
                {
                    if (ConfigurationManager.AppSettings["TestStatScrnshot"].ToLower() == "passed" || ConfigurationManager.AppSettings["TestStatScrnshot"].ToLower() == "both")
                    {
                        imgpath = util.TakeScreenshot(driver);
                        log.Info("Screenshot taken for failed test case : " + imgpath);
                        ExtentTestManager.GetTest().Log(logstatus, "Screenshot: \n", MediaEntityBuilder.CreateScreenCaptureFromPath(imgpath).Build());
                    }
                }
                ExtentTestManager.GetTest().Log(logstatus, MarkupHelper.CreateLabel(TestContext.CurrentContext.Test.Name + " :: " + logstatus, ExtentColor.Green));
            }
            else if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Warning)
            {
                logstatus = Status.Warning;
                log.Warning(TestContext.CurrentContext.Test.MethodName + " Test case warn");
                ExtentTestManager.GetTest().Log(logstatus, message);
                ExtentTestManager.GetTest().Log(logstatus, MarkupHelper.CreateLabel(TestContext.CurrentContext.Test.Name + " :: " + logstatus, ExtentColor.Orange));
            }
            else if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Skipped)
            {
                logstatus = Status.Skip;
                log.Info(TestContext.CurrentContext.Test.MethodName + " Test case skip");
                ExtentTestManager.GetTest().Log(logstatus, message);
                ExtentTestManager.GetTest().Log(logstatus, MarkupHelper.CreateLabel(TestContext.CurrentContext.Test.Name + " :: " + logstatus, ExtentColor.Blue));
            }
        }
コード例 #3
0
        public void OneTimeSetUp()
        {
            GlobalVariables globalVariables = new GlobalVariables();

            //initialize the global variables
            globalVariables.InitializeGlobalVariables();

            ExtentTestManager.CreateParentTest(GetType().Name + " (" + GlobalVariables.clientname + ")");
            log.Info("Parent Test created in Test report ");
        }
コード例 #4
0
        public void OneTimeSetUp()
        {
            GlobalVariables globalVariables = new GlobalVariables();

            //initialize the global variables
            globalVariables.InitializeGlobalVariables();
            if (ConfigurationManager.AppSettings["setvideorecording"].ToLower().Equals("true"))
            {
                string pth         = System.Reflection.Assembly.GetCallingAssembly().CodeBase;
                string actualpath  = pth.Substring(0, pth.LastIndexOf("bin"));
                string projectpath = new Uri(actualpath).LocalPath;
                string videopath   = projectpath + ConfigurationManager.AppSettings["recordingpath"];
                System.IO.Directory.CreateDirectory(videopath);
                string videoname = ConfigurationManager.AppSettings["application"] + "_" + GlobalVariables.environment + DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.ToString("HHmmss");
                rec = new VideoRecorder(new RecorderParams(videopath + videoname, 5, SharpAvi.KnownFourCCs.Codecs.MotionJpeg, 40));
                //DirectoryInfo dinfo = new DirectoryInfo(videopath);
                //long sizeofdirectory = DirSize(dinfo);
                //Console.WriteLine(sizeofdirectory);
                //if (sizeofdirectory / 1024 >= 2000)
                //    File.Delete();
            }

            //Create driver
            driver = DriverFactory.InitDriver(ConfigurationManager.AppSettings["platform"], GlobalVariables.browser, GlobalVariables.webdriverhost, GlobalVariables.webdriverport);

            if (driver != null)
            {
                ExtentTestManager.CreateParentTest(GetType().Name);
                log.Info("Parent Test created in Test report ");
                wait = new WebDriverWait(driver, TimeSpan.FromSeconds(120));
                if (GlobalVariables.platform.ToLower() == "win")
                {
                    driver.Manage().Window.Maximize();
                    //driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60);
                    driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(70);

                    DriverFactory.LoadApplication(driver);
                    log.Info("Driver loaded and Application launch");
                }
            }
            else
            {
                Console.WriteLine("Driver Not initialized");
                log.Error("Driver is not loaded");
            }
        }
コード例 #5
0
        public void SetUp()
        {
            is_soft_assert = false;
            softassertions = new SoftAssertions();
            ExtentTestManager.CreateTest(TestContext.CurrentContext.Test.Name);

            var categories = TestContext.CurrentContext.Test.Properties["Category"];

            foreach (var category in categories)
            {
                TestContext.WriteLine("Category: " + category);
                ExtentTestManager.GetTest().AssignCategory(category.ToString());
                log.Info("Category: " + category);
            }
            log.Info("Created node in report with Test case name");
            log.Info("Test case execution start  : " + TestContext.CurrentContext.Test.Name);
        }
コード例 #6
0
        private void PrintReport()
        {
            var    status     = TestContext.CurrentContext.Result.Outcome.Status;
            var    stacktrace = TestContext.CurrentContext.Result.StackTrace;
            var    message    = TestContext.CurrentContext.Result.Message;
            Status logstatus;

            if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
            {
                logstatus = Status.Fail; // red cross sign before test step
                Console.WriteLine("Message : " + TestContext.CurrentContext.Result.Message);
                log.Error(TestContext.CurrentContext.Test.MethodName + " Test case fail");
                ExtentTestManager.GetTest().Log(logstatus, stacktrace + "\n" + message);

                ExtentTestManager.GetTest().Log(logstatus, MarkupHelper.CreateLabel(TestContext.CurrentContext.Test.Name + " :: " + logstatus, ExtentColor.Red));
                util.WriteToFile(TestContext.CurrentContext.Test.FullName);
            }
            else if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Passed)
            {
                logstatus = Status.Pass;
                log.Info(TestContext.CurrentContext.Test.Name + "  Test case pass");
                ExtentTestManager.GetTest().Log(logstatus, MarkupHelper.CreateLabel(TestContext.CurrentContext.Test.Name + " :: " + logstatus, ExtentColor.Green));
            }
            else if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Warning)
            {
                logstatus = Status.Warning;
                log.Warning(TestContext.CurrentContext.Test.MethodName + " Test case warn");
                ExtentTestManager.GetTest().Log(logstatus, message);
                ExtentTestManager.GetTest().Log(logstatus, MarkupHelper.CreateLabel(TestContext.CurrentContext.Test.Name + " :: " + logstatus, ExtentColor.Orange));
            }
            else if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Skipped)
            {
                logstatus = Status.Skip;
                log.Info(TestContext.CurrentContext.Test.MethodName + " Test case skip");
                ExtentTestManager.GetTest().Log(logstatus, message);
                ExtentTestManager.GetTest().Log(logstatus, MarkupHelper.CreateLabel(TestContext.CurrentContext.Test.Name + " :: " + logstatus, ExtentColor.Blue));
            }
        }