Page 1 of 1

How to get a list of ALL test cases

Posted: Mon Jul 18, 2016 7:15 pm
by fester13579
Hello,

I need to use an external application/process to trigger my tests cases, so I want this application to call the Ranorex project EXE so it can then specify the test case name to run and its parameters.


In order to do this I need to generate a list of ALL the test cases (regardless if they are checked or not) in my suite that I can then parse, do some logic on then run as needed.

I've read some of the threads in the forum and I am just going round and round.

Could someone please post a working project (VB if possible) that dumps all of the test case names to a text file that I can look at? ( Dim Me = "n00b programmer" )


I wish this was just a built in function of any Ranorex project binary EG: Project.exe /ListAllTestCases but that does not seem to be the case unless I am missing something or there is a hidden switch somewhere.


I am running 6.0.1.

Thanks.

Re: How to get a list of ALL test cases

Posted: Mon Jul 18, 2016 8:52 pm
by Vega
I have come up with a quick solution for you to try, though it is utilizing C# rather than VB.net.

The below code will pull all active test cases and log them to a file in your output directory called "TEST_CASE_LIST.txt". The first thing you need to do is to make all test cases active(checked). I know this goes against your request, but this only has to be done once so that we can generate our list. The easiest way to do this is by creating a new run configuration and make every single test case active. You can find out about run configurations http://www.ranorex.com/support/user-gui ... suite.html

Once you have all test cases active, create a new test case at the very top of your test suite with a blank recording module. Add a user code method with the following:

Code: Select all

using (StreamWriter writer = new StreamWriter("TEST_CASE_LIST.txt"))
		{
			foreach(var testCase in TestSuite.Current.SelectedRunConfig.GetActiveTestCases())
			{
				writer.WriteLine(testCase.Name);
			}
		}
Validate.Fail();
Make sure this test case's error behavior is set to stop on fail, we don't want to run through everything.

Re: How to get a list of ALL test cases

Posted: Mon Jul 18, 2016 9:21 pm
by N612
Here is a code snippet that will report all test cases and does not matter if the test case is enabled or not. You can change to output to a text file if that is what you prefer.

VB

Code: Select all


Dim TS As TestSuite = DirectCast(TestSuite.Current, TestSuite)
Dim ss As IList(Of TestSuiteEntry) = TS.GetAllTestSuiteEntries()
For Each x As TestSuiteEntry In ss
	If x.[GetType]() = GetType(TestCaseNode) AndAlso Not x.DisplayName.Contains("Test Suite") Then
		Report.Info(x.DisplayName)
	End If
Next
C#

Code: Select all

TestSuite TS = (TestSuite)TestSuite.Current;
IList<TestSuiteEntry> ss =TS.GetAllTestSuiteEntries();
foreach(TestSuiteEntry x in ss)
{
	if(x.GetType()== typeof(TestCaseNode) && !x.DisplayName.Contains("Test Suite"))
		Report.Info(x.DisplayName);
}

Re: How to get a list of ALL test cases

Posted: Mon Jul 18, 2016 9:48 pm
by fester13579
Thank you both!!! I now have what I needed. :D

Re: How to get a list of ALL test cases

Posted: Tue Aug 07, 2018 4:43 am
by Jugaadi-ram
Hi
I am trying to run the use the same code as N612 in C# but I am getting an error at line of assignment of IList with GetAllTestSuiteEntries().

Here is the error :-

Object reference not set to an instance of an object.
Show/Hide Stacktrace
at Ranorex_SmokeTest.UserCodeCollection1.allTestCaseList() in D:\Study stuff\Ranorex Projects\Dump\03-08-2018 Only greys issue\Test Case numbers updated\UserCodeCollection1.cs:line 1268 at SmokeTestNoah.Creation_of_Copy_CSV_and_Report_File.Ranorex.Core.Testing.ITestModule.Run() in D:\Study stuff\Ranorex Projects\Dump\03-08-2018 Only greys issue\Test Case numbers updated\Creation_of_Copy_CSV_and_Report_File.cs:line 173 at Ranorex.Core.Testing.TestModuleLeaf.RunInternal(DataContext parentDataContext, Int32 iteration, Int32 iterationCount, Boolean skipIteration)

Please guide me, so as to what could be wrong. Thanks in advance.
JR

Re: How to get a list of ALL test cases

Posted: Thu Aug 09, 2018 2:36 am
by Support Team
Hi Jugaadi-ram,

Make sure you are running this from the test suite. If run by itself, it will fail since there is no "current" test suite to read the test containers from.

Code: Select all

TestSuite TS = (TestSuite)TestSuite.Current; 
				       🡅
Cheers,
Ned

Re: How to get a list of ALL test cases

Posted: Sat Feb 10, 2024 10:39 pm
by shidernatalia
I am new to Ranorex, could you please explain in detail how to run the piece of code that is provided above in this thread? Should it be inside a method in any class that is in the test suite, that would be invoked as a step in any test case? Thank you.