Skip to content

Latest commit

 

History

History
52 lines (38 loc) · 2.17 KB

fail-test-programmatically.md

File metadata and controls

52 lines (38 loc) · 2.17 KB
title page_title description position
Fail Step or Test Programmatically
Fail test step or mark the entire test result as failed
Even if all test steps are successful, you might need to fail one step or the entire test at the end of the execution. You can do that programmatically in OnAfterTestCompleted method.
1

Fail Step or Test Programatically

PROBLEM

All steps are successfully executed, but you might need to still fail the test due to internal errors in the application. Consider adding a verification step to ensure the state of the application is correct. In case there is no such verification available, you can apply the proposed solution.

SOLUTION

You can change the result from specific step or the entire test programmatically, after the test is completed. To do that, you need to override the method OnAfterTestCompleted() in a coded step.

1.  Add a coded step to the current test.

2.  Override the OnAfterTestCompleted() method outside of the coded step method. The logic inside this method will be executed after the last step of the test.

3.  Find a specific condition, which will be used to evaluate the state of the application and whether the step or test should be marked as failed.

namespace DemoProj
{

    public class testToFail : BaseWebAiiTest
    {
        #region [ Dynamic Pages Reference ]

        // Add your test methods here...
    
        [CodedStep(@"New Coded Step")]
        public void testToFail_CodedStep()
        {
            
        }

        public override void OnAfterTestCompleted(TestResult result)
        {
            if (condition == false)
                {
                    // Mark the last step as failed
                    //result.StepResults.Last().ResultType = ArtOfTest.Common.Design.ResultType.Fail; 

                    // Mark the whole test as failed 
                    result.StepResults.Last().ParentTestResult.Result = ArtOfTest.Common.Design.ResultType.Fail;             
                }    
        }
    }   
}