Conditional If testcase fails then else

Ranorex Studio, Spy, Recorder, and Driver.
syildiz
Posts: 2
Joined: Thu Mar 03, 2022 1:33 pm

Conditional If testcase fails then else

Post by syildiz » Thu Mar 03, 2022 1:47 pm

Hi all,
We are working on a WPF desktop automation project. We have created a framework consisting of 60 heavy cases. The application itself has some performance issues, so due to waits or some unavailable services, tests may fail at any steps, which are really hard to guess. Ideally, we should open and close the app for each test, but it almost doubles the execution time since it takes almost one minute for the app to load. In short, I am looking for some method which will do the following:
If the test case fails, then close the app and open it again, else continue with the next case.

I found this method from the forum but it was written in 2012 and is now obsolete (https://www.ranorex.info/conditional-if ... t3791.html)

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

Alternatively,

if (Ranorex.Core.Testing.TestCase.Current.Status.Equals(Ranorex.Core.Reporting.ActivityStatus.Failed))
//...
else
//..

Does anyone know a current method for this?

Thanks in advance.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Conditional If testcase fails then else

Post by odklizec » Thu Mar 03, 2022 4:22 pm

Hi,

I think this code should do the trick...

Code: Select all

var iCase = TestSuite.Current.GetTestContainer("TestCase1"); // The name of your Test Case
if (iCase.Status.Equals(Ranorex.Core.Reporting.ActivityStatus.Failed))  
{  
    Report.Info("TestCase1 Failed!"); 
}  
else
{
...
}
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

syildiz
Posts: 2
Joined: Thu Mar 03, 2022 1:33 pm

Re: Conditional If testcase fails then else

Post by syildiz » Fri Mar 04, 2022 2:45 pm

Thanks for the response. But in this code, I will need to write always the previous test case name by hardcoding. The order of the cases may change in time and it will cause my code not to run. Like in the code below, it should take the current test case dynamically. Is that possible?

if (Ranorex.Core.Testing.TestCase.Current.Status.Equals(Ranorex.Core.Reporting.ActivityStatus.Failed))
//...
else
//..