Exemple #1
0
 public void SetUpReporter()
 {
     InitBrowser("Firefox");
     WaitClass.Driver        = Driver;
     ExcelTool.ExcelFilePath = xlFilePath;
     extent = new ExtentReportsHelper();
 }
        public void ScenarioTearDown(ScenarioContext _scenarioContext)
        {
            var status     = TestContext.CurrentContext.Result.Outcome.Status;
            var stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.Message)
                    ? ""
                    : $"<pre>{TestContext.CurrentContext.Result.Message}</pre>";
            Status logstatus;

            switch (status)
            {
            case TestStatus.Failed:
                logstatus = Status.Fail;
                break;

            case TestStatus.Inconclusive:
                logstatus = Status.Warning;
                break;

            case TestStatus.Skipped:
                logstatus = Status.Skip;
                break;

            default:
                logstatus = Status.Pass;
                break;
            }
            ExtentReportsHelper.CreateTestStepBDD(CommonHelper.CaptureScreen(), $"The Scenario '{_scenarioContext.ScenarioInfo.Title}' ended with status {logstatus}").Info(stacktrace);
        }
Exemple #3
0
        public void TearDownTest()
        {
            try
            {
                var status       = TestContext.CurrentContext.Result.Outcome.Status;
                var stacktrace   = TestContext.CurrentContext.Result.StackTrace;
                var errorMessage = "<pre>" + TestContext.CurrentContext.Result.Message + "</pre>";

                switch (status)
                {
                case TestStatus.Failed:
                    ExtentReportsHelper.GetExtentReportsHelper().SetTestStatusFail($"<br>{errorMessage}<br>Stack Trace: <br>{stacktrace}<br>");
                    break;

                case TestStatus.Skipped:
                    ExtentReportsHelper.GetExtentReportsHelper().SetTestStatusSkipped();
                    break;

                default:
                    ExtentReportsHelper.GetExtentReportsHelper().SetTestStatusPass();
                    break;
                }
            }
            catch (Exception exc)
            {
                throw (exc);
            }
            finally
            {
                _client.Dispose();
                WebDriverFactory.CloseAllDrivers();
                LogHelper.Info("Browser closed.");
            }
        }
Exemple #4
0
        public void TestCleanup()
        {
            var status     = TestContext.CurrentContext.Result.Outcome.Status;
            var stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.Message)
                    ? ""
                    : string.Format("<pre>{0}</pre>", TestContext.CurrentContext.Result.Message);
            Status logstatus;

            switch (status)
            {
            case TestStatus.Failed:
                logstatus = Status.Fail;
                break;

            case TestStatus.Inconclusive:
                logstatus = Status.Warning;
                break;

            case TestStatus.Skipped:
                logstatus = Status.Skip;
                break;

            default:
                logstatus = Status.Pass;
                break;
            }

            ExtentReportsHelper.GetTest().Log(logstatus, "Test ended with " + logstatus + stacktrace);
            if (logstatus == Status.Fail)
            {
                ExtentReportsHelper.LogFail(CommonHelper.CaptureScreen());
            }
        }
Exemple #5
0
 public void StartUp()
 {
     extent = new ExtentReportsHelper();
     extent.CreateTest(TestContext.CurrentContext.Test.Name);
     ResolveDependency.RegisterAndResolveDependencies();
     Session.StartBrowser();
     extent.SetStepStatusPass("Successfully opened browser session");
 }
Exemple #6
0
 public void Click()
 {
     if (WrappedControl is null)
     {
         throw new NotFoundException("Element not found.");
     }
     ExtentReportsHelper.LogInformation(CommonHelper.CaptureScreen(WrappedControl), $"Click on the Button '{WrappedControl.Text}'.");
     WrappedControl.Click();
 }
