Conditional If testcase fails then else

Ask general questions here.
byonush
Posts: 7
Joined: Mon Mar 12, 2012 3:53 pm

Conditional If testcase fails then else

Post by byonush » Wed Sep 12, 2012 7:55 pm

I am currently working on automating all system checks for the service desk. I am trying to have the last test case view the previous test case and update a database table based on if the previous test failed or succeeded. I am able to get to update the database but having problems on the IF statement and where I need to be looking to grab the previous test case status. What I have in the last recording is a usercode in VB.
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Drawing
Imports System.Threading
Imports WinForms = System.Windows.Forms
Imports System.Data
Imports System.Data.SqlClient
Imports Console = System.Console

Imports Ranorex
Imports Ranorex.Core
Imports Ranorex.Core.Testing
Imports Ranorex.Core.Reporting

Namespace WDP_Check.CheckStatus

    Public Partial Class FinalStatus

       
        Dim con As New SqlConnection
        Dim cmd As New SqlCommand

       ''' <summary>
        ''' This method gets called right after the recording has been started.
        ''' It can be used to execute recording specific initialization code.
        ''' </summary>
        Private Sub Init()
            ' Your recording specific initialization code goes here.
        End Sub

        Public Sub FinalResuts()
        If (TestSuite.Current.GetTestCase("Launch_WDP_Report").Status.Success.Success) Then
        con.ConnectionString = "Data Source=PET1SQL;Initial Catalog=Staging;Integrated Security=SSPI" & ";"
        con.Open
        cmd.Connection = con
        cmd.CommandText = "UPDATE Systems_Check SET Status='Passed' WHERE Task='WDP'"
        cmd.ExecuteNonQuery()
        cmd.CommandText = "UPDATE Systems_Check SET DateTime= GETDATE() WHERE Task='WDP'"
        cmd.ExecuteNonQuery()
        con.Close()
        Else
        con.ConnectionString = "Data Source=PET1SQL;Initial Catalog=Staging;Integrated Security=SSPI" & ";"
        con.Open()
        cmd.Connection = con
        cmd.CommandText = "UPDATE Systems_Check SET Status='Failed' WHERE Task='WDP'"
        cmd.ExecuteNonQuery()
        cmd.CommandText = "UPDATE Systems_Check SET DateTime= GETDATE() WHERE Task='WDP'"
        cmd.ExecuteNonQuery()
        con.Close()
        End If
        End Sub
        

    End Class
End Namespace
I have also tried
Public Sub SetStatusPassed()
        If TestReport.CurrentTestSuiteActivity.Status.("Success") Then
        con.ConnectionString = "Data Source=PET1SQL;Initial Catalog=Staging;Integrated Security=SSPI" & ";"
        con.Open
        cmd.Connection = con
        cmd.CommandText = "UPDATE Systems_Check SET Status='Passed' WHERE Task='WDP'"
        cmd.ExecuteNonQuery()
        cmd.CommandText = "UPDATE Systems_Check SET DateTime= GETDATE() WHERE Task='WDP'"
        cmd.ExecuteNonQuery()
        con.Close()
        Report.Success("Database Updated as Passed")
        End If
        End Sub

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

Re: Conditional If testcase fails then else

Post by Support Team » Thu Sep 13, 2012 3:37 pm

Hi,

If you want to check the state from a previous test case you can use the following code:
ITestCase iCase = TestSuite.Current.GetTestCase("TestCase1"); // The name of your Test Case  
          if(iCase.Status == Ranorex.Core.Reporting.ActivityStatus.Failed){  
            Report.Info("TestCase1 Failed!");  
          }
If you want to check the state of the actual test case you have to place the following code in the tear down section of the test case:
if (Ranorex.Core.Testing.TestCase.Current.Status.Equals(Ranorex.Core.Reporting.ActivityStatus.Failed))
    //...
else
    //...
Regards,
Markus
Ranorex Support Team
.
Image

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Conditional If testcase fails then else

Post by omayer » Thu Jun 27, 2013 7:44 pm

ITestCase iCase = TestSuite.Current.GetTestCase("CompAddContact"); // The name of your Test Case
if(iCase.Status == Ranorex.Core.Reporting.ActivityStatus.Failed){
Report.Info("CompAddContact Failed!");
}

Following Error returned

The type or namespace name 'Current' does not exist in the namespace 'TestSuite' (are you missing an assembly reference?) (CS0234) - C:\..\TestCases\Company\CompanySendCheckedContactsAnEmailNoTemplate.cs:98,37
Tipu

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

Re: Conditional If testcase fails then else

Post by Support Team » Fri Jun 28, 2013 1:55 pm

Hi,

I checked the code but in my case it worked as expected. Are you sure you are using the right namespaces and assemblies?
Could it be that one of your classes is named "TestSuite"?

Regards,
Markus
.
Image

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Conditional If testcase fails then else

Post by omayer » Fri Jun 28, 2013 4:22 pm

My project name is "TestSuite" where I do execute all test cases
Tipu

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

Re: Conditional If testcase fails then else

Post by Support Team » Mon Jul 01, 2013 2:31 pm

Hello,

That's the reason for the error.
There is already a class in Ranorex defined with the name "TestSuite". Please choose another name for your project and your code should work.
Please do not use names in your project, which are already used in the Ranorex library.

Regards,
Bernhard
.
Image