private static void CaptureScreenshot(string screenshotName)
 {
     try {
         MobileDriver.Instance.TakeScreenshot().SaveAsFile(screenshotName, ScreenshotImageFormat.Png);
     } catch (Exception e) {
         TestLogs.Write($"Cannot capture screenshot of the application. {e.InnerException}");
     }
 }
Exemple #2
0
 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 + "---------");
     }
 }
Exemple #3
0
            /// <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);
            }
        /// <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");
        }
Exemple #5
0
            private void AfterInvocation(IInvocation invocation)
            {
                string logcontent = $"---------Script Call Successful =>[{invocation.Method.DeclaringType}.{invocation.Method.Name}] ";

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