示例#1
0
 /// <summary>
 /// Writes the specified string value to the log.
 /// </summary>
 /// <param name="value">The value to write.</param>
 public static void Write(string value = "")
 {
     if (destination == "console")
     {
         Console.Write(value);
     }
     else if (destination == "context")
     {
         // Get the "log" from the current TestContext
         string log = "";
         try
         {
             log = TestContext.Get("log").ToString();
         }
         catch
         {
             /* do nothing */
         }
         // Add the new "log line" to the "log"
         log = log + value;
         // Save the new log
         TestContext.Set("log", log);
     }
     else
     {
         throw new NotImplementedException("The destination '" + destination + "' is not setup in Log.WriteLine().");
     }
 }
示例#2
0
 /// <summary>
 /// Throws an NUnit.Framework.AssertionException with the message that is passed in.
 /// This is used by the other Assert functions.
 /// </summary>
 /// <param name="message">The message to initialize the NUnit.Framework.AssertionException with.</param>
 public static void Fail(string message = "")
 {
     if (TestContext.Get("Automates") != null)
     {
         message = message + Environment.NewLine + "    [INFO] Automates: " + TestContext.Get("Automates").ToString();
     }
     NUnit.Framework.Assert.Fail(message);
 }
示例#3
0
        public void TearDown()
        {
            // Print this Test's log (from "TestContext") to the system console
            string log = TestContext.Get("log").ToString();

            if (log.Length > 0)
            {
                Console.WriteLine(log);
            }
        }
示例#4
0
 /// <summary>
 /// Logs the Test properties from the TestContext. This conatins the NUnit attributes (not custom).
 /// </summary>
 public static void StandardAttributes()
 {
     // Log the current Test's [Description("")]
     try
     {
         Log.WriteLine("[INFO] Test Description: " + TestContext.Get("Description"));
         Log.WriteLine();
     }
     catch { /* do nothing */ }
 }
示例#5
0
        public static void TearDown()
        {
            // Print log to console (from TestContext)
            string log = TestContext.Get("log").ToString();

            if (log.Length > 0)
            {
                Console.WriteLine(log);
            }
        }
示例#6
0
        public void TearDown()
        {
            // Figure out the padding (if any) to prepend to the log line
            LogPadding logPadding = new LogPadding(new StackTrace().GetFrame(1).GetMethod().ReflectedType);
            // Logging - Before action
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(logPadding.Padding + "TestBase.TearDown()");
            sb.AppendLine(logPadding.InfoPadding + "[STACK] Caller: " + new StackTrace().GetFrame(1).GetMethod().ReflectedType + "." + new StackTrace().GetFrame(1).GetMethod().Name + "()");
            Log.Write(sb.ToString());
            // Perform the action
            try
            {
                // Check if the Test that is ending was a failure
                if (NUnit.Framework.TestContext.CurrentContext.Result.Outcome != NUnit.Framework.Interfaces.ResultState.Success)
                {
                    // Take screenshot of the failure state
                    AppBase.TakeScreenshot();
                }
                // Quit this driver, closing every associated window.
                AppBase.Quit();
                // Logging - After action success
                Log.Success(logPadding.Padding);
            }
            catch (Exception e)
            {
                // Logging - After action exception
                sb = Log.Exception(sb, e);
                // Fail current Test
                Assert.Fail(sb.ToString());
            }
            finally
            {
                // Logging - After action
                Log.Finally("");

                // Print this Test's log (from "TestContext") to the system console
                string log = TestContext.Get("log").ToString();
                if (log.Length > 0)
                {
                    Console.WriteLine(log);
                }
            }
        }
示例#7
0
        public void TearDown()
        {
            // Log Before Action
            Log.BeforeAction();

            // Perform the action
            try
            {
                // Check if the Test that is ending was a failure
                if (NUnit.Framework.TestContext.CurrentContext.Result.Outcome != NUnit.Framework.Interfaces.ResultState.Success)
                {
                    // Take screenshot of the failure state
                    AppBase.TakeScreenshot();
                }
                // Quit this driver, closing every associated window.
                AppBase.Quit();
                // Logging - After action success
                Log.Success();
            }
            catch (Exception e)
            {
                // Logging - After action exception
                Log.Failure(e.Message);
                // Fail current test
                Assert.Fail(e.Message);
            }
            finally
            {
                // Logging - After action
                Log.Finally();
                // Print log to console (for Visual Studio and Bamboo)
                string log = TestContext.Get("log").ToString();
                if (log.Length > 0)
                {
                    Console.WriteLine(log);
                }
            }
        }