Beispiel #1
0
        /// <summary>
        /// This method asserts an expression and logs result.
        /// </summary>
        /// <param name="testCaseName">The name of test case.</param>
        /// <param name="scenarioName">The name of the scenario.</param>
        /// <param name="message">Any user message</param>
        /// <param name="assertExpression">This is the assert expression
        /// This expression is expected to be of format ()=> Assert.Fail(),Assert.AreEqual()...
        /// The method is executed and based on result the logging is done.
        /// </param>
        /// <param name="isTakeScreenShotOnPass">This tells if a screen shot should be taken
        /// if execution passes.</param>
        private void LogAssertion(string testCaseName, string scenarioName, string message, Action assertExpression, bool isTakeScreenShotOnPass = false)
        {
            const string logMessageTemplate = "~TestCaseName  = {0} ~ ScenarioName ={1} ~ Result = {2} ~ Message= {3} ~ ScreenShot File = {4}";
            //  string logMessage = null;

            // Date time stamp to convert the Screen shot file name
            String screenShotFileName = DateTime.Now.Year.ToString(CultureInfo.InvariantCulture)
                                        + DateTime.Now.Month
                                        + DateTime.Now.Day
                                        + DateTime.Now.Hour
                                        + DateTime.Now.Minute
                                        + DateTime.Now.Second;

            try
            {
                assertExpression.Invoke();
                message = String.Format(logMessageTemplate, testCaseName, scenarioName, "Assert Passed",
                                        message, isTakeScreenShotOnPass ? screenShotFileName : "Not Applicable");
                Log(message);
                if (isTakeScreenShotOnPass)
                {
                    TakeScreenShot(screenShotFileName);
                }
            }
            catch (AssertFailedException afe)
            {
                message = String.Format(logMessageTemplate, testCaseName, scenarioName, "~Assert Failed~", " | UserMessage = " + message + "~ Reason = " + afe, screenShotFileName);
                TakeScreenShot(screenShotFileName);
                Log(message);
                // Close webdriver and browser instances if Assert Fails
                WebDriverSingleton.GetInstance().Dispose();
                throw;
            }
        }
        /// <summary>
        /// This method returns an instance of web driver singleton.
        /// </summary>
        /// <returns></returns>
        public static WebDriverSingleton GetInstance()
        {
            if (_webDriverSingleton == null)
            {
                _webDriverSingleton = new WebDriverSingleton();
            }

            return(_webDriverSingleton);
        }
Beispiel #3
0
        /// <summary>
        /// This method takes a screenshot and puts it in the directory.
        /// </summary>
        /// <param name="fileName">This is the name of the file.</param>
        private void TakeScreenShot(string fileName)
        {
            Screenshot screenShot    = ((ITakesScreenshot)WebDriverSingleton.GetInstance().WebDriver).GetScreenshot();
            string     executingPath = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName;

            if (executingPath != null)
            {
                screenShot.SaveAsFile(Path.Combine(executingPath, "Log", fileName + ".jpeg"), ImageFormat.Jpeg);
            }
        }
 /// <summary>
 /// Clean the WebDriver.
 /// </summary>
 public void WebDriverCleanUp()
 {
     WebDriverSingleton.GetInstance().Cleanup();
     FiddlerProxy.StopFiddlerProxy();
 }
 public void ResetDesiredBrowser(string browser)
 {
     WebDriverSingleton.GetInstance().ResetNewBrowserSingleton(browser);
 }
 /// <summary>
 /// Reset the Webdriver Singleton.
 ///  </summary>
 public void ResetWebdriver()
 {
     WebDriverSingleton.GetInstance().ResetSingleton();
 }
 public void ResetNewBrowserSingleton(string browser)
 {
     _webDriverSingleton = new WebDriverSingleton(browser);
 }
        ///// <summary>
        ///// Returns an instance of Selenium
        ///// </summary>
        //public ISelenium Selenium
        //{
        //    get
        //    {
        //        if (_webDriverSingleton == null)
        //        {
        //            _webDriverSingleton = new WebDriverSingleton();
        //        }
        //        return _selenium;
        //    }
        //}

        /// <summary>
        /// Resets the singleton.
        /// </summary>
        public void ResetSingleton()
        {
            _webDriverSingleton = new WebDriverSingleton();
        }