Conditional If testcase fails then else
Posted: 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 NamespaceI 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