Beispiel #1
0
 private static void CaptureScreenshot(string screenShotName)
 {
     try {
         WebDriver.Instance.TakeScreenshot().SaveAsFile(screenShotName, ScreenshotImageFormat.Png);
     } catch (Exception e) {
         TestLogs.Write($"cannot capture screenshot of the application. {e.InnerException}");
     }
 }
 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");
 }
 private void BeforeInvocation(IInvocation invocation)
 {
     if (invocation.Arguments.Length > 0)
     {
         string log = $"[{invocation.Method.DeclaringType}.{invocation.Method.Name}] with Arguments:" +
                      $"[{BuildArgumentString(invocation, ",")}]";
         TestLogs.Write("---------Script Call Initiated=>" + log + "---------");
     }
     else
     {
         string log = $"[{invocation.Method.DeclaringType}.{invocation.Method.Name}]";
         TestLogs.Write($"---------Script Call Initiated=>" + log + "---------");
     }
 }
            /// <summary>
            /// Intercept Method Calls
            /// </summary>
            /// <param name="invocation"></param>
            /// <exception cref="Exception"></exception>
            public void Intercept(IInvocation invocation)
            {
                BeforeInvocation(invocation);
                try {
                    invocation.Proceed();
                } catch (Exception e) {
                    string logcontent = $"[{invocation.Method.DeclaringType}.{invocation.Method.Name}], with" +
                                        $"\nError:{e.Message} \n {e.StackTrace}";
                    TestLogs.Write("---------Script Call Failed =>" + logcontent + "---------");

                    throw new MethodExecutionFailedException($"Execution of method [{invocation.Method.Name}] failed", e);
                }
                AfterInvocation(invocation);
            }
Beispiel #5
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");
        }
            private void AfterInvocation(IInvocation invocation)
            {
                string logcontent = $"---------Script Call Successful =>[{invocation.Method.DeclaringType}.{invocation.Method.Name}] ";

                TestLogs.Write(logcontent + "---------");
            }