Validate TestSuite pre-conditions before running test cases

Class library usage, coding and language questions.
Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Validate TestSuite pre-conditions before running test cases

Post by Vaughan.Douglas » Fri Jul 08, 2016 3:05 pm

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.
Doug Vaughan

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Validate TestSuite pre-conditions before running test cases

Post by Support Team » Tue Jul 12, 2016 3:10 pm

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
.
Image

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: Validate TestSuite pre-conditions before running test cases

Post by Vaughan.Douglas » Tue Jul 12, 2016 3:25 pm

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
ConsoleLog.png (36.35 KiB) Viewed 881 times
But not in the Ranorex report
RanorexReportNoFail.png
RanorexReportNoFail.png (50.36 KiB) Viewed 881 times
Doug Vaughan

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Validate TestSuite pre-conditions before running test cases

Post by Support Team » Wed Jul 13, 2016 11:15 am

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
.
Image

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: Validate TestSuite pre-conditions before running test cases

Post by Vaughan.Douglas » Thu Jul 14, 2016 1:40 pm

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.
Doug Vaughan

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Validate TestSuite pre-conditions before running test cases

Post by Support Team » Thu Jul 14, 2016 2:59 pm

Hi Douglas,

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

I'm looking forward to your email.

Sincerely,
Matthias
.
Image

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: Validate TestSuite pre-conditions before running test cases

Post by Vaughan.Douglas » Thu Jul 14, 2016 3:05 pm

I've sent it and it seems to have been received. Thank you!
Doug Vaughan