Output a text file from Ranorex to include just a pass/fail result and a number

StackOverflow https://stackoverflow.com/questions/17649755

  •  03-06-2022
  •  | 
  •  

Question

I am trying to get Ranorex to output a text file which will look like the following:

Pass
74

The pass/fail result will be obtained based on whether the test running has passed or failed. The number will be hardcoded to all I need to do is store that in a variable and include it in the output.

I would have thought it would have been simple but I'm struggling to get any help from Ranorex. I though I might be able to use the reporting function, change the output file type and alter the report structure but that didn't work either.

Although I am used to Ranorex and writing my own user code, I am new to adapting it in this way.

All my user code is written in C#

Can anyone offer any assistance?

Thanks!


Edit: So I've now managed to get Ranorex to output a text file and I can put any text into it, including a string stored in a variable.

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

Was it helpful?

Solution

I've discovered a way to do this however it relies on the following:-

  • The user code must be in separate test
  • This separate test must exist in a sibling test case to the one your main test is in
  • Both this test case and the case containing your main test must both be part of a parent test case

For example:

Parent TC
.....-AddUser TC
.........-MAIN TEST
.....-AddUser FailCheck
.........-USER CODE

You can then set your AddUser TC to 'Continue with sibling on fail'

The user code is as follows:

    public static void Output()
    {    
        string result = "";
        ITestCase iCase = TestSuite.Current.GetTestCase("Add_User_Test"); // 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);               
        }
    }

This will take the testrunID (specific to each test case) and the result of the test and output it to a text file.

The idea is then to read in the file with a custom java application I've developed and push the data into a test case management program such as QA Complete which can mark tests as Passed/Failed automatically

OTHER TIPS

You can run the test suite directly using the TestSuiteRunner.Run() method. This will allow you to look at the return value of that directly and output pass or failure based on the return value.

http://www.ranorex.com/Documentation/Ranorex/html/M_Ranorex_Core_Testing_TestSuiteRunner_Run.htm

if(TestSuiteRunner.Run(typeof({testSuiteclass}),{Command Line Arguments})==0)
{
    File.WriteLine("success");
}
else
{
    File.WriteLine("failure");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top