private static void AttachLocalServerLogs() { if (string.IsNullOrEmpty(MobileTestContext.Get <string>(Constants.AppiumServerLogFileKey, false))) { return; } TestContext.AddTestAttachment(MobileTestContext.Get <string>(Constants.AppiumServerLogFileKey), "Local Appium Server Logs"); }
static CreateInstance() { generator = MobileTestContext.Get <ProxyGenerator>(Constants.ProxyKey, false); if (generator == null) { MobileTestContext.Set(Constants.ProxyKey, new ProxyGenerator()); generator = MobileTestContext.Get <ProxyGenerator>(Constants.ProxyKey); } }
public ServerCommandExecutor() : this(null, null) { //Check if the test context contains appropriate parameters, set them if true AppiumDriver <AppiumWebElement> driver = MobileTestContext.Get <AppiumDriver <AppiumWebElement> >(nameof(MobileDriver), false); TestEnvironmentParameters parameters = MobileTestContext.Get <TestEnvironmentParameters>(Constants.TestEnvironmentKey); Uri serverUri = parameters.ServerUri; this.sessionId = driver.SessionId; this.serverUri = serverUri; }
/// <summary> /// Attach log files /// </summary> public static void Attach() { //Attach local Server Logs, if any AttachLocalServerLogs(); //Attach Device Logs if (MobileTestContext.Get <AppiumDriver <AppiumWebElement> >(nameof(MobileDriver), false) != null) { AttachDeviceLogs(); } if (!string.IsNullOrEmpty(MobileTestContext.Get <string>(Constants.TestLogFileKey, false))) { TestContext.AddTestAttachment(MobileTestContext.Get <string>(Constants.TestLogFileKey), "Test Log File"); } }
private static void CleanupScreenshots() { string testScreenshotFullPath = Path.Combine(screenshotFolder, TestContext.CurrentContext.Test.Name + ".jpeg"); if (File.Exists(testScreenshotFullPath)) { try { File.Delete(testScreenshotFullPath); } catch (UnauthorizedAccessException e) { Console.WriteLine("Cannot cleanup test screenshot file", e); } catch (Exception ex) { Console.WriteLine("Cannot cleanup test screenshot file", ex); } } MobileTestContext.Set(Constants.ScreenshotFileKey, testScreenshotFullPath); }
/// <summary> /// Write content to the test log file /// </summary> /// <param name="content"></param> public static void Write(string content) { if (Convert.ToBoolean(MobileTestContext.Get <string>(nameof(Constants.DevelopmentMode), false))) { return; } IEnumerable <string> log = new List <string>() { content }; if (content == null) { return; } File.AppendAllLines(MobileTestContext.Get <string>(Constants.TestLogFileKey), log); }
private static void SetupTestLog() { string testFileNameFullPath = Path.Combine(testLogFolder, TestContext.CurrentContext.Test.Name + ".log"); if (File.Exists(testFileNameFullPath)) { try { File.Delete(testFileNameFullPath); } catch (UnauthorizedAccessException e) { Console.WriteLine("Cannot cleanup test log file", e); } catch (Exception ex) { Console.WriteLine("Cannot cleanup test log file", ex); } } File.Create(testFileNameFullPath).Close(); MobileTestContext.Set(Constants.TestLogFileKey, testFileNameFullPath); }
/// <summary> /// Capture and attach screenshot on test failure. /// </summary> public static void Attach() { //Check if prereq passed and the file name/path setup correctly. string screenshotName = MobileTestContext.Get <string>(Constants.ScreenshotFileKey, false); if (string.IsNullOrEmpty(screenshotName)) { TestLogs.Write("No screenshot file exists, no screenshot will be attached."); return; } CaptureScreenshot(screenshotName); if (!File.Exists(screenshotName)) { TestLogs.Write("No screenshot file exists, no screenshot will be attached."); return; } TestContext.AddTestAttachment(MobileTestContext.Get <string>(Constants.ScreenshotFileKey), $"Error screenshot"); }
/// <summary> /// Write content to file. File name with be appended to the test name. /// </summary> /// <param name="fileName">file name suffix</param> /// <param name="content">content to write to file</param> public static string Write(string fileName, string content) { if (Convert.ToBoolean(MobileTestContext.Get <string>(nameof(Constants.DevelopmentMode), false))) { return(string.Empty); } IEnumerable <string> log = new List <string>() { content }; if (content == null) { return(string.Empty); } string basePath = Path.Combine(Resources.BasePath, Constants.TestLogFolder, TestContext.CurrentContext.Test.Name + $"_{fileName}.log"); if (File.Exists(basePath)) { File.Delete(basePath); } File.AppendAllLines(basePath, log); return(basePath); }