Possible to Call ModuleGroups within Code?

Class library usage, coding and language questions.
anja
Posts: 67
Joined: Fri Nov 26, 2010 3:39 pm

Possible to Call ModuleGroups within Code?

Post by anja » Wed Jul 11, 2012 8:32 am

Hi,

within the installing scenario of our software under test, there are two possibilities...
1. Install the .Net 4.0 Framework first
2. Installation of .Net 4.0 Framework not needed because already installed

The installation of the .Net Framework is covered by several Codemodules, which are grouped to a module group.

Is it possible to call this module group from within a codemodule? I would be great to have this possibility because I can use the same testcase for both scenarios....

Thank you in advance

Best regards
Anja

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Possible to Call ModuleGroups within Code?

Post by Support Team » Thu Jul 12, 2012 3:17 pm

Hi Anja,

This is unfortunately not yet possible, but you can directly call the specific recordings of the module group in User Code.
YourRecording.Start();
I will add an issue to our internal system, we will discuss if we will implement such a feature.

Regards,
Markus
Ranorex Support Team
.
Image

orbistest
Posts: 23
Joined: Mon Oct 17, 2011 5:31 pm

Re: Possible to Call ModuleGroups within Code?

Post by orbistest » Mon Sep 03, 2012 4:55 pm

Sorry if I am a bit slow in this but can you give me the declaration for the recording.

A few lines of code which would allow me to run a specific rxrec or test case would really help me but I am not a .net programmer.

I know I need to declare the recording as a new object and then somehow populate this with the real object details.
For example, I would love to do: -

Dim myTestCase As New TestCase()
myTestCase = Ranorex.Core.Testing.ITestSuite.GetTestCase( argument2 )
myTestCase.Run()

where argument2 is the name of the test case e.g. "RunWhenFalse".

If I could do this and then jump to a specific test case to continue in the suite, the I could implement the much needed "if this is not true ... do x" in my user code.

For example I could pass the ranorexpath of an object which I want to exist and two test case names.
I could the do a FindSingle to see if the object exists and if so execute one of the cases if not execute the other using the code above.

Dare I say that One of your competitors products makes this very simple as it has a built in IF ... then ... else to control case execution based upon many types of validation.

Thanks.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Possible to Call ModuleGroups within Code?

Post by Support Team » Tue Sep 04, 2012 2:49 pm

Hi,

In general such a "RunWhenFalse" construct is not recommended, there are some ways how you can manually execute specific test cases or recordings, but as I said it is not the recommended way.
I attached a solution where you can see how it works.
You can execute specific Recordings in code with the following code:
YourRecording.Start();
Here is also a link to a similar topic: Plug custom data source in.
Again we don't recommend mixing up the Ranorex test suite with code which executes/creates specific test cases, this is not really/officially supported.
We suggest either using the test suite or creating the whole test structure in code, but it is not recommended to mix it up.
You can for instance create your test structure, in VS, with the following code:
RecordingModule rec = RecordingModule.Instance;
rec.NewVariable = "Test Value";

TestReport.Setup(ReportLevel.Info, "MyReport.rxlog", true);

TestReport.BeginTestSuite("MySolution");
TestReport.BeginTestCase("myTestCase");
TestReport.BeginTestModule("Recording");
TestModuleRunner.Run(rec);
        
TestReport.EndTestModule();
TestReport.EndTestCase(TestResult.Passed);
Regards,
Markus
Ranorex Support Team
Attachments
TestCasePerCode.zip
(318.47 KiB) Downloaded 395 times
.
Image

orbistest
Posts: 23
Joined: Mon Oct 17, 2011 5:31 pm

Re: Possible to Call ModuleGroups within Code?

Post by orbistest » Thu Sep 20, 2012 3:22 pm

Thanks for the helpful code.
I have now set up a piece of user code (called from a single line recording) which checks for existence of a particular dialog box using a repository object (the titlebar).
If the object exists it calls a recording to fill in the dialog and if not - simply carries on.
Previously we had to make all the login box actions "continue on fail" which meant they were all being attempted and thus taking time to fail. Now the existence of the dialog is the only item which has to timeout.

BTW I use object.selfinfo.exists() to do the check which is really simple and uses the OBJECT search timeout and so is easy to set.

I have tried this with deliberate failures due to renaming objects in the second recording and Ranorex stops gracefully. So, no problems for me, even though I know it is not "good" practice.

Hermch
Posts: 40
Joined: Thu May 26, 2011 7:17 am
Location: Germany

Re: Possible to Call ModuleGroups within Code?

Post by Hermch » Mon Oct 15, 2012 11:49 am

I also would be very happy about this functionality, to call ModuleGroups from Code-modules.

About when will this be possible?

Thanks!

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Possible to Call ModuleGroups within Code?

Post by Support Team » Tue Oct 16, 2012 5:20 pm

Hi,

We have not yet decided if we should add such a functionality or not, because in our opinion it should not be necessary if the tests are well structured.
If this should be really essential for you could you post us a basic UseCase of a situation which couldn't be handled in any other way?

Regards,
Markus
Ranorex Support Team
.
Image

anja
Posts: 67
Joined: Fri Nov 26, 2010 3:39 pm

Re: Possible to Call ModuleGroups within Code?

Post by anja » Wed Oct 17, 2012 7:15 am

Hi,

