static CreateInstance()
 {
     generator = WebTestContext.Get <ProxyGenerator>(Constants.ProxyKey, false);
     if (generator == null)
     {
         WebTestContext.Set(Constants.ProxyKey, new ProxyGenerator());
         generator = WebTestContext.Get <ProxyGenerator>(Constants.ProxyKey);
     }
 }
        private static void WriteToFile()
        {
            List <string> contents = WebTestContext.Get <List <string> >(Constants.LogsKey);

            if (contents == null || contents.Count == 0)
            {
                return;
            }
            File.AppendAllLines(WebTestContext.Get <string>(Constants.TestLogFileKey), contents);
        }
        public ServerCommandExecutor() : this(null, null)
        {
            //Check if the test context contains appropriate parameters, set them if true
            RemoteWebDriver           driver     = WebDriver.Instance;
            TestEnvironmentParameters parameters = WebTestContext.Get <TestEnvironmentParameters>(Constants.TestEnvironmentKey);
            Uri serverUri = parameters.ServerUri;

            sessionId      = driver.SessionId;
            this.serverUri = serverUri;
        }
        /// <summary>
        /// Write content to the test log file
        /// </summary>
        /// <param name="content"></param>
        public static void Write(string content)
        {
            if (Convert.ToBoolean(WebTestContext.Get <string>(nameof(Constants.DevelopmentMode), false)))
            {
                return;
            }
            List <string> log = new List <string>()
            {
                content
            };

            Write(log);
        }
 public static void Attach()
 {
     if (!WebTestContext.ContainsKey(Constants.TestLogFileKey))
     {
         TestContext.WriteLine($"No test logs generated, test logs will not be attached");
         return;
     }
     if (!File.Exists(WebTestContext.Get <string>(Constants.TestLogFileKey)))
     {
         TestLogs.Write("No test log file exists, no screenshot will be attached.");
         return;
     }
     TestContext.AddTestAttachment(WebTestContext.Get <string>(Constants.TestLogFileKey), "Test Log File");
 }
        /// <summary>
        /// Write content to the test log file
        /// </summary>
        /// <param name="content"></param>
        public static void Write(List <string> content)
        {
            if (Convert.ToBoolean(WebTestContext.Get <string>(nameof(Constants.DevelopmentMode), false)))
            {
                return;
            }
            IEnumerable <string> log = content;

            if (content == null)
            {
                return;
            }
            File.AppendAllLines(WebTestContext.Get <string>(Constants.TestLogFileKey), log);
        }
Example #7
0
        public static void Attach()
        {
            if (!WebTestContext.ContainsKey(Constants.ScreenshotFileKey))
            {
                TestLogs.Write("No screenshot file exists, no screenshot will be attached.");
                return;
            }

            string screenShotName = WebTestContext.Get <string>(Constants.ScreenshotFileKey);

            CaptureScreenshot(screenShotName);
            if (!File.Exists(screenShotName))
            {
                TestLogs.Write("No screenshot file exists, no screenshot will be attached.");
                return;
            }
            TestContext.AddTestAttachment(WebTestContext.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(WebTestContext.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);
        }