Exemple #7
0
 public void SetUpTest()
 {
     ExtentReportsHelper.GetExtentReportsHelper().CreateTest(TestContext.CurrentContext.Test.Name);
     WebDriverFactory.InitBrowser("Chrome");
     LogHelper.Info("Browser started.");
     WebDriverFactory.GoToUrl(ConfigurationManager.AppSettings["URL"]);
     LogHelper.Info($"Browser navigated to the url [{ConfigurationManager.AppSettings["URL"]}].");
     WebDriverFactory.Driver.Manage().Window.Maximize();
     LogHelper.Info("Browser maximized.");
 }
Exemple #8
0
 protected void CaptureStepAndLogInfo(IWebElement control, string message = "")
 {
     if (control is null)
     {
         CaptureStepAndLogInfo(message);
     }
     else
     {
         ExtentReportsHelper.LogInformation(CommonHelper.CaptureScreen(control), message);
     }
 }
 public static void ClearWrapper(this IWebElement element, ExtentReportsHelper extentReportsHelper, string elementName)
 {
     element.Clear();
     if (element.Text.Equals(string.Empty))
     {
         extentReportsHelper.SetStepStatusPass($"Cleared element [{elementName}] content.");
     }
     else
     {
         extentReportsHelper.SetStepStatusWarning($"Element [{elementName}] content is not cleared. Element value is [{element.Text}]");
     }
 }
Exemple #10
0
 public void SetUpTest()
 {
     _client = new HttpClient();
     ExtentReportsHelper.GetExtentReportsHelper().CreateTest(TestContext.CurrentContext.Test.Name);
     WebDriverFactory.InitBrowser("Chrome");
     LogHelper.Info("Browser started.");
     WebDriverFactory.GoToUrl(ConfigurationManager.AppSettings["URL"]);
     LogHelper.Info($"Browser navigated to the url [{ConfigurationManager.AppSettings["URL"]}].");
     WebDriverFactory.Driver.Manage().Window.Maximize();
     LogHelper.Info("Browser maximized.");
     WebDriverFactory.Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);
 }
 public static void ClickWrapper(this IWebElement element, IWebDriver driver, ExtentReportsHelper extentReportsHelper, string elementName)
 {
     if (element.ElementlIsClickable(driver, extentReportsHelper, elementName))
     {
         element.Click();
         extentReportsHelper.SetStepStatusPass($"Clicked on the element [{elementName}].");
     }
     else
     {
         throw new Exception($"Element [{elementName}] is not displayed");
     }
 }
Exemple #12
0
        public void InsertReportingAfterSteps(ScenarioContext _scenarioContext)
        {
            var stepType = ScenarioStepContext.Current.StepInfo.StepDefinitionType.ToString();

            // Handle spending steps
            if (_scenarioContext.ScenarioExecutionStatus.ToString() == "StepDefinitionPending")
            {
                ExtentReportsHelper.LogWarning(stepType, ScenarioStepContext.Current.StepInfo.Text);
            }
            // Handle failed steps
            else if (_scenarioContext.TestError != null)
            {
                ExtentReportsHelper.LogFail(stepType, ScenarioStepContext.Current.StepInfo.Text);
            }
        }
