Get the list of test case names back.

Class library usage, coding and language questions.
qphan613
Posts: 4
Joined: Fri Sep 21, 2018 9:29 pm

Get the list of test case names back.

Post by qphan613 » Fri Sep 21, 2018 9:56 pm

Image

Hello,

I'm trying to get a list of the test case names that are active. However, I can't seem to get the right information back. I keep getting one item with the name "SpaceTRAXbuild" whereas I'm expecting to get two items back with names "Create_and_log_into_New_Department" and "Initial_inventroy"

Below is the code I came up with after looking through multiple posts on this forum and Ranorex's API reference page.

Code: Select all

TestSuite ts = new TestSuite("SpaceTRAXbuild");
                TestSuiteRunConfig tsrc = new TestSuiteRunConfig("Build_Single_Test", ts);
                ts.Run();
                
                var entries = TestSuite.Current.SelectedRunConfig.GetActiveTestContainers();
                foreach(var entry in entries)
                {
                    var testcase = entry as TestCaseNode;
                    if(testcase != null)
                    {
                        //I get one entry back only and the Name is "SpaceTRAXbuild"
                        string testcaseName = testcase.Name;
                        
                    }

                }
               
You do not have the required permissions to view the files attached to this post.

User avatar
RobinHood42
Posts: 324
Joined: Fri Jan 09, 2015 3:24 pm

Re: Get the list of test case names back.

Post by RobinHood42 » Mon Sep 24, 2018 7:29 am

Hi,

I came up with the following code. I hope this helps.
var suite = (TestSuite) TestSuite.Current;
			IList<TestSuiteEntry> entries = suite.GetAllTestSuiteEntries();
			
			//Remove TestSuite entry, since it's recognized as a TestCaseNode
			entries.RemoveAt(0);
			
			foreach(var entry in entries)
			{
				var testcase = entry as TestCaseNode;
				
					if(testcase != null && testcase.Checked)
				{
					string testcaseName = testcase.Name;
					Report.Info("User","Active TestCase:" + testcaseName);
				}
			}
Cheers,
Robin :mrgreen:

qphan613
Posts: 4
Joined: Fri Sep 21, 2018 9:29 pm

Re: Get the list of test case names back.

Post by qphan613 » Fri Sep 28, 2018 4:43 pm

Thanks Robin,

I forgot to mention one important factor is I'm running this code within my NUNIT in Visual Studio and not inside Ranorex. Therefore right now when I run it, TestSuite.Current is NULL; I imagine if you run the c# code inside Ranorex then this is already populated with the proper object.

So I wonder what I need to do to get this object pre-populated. This is why you see in my code I attempted to load the Test suite name and the run configuration name.

User avatar
RobinHood42
Posts: 324
Joined: Fri Jan 09, 2015 3:24 pm

Re: Get the list of test case names back.

Post by RobinHood42 » Mon Oct 01, 2018 11:37 am

Hi,

Well it doesn't matter which IDE you use to run your test, but it does matter if you're executing your code within your Ranorex test run or outside of it.

I'm not sure what want to check. There is no current TestSuite or "SelectedRunConfig" outside the Ranorex test run. Maybe you could provide further information.

Looking forward to hearing back from you.

Cheers,
Robin

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

Re: Get the list of test case names back.

Post by odklizec » Mon Oct 01, 2018 12:24 pm

qphan613 wrote:
Fri Sep 28, 2018 4:43 pm
Thanks Robin,

I forgot to mention one important factor is I'm running this code within my NUNIT in Visual Studio and not inside Ranorex. Therefore right now when I run it, TestSuite.Current is NULL; I imagine if you run the c# code inside Ranorex then this is already populated with the proper object.

So I wonder what I need to do to get this object pre-populated. This is why you see in my code I attempted to load the Test suite name and the run configuration name.
Hi,

It seems as if your test suite has been developed in Ranorex Studio and now you are trying to run the tests via Ranorex and Visual Studio integration? I'm afraid, If you are using Visual Studio, many of the Ranorex goodies are not available in VS, for example repository (*.rxrep) and test suite (*.rxtst). In other words, the code you are trying to use is only useful, if the test is started from Ranorex Studio, Ranorex Test Suite runner or command line, but not if the individual test modules are started from VS.
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

qphan613
Posts: 4
Joined: Fri Sep 21, 2018 9:29 pm

Re: Get the list of test case names back.

Post by qphan613 » Mon Oct 01, 2018 9:02 pm

My QA Team created a Ranorex project with over 40 test cases.
I want to incorporate these into my continuous build/deployment process in TFS Team Service or Azure DevOps.

In order to do this, I implement a NUnit wrapper in Visual Studio where I can call the Ranorex test case outside of Ranorex using Ranorex's API.
I got this working already as per the sample code below:

Code: Select all

[TestMethod]
        public void Item_Summary_Current_Histroy()
        {
            RunRanorexTestCase("Item_Summary:_Current_Histroy");
        }
		
		public void RunRanorexTestCase(string tc)
        {
            int error = 0;

            try
            {
                error = TestSuiteRunner.Run(typeof(SpaceTRAXbuild.Program), @"..\RanorexTestBuild.exe /rc:Build_Single_Test /zr /zrf:Reports/Report.rxzlog /tc:" + tc);
        

            }
            catch(Exception ex)
            {
                Report.Error("Unexpected exception occurred: " + ex.ToString());
                error = -1;
            }

            if (error != 0)
                throw new Ranorex.RanorexException("Test run failed! See report.rxzlog for further details! :" + error.ToString());
        }

However, I don't want to manually maintain 40 test cases and that is why I want to parse the Ranorex project to get the list of all active test case names so I can invoke them via my NUnit test. This is the reason why I don't do this C# code from within the Ranorex's IDE.

User avatar
RobinHood42
Posts: 324
Joined: Fri Jan 09, 2015 3:24 pm

Re: Get the list of test case names back.

Post by RobinHood42 » Tue Oct 02, 2018 8:58 am

Hi,
However, I don't want to manually maintain 40 test cases and that is why I want to parse the Ranorex project to get the list of all active test case names
Based on what? At this point in time, there is no active test case. You're just about to start them afterwards.

Cheers,
Robin

qphan613
Posts: 4
Joined: Fri Sep 21, 2018 9:29 pm

Re: Get the list of test case names back.

Post by qphan613 » Tue Oct 02, 2018 3:09 pm

Hi Robin,

Perhaps "active" is not the right word, I don't mean the test case that are "currently running". What I meant is all the test cases that should be run in a test suite within a particular run configuration.

For example in the screenshot below, if I select the run configuration "Build Single Test" then want to get the list of all the test cases in the test suite that have the check mark (2 in the screenshot), aka the test cases that will be executed as part of the selected run configuration.

Image
You do not have the required permissions to view the files attached to this post.

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

Re: Get the list of test case names back.

Post by odklizec » Tue Oct 02, 2018 3:29 pm

Hi,

As mentioned, information about the test suite/test cases and run configurations is stored in rxtst file, which is only useful in Ranorex Studio and Ranorex test suite runner (or if the test is started from command line)! So if you really need to get the name of test cases from test suite and using Visual Studio, you will have to parse the rxtsts file. But to be honest, I don't know how this information will be useful for you, since the rxtst file (which means the whole test suite and its run configs) is not useful in VS? But maybe I'm missing something important? ;) Could you please elaborate, what exactly do you want to achieve or why you need to use VS? Honestly, using VS will not speed the development of your tests. In contrary, you will have to handle many things in code, which are perfectly covered by Test Suite and Repository.
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