Hi

I'm using special attribute for this - code below might help you:

    [AttributeUsage ( PatternAttributeTargets.Test, AllowMultiple = false, 
Inherited = true )]
    [SystemInternal]
    public class ScreenShotOnExceptionAttribute : 
TestMethodDecoratorPatternAttribute
    {
        /// <inheritdoc />
        protected override void DecorateMethodTest ( IPatternScope 
methodScope, IMethodInfo method )
        {
            
methodScope.TestBuilder.TestInstanceActions.ExecuteTestInstanceChain.Around 
( WithinTryCatch );
        }

        [UserCodeEntryPoint]
        private void WithinTryCatch ( PatternTestInstanceState state, 
Action<PatternTestInstanceState> action )
        {
            try
            {
                action ( state );
            }
            catch
            {
                TestLog.EmbedImage ( screenshotName, screenShotMethod () );
                throw;
            }
        }
    }

I did not work with selenium screenShot options so you have to figure out 
this function by yourself.

Regards,
Marcin


W dniu piątek, 16 listopada 2012 10:12:57 UTC+1 użytkownik davy derwael 
napisał:
>
> Hi,
>
> I am trying to take a screenshot whenever a test fails. I am using the 
> setup below: 
> Unfortunately this always returns "passed" when I try the following:if 
> (TestContext.CurrentContext.
> IsTriggeredEventSatisfied(TriggerEvent.TestFailed))
>
>
>  [Test]
>         [Parallelizable]
>         [Description ("Change password and change it back")]
>         [Row("nl")]
>         [Row("fr")]
>        
>         public void Test(string locale)
>         {
>             
>              try
>              {
>                  // do something
>              }
>              finally
>              {
>                
>                     //if failed, take screenshot
>              }
>         }
>
> any tips / hints would be great
>
> thanks a lot!
>

-- 
You received this message because you are subscribed to the Google Groups 
"MbUnit.User" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/mbunituser/-/d88berm8lEQJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/mbunituser?hl=en.

Reply via email to