Get Ranorex to output a text file with pass/fail

Class library usage, coding and language questions.
cdmartinus
Posts: 8
Joined: Wed Jul 03, 2013 11:21 am

Get Ranorex to output a text file with pass/fail

Post by cdmartinus » Wed Jul 10, 2013 2:47 pm

Hi,

I am trying to get Ranorex to output a simple text file with pass or fail on the first line but I can't work out how to output the text file or store the test result and print it to a line in the text file.

Thanks

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Get Ranorex to output a text file with pass/fail

Post by krstcs » Thu Jul 11, 2013 1:24 pm

This is a .NET base feature, so you will need to familiarize yourself with .NET.

http://msdn.microsoft.com/en-us/library/

Check out the IO library under .NET Development specifically.
Shortcuts usually aren't...

cdmartinus
Posts: 8
Joined: Wed Jul 03, 2013 11:21 am

Re: Get Ranorex to output a text file with pass/fail

Post by cdmartinus » Mon Jul 15, 2013 12:19 pm

Thanks for the response!

I've now managed to get it to create a output a file with any text I want, including the data stored in a string variable.

However I'm struggling to store the pass/fail result of my test in a string that I can output.

orbistest
Posts: 23
Joined: Mon Oct 17, 2011 5:31 pm

Re: Get Ranorex to output a text file with pass/fail

Post by orbistest » Wed Jul 17, 2013 10:52 am

I came across some code in another thread which may help you - I have to admit I have not had much time to think this over but here it is.
ITestCase iCase = TestSuite.Current.GetTestCase("TestCase1"); // The name of your Test Case
if(iCase.Status == Ranorex.Core.Reporting.ActivityStatus.Failed){
Report.Info("TestCase1 Failed!");

I think you can see the principle of using the ActivityStatus to get what you need.

Hope that helps.

cdmartinus
Posts: 8
Joined: Wed Jul 03, 2013 11:21 am

Re: Get Ranorex to output a text file with pass/fail

Post by cdmartinus » Wed Jul 17, 2013 12:03 pm

That's perfect, problem solved. Thanks!!!

Code: Select all

        public static void Output()
        {    
        	string result = "";
        	ITestCase iCase = TestSuite.Current.GetTestCase("AddUser"); // The name of your Test Case 
			if(iCase.Status == Ranorex.Core.Reporting.ActivityStatus.Failed){ 
        		result = "Failed"; }
        	if(iCase.Status == Ranorex.Core.Reporting.ActivityStatus.Success){ 
        		result = "Passed"; }
        	int testrunID = 79;
        	
        	using (StreamWriter writer =
        	       new StreamWriter("testresult.txt"))
        	{
        		writer.WriteLine(testrunID);
        		writer.WriteLine(result);        		
        	}
        }