Start a testcase - pass name as parameter

Ranorex Studio, Spy, Recorder, and Driver.
jsmith
Posts: 36
Joined: Mon Mar 05, 2018 4:03 pm

Start a testcase - pass name as parameter

Post by jsmith » Tue Sep 04, 2018 11:05 am

Hi there,
I want to start a test module via user code, but I want to reuse this method, so I want to pass the test module name in as a string, and have whatever that string is, run. My attempt so far is this:

public static void Run_a_test(string test_name)
{
string test_name = "Base_walkthru.Blocks.MSOfficeExport";
var execute = "Base_walkthru." + test_name;


//Base_walkthru.Blocks.MSOfficeExport.Start(); //correct implementation without parameterisation
execute.Start();
}


Unsurprisingly this doesn't work as the var needs casting to a module.
Can anyone advise how to go about this?

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

Re: Start a testcase - pass name as parameter

Post by odklizec » Tue Sep 04, 2018 11:34 am

Hi,

May I ask why do you want to run the test case via code? I mean, what's wrong with the test suite? I would personally use a combination of test suite and configurations, in which you can define what test cases should be run.

As far as I know, there is no public way to start the test case via code. All you can do is to start the test case via command line.
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

jsmith
Posts: 36
Joined: Mon Mar 05, 2018 4:03 pm

Re: Start a testcase - pass name as parameter

Post by jsmith » Tue Sep 04, 2018 12:49 pm

Hi Pavel,
My apologies, I have crossed two terms. I am trying to start a test module. Throughout many of my tests, I am repeating approx 100 lines of code, in this particular case, to test an export to MS Office feature. Recently I wanted to make a two line amendment to this section, and then need to roll it out across x number of uses. Instead, I have copied the 100 lines to a new test module. Now I need only change the code in one place, and call it in many places.
Hence, I have created the run_a _test user code method to execute any one test module. But I can see it would be useful to choose which module I want to run, without having to create another variation of run_a_test. Thus, I want a parameter, and to have the method start whatever test module I point it at.

I hope this helps clarify what I am trying to do, and I hope you can help me achieve it.

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

Re: Start a testcase - pass name as parameter

Post by odklizec » Tue Sep 04, 2018 1:17 pm

Hi,

I understand. But I'm afraid, this is not possible. The only thing you can probably do is to create a condition in your code module and then start the hardcoded module based of the condition? Something like this...

Code: Select all

public static void Run_a_test(string test_name)
{
  if (test_name == "AAA")
  {
    Base_walkthru.Blocks.ModuleA.Start(); 
  }
  else if (string test_name == "BBB")
  {
    Base_walkthru.Blocks.ModuleB.Start(); 
  }
}
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

jsmith
Posts: 36
Joined: Mon Mar 05, 2018 4:03 pm

Re: Start a testcase - pass name as parameter

Post by jsmith » Tue Sep 04, 2018 2:25 pm

Thank you Pavel, I shall use this approach.