コード例 #1
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);
            }
        }
コード例 #2
0
        public static void TearDown()
        {
            // Print log to console (from TestContext)
            string log = TestContext.Get("log").ToString();

            if (log.Length > 0)
            {
                Console.WriteLine(log);
            }
        }
コード例 #3
0
        public void SetUp()
        {
            // Save a reference to the current Test's log in its TestContext
            TestContext.Set("log", "");

            // Get the Base Address
            string baseAddress = ConfigurationManager.AppSettings["baseAddress"] ?? "";

            // Get the Test's custom Attributes
            IEnumerable <CustomAttributeData> customAttributeDatas = new StackTrace().GetFrame(1).GetMethod().CustomAttributes;

            // Log the custom Attributes
            Log.CustomAttributes(customAttributeDatas);
            // Write an end-line
            Log.WriteLine();
            // 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.SetUp()");
            sb.AppendLine(logPadding.InfoPadding + "[INFO] Base Address: " + baseAddress);
            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
            {
                // Create a new instance of the httpclient
                HttpClient httpClient = new HttpClient();
                if (baseAddress.Length > 0)
                {
                    httpClient.BaseAddress = new Uri(baseAddress);
                }
                // Save that to the test context
                TestContext.Set("httpClient", httpClient);
                // 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(logPadding.Padding);
            }
        }
コード例 #4
0
        public void Setup()
        {
            // Save a reference to the current Test's log in its TestContext
            TestContext.Set("log", "");

            // Get the Test's custom Attributes
            IEnumerable <CustomAttributeData> customAttributeDatas = new StackTrace().GetFrame(1).GetMethod().CustomAttributes;

            // Log the custom Attributes
            Log.CustomAttributes(customAttributeDatas);
            // Write an end-line
            Log.WriteLine();

            // 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.Setup()");
            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
            {
                // Create a WebDrvier session
                Session.Create();

                // Set WebDriver's window to full screen
                AppBase.Maximize();

                // Delete all cookies
                AppBase.DeleteAllCookies();

                // 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(logPadding.Padding);
            }
        }
コード例 #5
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);
                }
            }
        }
コード例 #6
0
        public void SetUp()
        {
            // Get the Base Address
            string baseAddress = ConfigurationManager.AppSettings["baseAddress"] ?? "";

            // Save a reference to the current Test's log in its TestContext
            TestContext.Set("log", "");

            // Log the test attributes of the current [Test]
            Log.StandardAttributes();

            // Log Before Action
            Log.BeforeAction(new OrderedDictionary()
            {
                { "baseAddress", baseAddress }
            });

            // Perform the action
            try
            {
                // Create a new instance of the httpclient
                HttpClient httpClient = new HttpClient();
                if (baseAddress.Length > 0)
                {
                    httpClient.BaseAddress = new Uri(baseAddress);
                }
                // Save that to the test context
                TestContext.Set("httpClient", httpClient);
                // 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();
            }
        }
コード例 #7
0
        public void Setup()
        {
            // Save a reference to the current Test's log in its TestContext
            TestContext.Set("log", "");

            // Log the test attributes of the current [Test]
            Log.StandardAttributes();

            // Log Before Action
            Log.BeforeAction();

            // Perform the action
            try
            {
                // Create a WebDrvier session
                Session.Create();

                // Set WebDriver's window to full screen
                AppBase.Maximize();

                // Delete all cookies
                AppBase.DeleteAllCookies();

                // 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();
            }
        }
コード例 #8
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);
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Create a TestBase for your specific project (see TestBaseStarAppIos, for example) and call this method.
        /// The Setup annotation was removed to prevent it being called when there is a project specific Setup (see above).
        /// </summary>
        public static void Setup()
        {
            // Log Before Action
            Log.BeforeAction();

            // Perform the action
            try
            {
                // Create a variable to serve as a flag for if a new session needs to be created or not
                bool createNewSession = false;
                // Create a variable to hold the Test's WebDriver
                AppiumDriver <AppiumWebElement> driver = null;
                // Is the global WebDriver varaiable set?
                if (Session.driver != null)
                {
                    // Create a variable to hold the Session Info
                    Dictionary <string, object> sessionInfo = null;
                    // Try to get the Session Info (which only works if there is a valid session) from the global variable
                    // Note: We need to use the same Appium session (driver) for all test or we could lose the device in the cloud.
                    try { sessionInfo = Session.driver.SessionDetails; }
                    catch { /* do nothing */ }
                    // Check the Session Info variable has some content
                    if (sessionInfo != null)
                    {
                        // Use the existing session
                        Log.WriteLine("    [INFO] Using the existing session.");
                        driver = Session.driver;
                    }
                    else
                    {
                        // Set the flag to create a new session to true
                        createNewSession = true;
                    }
                }
                // Should we create a new session?
                if (createNewSession == true)
                {
                    // Wait 60 seconds to timeout any existing sessions (in SauceLab's TestObject)
                    if (ConfigurationManager.AppSettings["appConfig"].ToString().Contains("SauceLabs"))
                    {
                        Sleep.Milliseconds(60000, "Waiting 60 seconds to kill the current session (in SauceLab's TestObject).");
                    }
                    // Create a new session
                    Log.WriteLine("    [INFO] Creating a new session.");
                    driver = Session.Create();
                }
                // Save a reference to the current Test's driver (session) in its TestContext
                TestContext.Set("driver", driver);

                // Reset the app
                AppBase.ResetApp();

                // 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();
            }
        }
コード例 #10
0
        public void Setup()
        {
            // Save a reference to the current Test's log in its TestContext
            TestContext.Set("log", "");

            // Get the Test's custom Attributes
            IEnumerable <CustomAttributeData> customAttributeDatas = new StackTrace().GetFrame(1).GetMethod().CustomAttributes;

            // Log the custom Attributes
            Log.CustomAttributes(customAttributeDatas);
            // Write an end-line
            Log.WriteLine();

            // 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.Setup()");
            //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
            {
                // Create a variable to serve as a flag for if a new session needs to be created or not
                bool createNewSession = false;
                // Create a variable to hold the Test's WebDriver
                AppiumDriver <AppiumWebElement> driver = null;
                // Is the global WebDriver varaiable set?
                if ((Session.driver != null))
                {
                    // Is there session info?
                    Dictionary <string, object> sessionInfo = null;
                    try { sessionInfo = Session.driver.SessionDetails; }
                    catch { /* do nothing */ }
                    if (sessionInfo != null)
                    {
                        // Use the existing session
                        Log.WriteLine(logPadding.InfoPadding + "[INFO] Using the existing session.");
                        driver = Session.driver;
                    }
                    else
                    {
                        // Set the flag to create a new session to true
                        createNewSession = true;
                    }
                }
                // Should we create a new session?
                if (createNewSession == true)
                {
                    // Wait 60 seconds to kill the current session (the default TimeOut for Appium)
                    Sleep.Milliseconds(60000, "Waiting 60 seconds to kill the current session.");
                    // Create a new session
                    Log.WriteLine(logPadding.InfoPadding + "[INFO] Creating a new session.");
                    driver = Session.Create();
                }
                // Save a reference to the current Test's driver in its TestContext
                TestContext.Set("driver", driver);

                // Reset the app
                AppBase.ResetApp();

                // 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(logPadding.Padding);
            }
        }