Exemple #13
0
        public void TestInitialize()
        {
            if (TestContext.Properties.Contains("browser"))
            {
                browser = TestContext.Properties["browser"].ToString();
            }

            if (TestContext.Properties.Contains("environment"))
            {
                environment = TestContext.Properties["environment"].ToString();
            }

            if (TestContext.Properties.Contains("teamBinderVersion"))
            {
                teamBinderVersion = TestContext.Properties["teamBinderVersion"].ToString();
            }

            if (TestContext.Properties.Contains("excelUserSourcePath"))
            {
                excelUserSourcePath = TestContext.Properties["excelUserSourcePath"].ToString();
            }

            if (TestContext.Properties.Contains("localTempExcelUserTargetPath"))
            {
                localTempExcelUserTargetPath = TestContext.Properties["localTempExcelUserTargetPath"].ToString();
            }

            if (TestContext.Properties.Contains("headless"))
            {
                Browser.Headless = bool.Parse(TestContext.Properties["headless"].ToString());
            }

            if (!System.IO.Directory.Exists(captureLocation))

            {
                Directory.CreateDirectory(captureLocation);
            }

            string report = Utils.GetRandomValue(TestContext.TestName);

            reportPath = captureLocation + report + ".html";
            extent     = ExtentReportsHelper.CreateReport(reportPath, TestContext.TestName);
            extent.AddSystemInfo("Environment", TestContext.Properties["environment"].ToString());
            extent.AddSystemInfo("Browser", TestContext.Properties["browser"].ToString());
            test = ExtentReportsHelper.LogTest("Pre-condition");
        }
        public static bool ValidatePageTitle(this IWebDriver driver, ExtentReportsHelper extentReportsHelper, string title, uint timeoutInSeconds = 300)
        {
            bool result = false;
            var  wait   = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));

            wait.IgnoreExceptionTypes(typeof(Exception));
            return(result = wait.Until(drv =>
            {
                if (drv.Title.Contains(title))
                {
                    extentReportsHelper.SetStepStatusPass($"Page title [{drv.Title}] contains [{title}].");
                    return true;
                }
                extentReportsHelper.SetStepStatusWarning($"Page title [{drv.Title}] does not contain [{title}].");
                return false;
            }));
        }
Exemple #15
0
        public void ClassCleanup()
        {
            // Runs once after all tests in this class are executed. (Optional)
            // Not guaranteed that it executes instantly after all tests from the class.
            var status = TestContext.CurrentContext.Result.Outcome.Status;

            if (status == TestStatus.Failed && ExtentReportsHelper.GetTest() == null)
            {
                ExtentReportsHelper.CreateTest(TestContext.CurrentContext.Test.Name);
                ExtentReportsHelper.LogFail(null, "Test Fail.");
            }

            BaseValues.ExtentReports.Flush();

            // Disppose the instance of webdriver
            BaseDriver.StopBrowser();
            CleanUpAllDriver();
        }
Exemple #16
0
 public Home(IWebDriver webDriver, ExtentReportsHelper reportsHelper)
 {
     driver = webDriver;
     extentReportsHelper = reportsHelper;
 }
Exemple #17
0
 public void TestInit()
 {
     // Create Test Set
     ExtentReportsHelper.CreateTest(TestContext.CurrentContext.Test.Name);
 }
Exemple #18
0
 public void ClassInit()
 {
     ExtentReportsHelper.CreateParentTest(GetType().Name);
 }
        public static bool ControlDisplayed(this IWebElement element, IWebDriver driver, ExtentReportsHelper extentReportsHelper, string elementName, bool displayed = true, uint timeoutInSeconds = 60)
        {
            var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));

            wait.IgnoreExceptionTypes(typeof(Exception));
            return(wait.Until(drv =>
            {
                if (!displayed && !element.Displayed || displayed && element.Displayed)
                {
                    extentReportsHelper.SetStepStatusPass($"[{elementName}] is displayed on the page.");
                    return true;
                }
                extentReportsHelper.SetStepStatusPass($"[{elementName}] is displayed on the page.");
                return false;
            }));
        }
Exemple #20
0
 protected void CaptureStepAndLogInfo(string message = "")
 {
     ExtentReportsHelper.LogInformation(CommonHelper.CaptureScreen(WrappedControl), message);
 }
 public static void SetPass(ExtentReportsHelper extentReportsHelper)
 {
     extentReportsHelper.SetStepStatusPass("Hanuman");
 }
Exemple #22
0
 public void ThenILogOut()
 {
     PracticePage.Instance.LogOut();
     ExtentReportsHelper.LogInformation(CommonHelper.CaptureScreen(), "------------------------------");
 }
Exemple #23
0
 public void ThenThePageIsSearchWithTheValueAndTheTitleIsDisplayed(string p0)
 {
     // Verify
     Assert.AreEqual(p0, PracticePage.Instance.GetTitle);
     ExtentReportsHelper.LogPass(CommonHelper.CaptureScreen(), "The title of page is displayed as expected");
 }
