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); } }
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); } }
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(); } }
/// <summary> /// Writes the specified string value, followed by the current line terminator, to the log. /// </summary> /// <param name="value">The value to write.</param> public static void WriteLine(string value = "") { if (destination == "console") { Console.WriteLine(value); } else if (destination == "context") { // Get the "log" from the current TestContext string log = TestContext.Get("log").ToString(); // Add the new "log line" to the "log" log = log + value + Environment.NewLine; // Save the new log TestContext.Set("log", log); } else { throw new NotImplementedException("The destination '" + destination + "' is not setup in Log.WriteLine()."); } }
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(); } }
/// <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(); } }
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); } }