Ejemplo n.º 1
0
 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");
 }
Ejemplo n.º 2
0
 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;
        }
Ejemplo n.º 4
0
 /// <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");
     }
 }
Ejemplo n.º 5
0
        /// <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);
        }
        /// <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");
        }
Ejemplo n.º 7
0
        /// <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);
        }