Exemple #24
0
 public void ThenThePageIsSignedSuccessfullyWithTitle(string p0)
 {
     Assert.AreEqual(p0, PracticePage.Instance.GetTitle);
     ExtentReportsHelper.LogPass(CommonHelper.CaptureScreen(), "The title of page is displayed as expected");
 }
Exemple #25
0
        protected void ReportResult(Status status, string reportFilePath)
        {
            test = extent.CreateTest("Test Summary");

            if (status == Status.Pass)
            {
                test.Pass(TestContext.TestName + " Passed");
                for (int i = 0; i < validations.Count; i++)
                {
                    test.Info(string.Join(Environment.NewLine, validations[i]));
                }
            }

            else
            {
                //ExtentReportsHelper.test.Error(lastException);
                //string callingMethodName = new StackFrame(1, true).GetMethod().Name;
                //string callingClassName = GetType().Name;
                string timeStamp = DateTime.Now.ToString("ddMMyyyyHHmmss");
                string filePath  = captureLocation + "ErrorCapture" + timeStamp + ".png";
                try
                {
                    Screenshot screenshot = ((ITakesScreenshot)Browser.Driver).GetScreenshot();
                    screenshot.SaveAsFile(filePath, ScreenshotImageFormat.Png);
                }
                catch (Exception e)
                {
                    Console.WriteLine("TakeScreenshot encountered an error. " + e.Message);
                }
                finally
                {
                    try
                    {
                        if (lastException == null || lastException.ToString().Contains("Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException"))
                        {
                            test.Fail(TestContext.TestName + " Failed - " + lastException.Message);
                            for (int i = 0; i < validations.Count; i++)
                            {
                                test.Info(string.Join(Environment.NewLine, validations[i]));
                            }
                        }

                        else
                        {
                            if (ExtentReportsHelper.nodeList.LastOrDefault() != null)
                            {
                                ExtentReportsHelper.nodeList.LastOrDefault().Error(lastException.ToString(), ExtentReportsHelper.AttachScreenshot(filePath));
                            }
                            {
                                test.Error(TestContext.TestName + " Got Exception During Execution - " + lastException.Message + " " + lastException.StackTrace, ExtentReportsHelper.AttachScreenshot(filePath));
                                for (int i = 0; i < validations.Count; i++)
                                {
                                    test.Info(string.Join(Environment.NewLine, validations[i]));
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        // do nothing
                    }
                }
                TestContext.AddResultFile(filePath);
            }

            extent.AnalysisStrategy = AnalysisStrategy.Test;
            extent.Flush();
            TestContext.AddResultFile(reportPath);
        }
Exemple #26
0
 public static void SetUpReporter(TestContext context)
 {
     extent = new ExtentReportsHelper();
 }
 public static bool ElementlIsClickable(this IWebElement element, IWebDriver driver, ExtentReportsHelper extentReportsHelper, string elementName, uint timeoutInSeconds = 60, bool displayed = true)
 {
     try
     {
         WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
         return(wait.Until(drv =>
         {
             if (WaitHelpers.ExpectedConditions.ElementToBeClickable(element) != null)
             {
                 extentReportsHelper.SetStepStatusPass($"Element [{elementName}] is clickable.");
                 return true;
             }
             extentReportsHelper.SetStepStatusWarning($"Element [{elementName}] is not clickable.");
             return false;
         }));
     }
     catch
     {
         return(false);
     }
 }
 public static void SendKeysWrapper(this IWebElement element, ExtentReportsHelper extentReportsHelper, string value, string elementName)
 {
     element.SendKeys(value);
     extentReportsHelper.SetStepStatusPass($"SendKeys value [{value}] to  element [{elementName}].");
 }
Exemple #29
0
 public void SetUpReporter()
 {
     extent = new ExtentReportsHelper();
 }
Exemple #30
0
 public Browsers(ExtentReportsHelper reportsHelper)
 {
     extentReportsHelper = reportsHelper;
 }