Esempio n. 1
0
        /// <summary>
        /// Soft assert method to check if the boolean is false
        /// </summary>
        /// <param name="condition">Boolean condition</param>
        /// <param name="softAssertName">Soft assert name</param>
        /// <param name="failureMessage">Failure message</param>
        /// <returns>Boolean of the assert</returns>
        /// <example>
        /// <code source = "../SeleniumUnitTesting/SeleniumUnitTest.cs" region="SoftAssertIsFalse" lang="C#" />
        /// </example>
        public override bool IsFalse(bool condition, string softAssertName, string failureMessage = "")
        {
            bool didPass = base.IsFalse(condition, softAssertName, failureMessage);

            if (!didPass)
            {
                if (Config.GetValue("SoftAssertScreenshot", "No").ToUpper().Equals("YES"))
                {
                    SeleniumUtilities.CaptureScreenshot(this.webDriver, this.Log, StringProcessor.SafeFormatter(" ({0})", this.NumberOfAsserts));
                }

                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Soft assert method to check if the strings are equal
        /// </summary>
        /// <param name="expectedText">Expected text</param>
        /// <param name="actualText">Actual text</param>
        /// <param name="softAssertName">Soft assert name to use</param>
        /// <param name="message">Exception message if desired</param>
        /// <returns>Boolean if the assert is true</returns>
        /// <example>
        /// <code source = "../SeleniumUnitTesting/SeleniumUnitTest.cs" region="SoftAssertAreEqual" lang="C#" />
        /// </example>
        public override bool AreEqual(string expectedText, string actualText, string softAssertName, string message = "")
        {
            bool didPass = base.AreEqual(expectedText, actualText, softAssertName, message);

            if (!didPass)
            {
                if (Config.GetValue("SoftAssertScreenshot", "No").ToUpper().Equals("YES"))
                {
                    SeleniumUtilities.CaptureScreenshot(this.webDriver, this.Log, StringProcessor.SafeFormatter(" ({0})", this.NumberOfAsserts));
                }

                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Take a screen shot if needed and tear down the web driver
        /// </summary>
        /// <param name="resultType">The test result</param>
        protected override void BeforeLoggingTeardown(TestResultType resultType)
        {
            // Try to take a screen shot
            try
            {
                if (this.Log is FileLogger && resultType != TestResultType.PASS && this.LoggingEnabledSetting != LoggingEnabled.NO)
                {
                    SeleniumUtilities.CaptureScreenshot(this.WebDriver, this.Log);
                }
            }
            catch (Exception e)
            {
                this.TryToLog(MessageType.WARNING, "Failed to get screen shot because: {0}", e.Message);
            }

            this.TryToLog(MessageType.INFORMATION, "Closing webDriver");

            try
            {
                // Clear the waiter
                this.WebDriver.RemoveWaitDriver();

                // Quite
                this.WebDriver.Quit();
            }
            catch (Exception e)
            {
                this.TryToLog(MessageType.WARNING, "Failed to quit because: {0}", e.Message);
            }

            try
            {
                this.WebDriver.Dispose();
            }
            catch (Exception e)
            {
                this.TryToLog(MessageType.WARNING, "Failed to dispose because: {0}", e.Message);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Get the javaScript executor from a web element or web driver
 /// </summary>
 /// <param name="searchContext">The search context</param>
 /// <returns>The javaScript executor</returns>
 public static IJavaScriptExecutor SearchContextToJavaScriptExecutor(ISearchContext searchContext)
 {
     return((searchContext is IJavaScriptExecutor) ? (IJavaScriptExecutor)searchContext : (IJavaScriptExecutor)SeleniumUtilities.WebElementToWebDriver((IWebElement)searchContext));
 }
Esempio n. 5
0
 /// <summary>
 /// Get the web driver from a web element or web driver
 /// </summary>
 /// <param name="searchContext">The search context</param>
 /// <returns>The web driver</returns>
 public static IWebDriver SearchContextToWebDriver(ISearchContext searchContext)
 {
     return((searchContext is IWebDriver) ? (IWebDriver)searchContext : SeleniumUtilities.WebElementToWebDriver((IWebElement)searchContext));
 }