Page 1 of 1

Get Ranorex to output a text file with pass/fail

Posted: Wed Jul 10, 2013 2:47 pm
by cdmartinus
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

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

Posted: Thu Jul 11, 2013 1:24 pm
by krstcs
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.

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

Posted: Mon Jul 15, 2013 12:19 pm
by cdmartinus
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.

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

Posted: Wed Jul 17, 2013 10:52 am
by orbistest
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.

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

Posted: Wed Jul 17, 2013 12:03 pm
by cdmartinus
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);        		
        	}
        }