here is my use case where it is neccessary for me:
During the automated installation of my Application under Test it is neccessary to have the .Net 4.0 Framework installed. On some PCs it is neccessary to install it during the test execution, on others it is already installed.

What I've now is following:
Code Module: start installation
Module Group: install .Net Framework (here is not only one code module in)
Code Modules to execute the installation of my application

If I execute the Testcase on a PC where no .Net 4.0 is installed it is working.
If I want to execute the Testcase on a PC where .Net is already installed, it is not working. Here it would be neccessary to run the code module only under a defined precondition --> If I could call the module group from within code this would be easy to do.

This is only one example where it would be nice to have this feature...

Hermch
Posts: 40
Joined: Thu May 26, 2011 7:17 am
Location: Germany

Re: Possible to Call ModuleGroups within Code?

Post by Hermch » Wed Oct 17, 2012 8:57 am

Hi,

my usecase:

The running testcase clicks through my gui. After some time, a popup message is shown.
When this popup is shown, a modulegroup (or a testcase) with serveral recordings and code modules inside needs to be started.

This could easily be done, if it would be possible to start modulegroups from usercode.
otherwise I need to start every single recording one by one from the current code module.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Possible to Call ModuleGroups within Code?

Post by Support Team » Thu Oct 18, 2012 3:39 pm

Hello,

We have discussed this feature internally, but unfortunately this feature is not planned for Ranorex in the future. This would make problems with the reporting and would cause too many changes in Ranorex basics.
Sorry about this bad news.

Regards,
Bernhard
Ranorex Support Team
.
Image

macgowan
Posts: 14
Joined: Mon Jun 23, 2014 9:20 pm

Re: Possible to Call ModuleGroups within Code?

Post by macgowan » Mon Jun 23, 2014 10:00 pm

Hi

This is an 'old' thread with not much since 2012 ...

Is Ranorex now supporting the ability to call methods in other classes (Code Modules) ?? I would be interested to know if this is supported.

The Use Case I have was recommended by Ranorex as a workaround to a bug related to Flash/Flex. It was suggesed to us to load the flex widget prior to actaully using it in the test process. This loads some data into the browser (IE 8) cache. During the workaround process - there are times when Ranorex will not recognize a flex object and we have been instructed to close the object and try again.

There are some utility classes that are used to CleanData ... so it would be nice to be able to instantiate thee classes and call the methods (.Run) ...

Here is what I'd like to do ...

Below is a sample utility class. I'd like to call this from another CodeModule - see below.

Code: Select all

namespace SummaryRegression.CodeModules
{
    /// <summary>
    /// Removes all summaries for current artifact being used in test  
    /// </summary>
    [TestModule("D8413E73-6B7F-4B63-9CCA-22C011D6402C", ModuleType.UserCode, 1)]
    public class CleanupData : SummaryBase, ITestModule
    {
        public CleanupData()
        { }

        void ITestModule.Run()
        {
        	Report.Info("Removing all summaries in artifact with UUID = " + ArtifactUuid);
        	SummaryRestClient client = new SummaryRestClient();
        	client.deleteSummariesForArtifact(ArtifactUuid);
        }
    }
}
Here is the code module - we are testing and when we fail - I'd like to call the code above to Cleanup Some data --- and then some other classes to reload the Widget and such fun ... The error handling below is not complete - will probably use try/catch ... I have added peudocode where we might back to the call.

Code: Select all

        private bool ExecuteWorkaround()
        {
        	bool returnVal = true; 
        	
            int retryCount = 0; 
            int retryLimit = 3;

            // Add a Headnote
            
            while (retryCount < retryLimit)
            { 
		       	Report.Info("Add new Headnote.");
	            SummaryRegressionRepository.Instance.JSA.Features.CreateNewDropdown.Click();
	            SummaryRegressionRepository.Instance.JSA.Features.AddNewHeadnote.Click();
	            SummaryRegressionRepository.Instance.Alert.OKButton.Click();
	            
	            if (!waitForVisible(SummaryRegressionRepository.Instance.JSA.Headnote.X, "Headnote didn't open"))
	            {
					// Headnote didn't open - will try again
			       	Report.Info("Fail: Headnote didn't open. RetryCount: " + retryCount + " of " + retryLimit);
			       	
			       	// We are going to close the browser and then start over 
			       	// with a new session. Not sure if this is a good idea - as we cleared the 
			       	// browser cache 
			       	
			       	// Note in most cases the headnote is visible and Ranorex failed to find the 
			       	// item that is used to close it - I think our only option in this case 
			       	// would be to close the browser and start again. 
			       	
			       	// Instantiate the CleanupData class and call the Run method 
			       	
			       	CleanupData cleanupData = new CleanupData(); 
			       	cleanupData.Run(); 
			       	
		        	returnVal = false; 
	            }
	            else
	            {
			       	Report.Info("Headnote opened successfully. RetryCount: " + retryCount + " of " + retryLimit);
			       	Report.Info("Close the Headnote widget. (wait 3 sec)");
 					System.Threading.Thread.Sleep(3000); 	
            		SummaryRegressionRepository.Instance.JSA.Headnote.X.Click();
	            	break; 
	            }
            	
            	retryCount++; 
            } 
            
            return returnVal; 
        	
        }


That's it ... thanks for reading.
Looking forward to your comments / suggestions.

Thanks,
Chris