Page 1 of 1

Validate TestSuite pre-conditions before running test cases

Posted: Fri Jul 08, 2016 3:05 pm
by Vaughan.Douglas
I've got a fun little event handler that's been attached to TestSuiteCompleted which reports various metrics to a reporting database. This works pretty much fine, but there are a few items that I need the user to provide or the entire thing will fail.

I've decided to have the user add two global parameters to the test suite and provide a value for them, as opposed to them setting it directly from the code. Unfortunately these are not derived and must be provided directly.

To check for these parameters prior to test case execution, I've attached another custom handler to the TestSuiteStarted event where I simply throw in a check:

Code: Select all

 If Not TestSuite.Current.Parameters.ContainsKey("Parm_Name") Then 
Now I'm a bit stuck on how to stop execution and provide feedback to the user. If I report a failure it registers in the cmd window, but the failure message isn't provided on the report.

I'd appreciate any suggestions or ideas. The only real constraints are that I'm trying to get this done at the TestSuite level so I don't have to worry about adding teardown modules and other such shenanigans.

Re: Validate TestSuite pre-conditions before running test cases

Posted: Tue Jul 12, 2016 3:10 pm
by Support Team
Hi Douglas,

I'm not sure if I understood your question correctly.
However, if you want to stop the test and let the execution fail you could use the following line of code.

Code: Select all

Validate.Fail();
Please get back to me if I misunderstood your query.

Sincerely,
Matthias

Re: Validate TestSuite pre-conditions before running test cases

Posted: Tue Jul 12, 2016 3:25 pm
by Vaughan.Douglas
Doing so does not actually stop the execution, nor is the report message reflected on the Ranorex Report.

In main I've added a delegate handler to TestSuite.TestSuiteStarting

Code: Select all

        <STAThread()>
        Function Main() As Integer
            ' Uncomment the following 3 lines if you want to automate Windows apps
            ' by starting the test executable directly
            'If Util.IsRestartRequiredForWinAppAccess Then
            '    Return Util.RestartWithUiAccess()
            'End If

            'Add to TestSuiteCompleted event handler to report test run information
            TestSuite.TestSuiteCompleted = DirectCast([Delegate].Combine(TestSuite.TestSuiteCompleted, New EventHandler(AddressOf TestSuite_TestSuiteCompleted)), EventHandler)
           TestSuite.TestSuiteStarting = DirectCast([Delegate].Combine(TestSuite.TestSuiteStarting, New EventHandler(AddressOf TestSuite_TestSuiteStarted)), EventHandler)
            
            Keyboard.AbortKey = System.Windows.Forms.Keys.Pause
            Dim errorNumber As Integer = 0

            Try

                errorNumber = TestSuiteRunner.Run(GetType(Program), Environment.CommandLine)

            Catch e As Exception
                Report.Error("Unexpected exception occurred: " + e.ToString())
                errorNumber = -1
            End Try

            Return errorNumber

        End Function
Then handler is as below:

Code: Select all

        Private Sub TestSuite_TestSuiteStarted(sender As Object, e As EventArgs)
            Validate.Fail("This is my Fail message")

        End Sub
This failure is not reflected on the Ranorex Report even though it is registered in the command window
ConsoleLog.png
But not in the Ranorex report
RanorexReportNoFail.png

Re: Validate TestSuite pre-conditions before running test cases

Posted: Wed Jul 13, 2016 11:15 am
by Support Team
Hi Douglas,

In order to analyze your issue in more detail, I would like you to send an email to [email protected] with a description of your problem and your compressed solution attached.

I'm looking forward to your email.

Kind regards,
Matthias

Re: Validate TestSuite pre-conditions before running test cases

Posted: Thu Jul 14, 2016 1:40 pm
by Vaughan.Douglas
Support Team wrote:Hi Douglas,

In order to analyze your issue in more detail, I would like you to send an email to [email protected] with a description of your problem and your compressed solution attached.

I'm looking forward to your email.

Kind regards,
Matthias
The email and attachment are being rejected as an unknown address.

Re: Validate TestSuite pre-conditions before running test cases

Posted: Thu Jul 14, 2016 2:59 pm
by Support Team
Hi Douglas,

Sorry for providing wrong information
Of course it's [email protected].

I'm looking forward to your email.

Sincerely,
Matthias

Re: Validate TestSuite pre-conditions before running test cases

Posted: Thu Jul 14, 2016 3:05 pm
by Vaughan.Douglas
I've sent it and it seems to have been received. Thank you!