How to: Plug custom data source in?

Class library usage, coding and language questions.
AdamHepner
Posts: 7
Joined: Thu Oct 20, 2011 1:55 pm

How to: Plug custom data source in?

Post by AdamHepner » Thu Oct 20, 2011 2:12 pm

I'm working on an interesting project, for migration of existing test cases to Ranorex.

Existing tests are very strongly data-driven (it's basically one huge script with multiple flows possible, depending on a complex data configuration). With every run, the testers specify tests/configurations by numbers, and they are loaded from a custom-build excel files.

What I want to do, is to run the Ranorex script, have it dynamically load the configuration, and then load the test cases from the excel files. I wish not to use the standard ExcelDataSource, because I need extra functionality (complex filtering), so I figured out I'd write my own DataSource. I just can't seem to find a way to actually make my test cases use the said data source.

Can I get a little customer love here? :roll:
Adam Hepner
REC Solutions sp. z o.o.

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: How to: Plug custom data source in?

Post by Ciege » Thu Oct 20, 2011 3:54 pm

If you’re comfortable writing some code you can use the Excel Interop object. You can then interact with Excel through a COM object and read/write to excel on a whim.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

AdamHepner
Posts: 7
Joined: Thu Oct 20, 2011 1:55 pm

Re: How to: Plug custom data source in?

Post by AdamHepner » Thu Oct 20, 2011 5:38 pm

Excel Interop is not the problem. The problem is, that I'd like to be able to do something along this pseudo-code:

Code: Select all

TestCase c = new TestCase();
c.Setup.Add(new SetupModule1());
c.Setup.Add(new SetupModule2());
c.Add(new CodeModule1());
c.Add(new CodeModule2());
c.BindDataSource(new CustomDataSource());
TestCaseRunner.Run(c);
As far as I know, Ranorex currently doesn't provide such functionality?
Adam Hepner
REC Solutions sp. z o.o.

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

Re: How to: Plug custom data source in?

Post by Support Team » Fri Oct 21, 2011 1:20 pm

Hi,

Ranorex provides such functionality, but as Peter wrote http://www.ranorex.com/forum/how-to-dyn ... tml#p10987 it is not recommended and therefore not documented.
For such reasons we have developed the Ranorex Studio where you can logically split your tests into the test suite and test cases.

Regards,
Markus
Ranorex Support Team
.
Image

AdamHepner
Posts: 7
Joined: Thu Oct 20, 2011 1:55 pm

Re: How to: Plug custom data source in?

Post by AdamHepner » Mon Oct 24, 2011 9:10 am

Ok, so maybe I'll rephrase my question, to present a different aspect of what I want to achieve.

Assumptions:
- there's a more than one datapool. They are stored in excel files, but, as they are shared between various tools, they are not "pure data" - there's a lot of metadata, noise, additional information, split across several worksheets in a several workbooks. The data does not start in the first row, nor in the second - it varies from sheet to sheet. The format cannot be altered, because it is used by several different tools at the same time.
- the datapool contains usually several thousand test cases / fixtures, each of which contains at least a few hundred variables. Each fixture is stored in a single row. But the information about which columns contain relevant data (which variables are actually set) is stored somewhere in this row as well (again, it can be resolved on test run-time)
- the user specifies a datapool to use not at design time, but at run-time, via a configuration file (and they want to keep it that way)
- on test does not utilize all the testcases from a single datapool. User specifies (via a conf file again, and to be kept that way) numbers of testcases to be run. So it's something like: use datapool X, and run testcases 100 to 110 and 678 to 2100 out of 4021, but don't run the number 2000.
-workflow to be tested is fairly simple. It's just a series of UI-related actions, like "fill given form and click OK, verify result on the next screen"... but: depending on data configuration in a single fixture (which is resolved at run-time, not at a design time!), some steps are skipped, some steps are done only one time, and some steps are executed several times. The skipped steps should not be displayed in the report. There's only one workflow specified, but it has potentially huge number of variations, so it is not feasible to specify each one by hand in GUI.

And to make things harder, the customer have specifically selected your product :).

I could potentially just throw everything in one huge usercode module, and just run this against all the testcases in datapool, selectively ignoring unrelevant entries, and making enormous log entries, but I have a gutfeeling that it will be neither nice, nor reusable, nor extendable, and I want to provide the customer with a high-end solution that they can expand as they will. I don't care if your internal API is difficult to use, I aim to wrap it in another abstraction layer, to provide a DSL. And yes, I do have programming experience, so it's not that much of a challange. I just need a starting point, and/or code sample.

Again, I want to do two (fairly simple) things:
-feed a custom-designed data source into a testcase. I've already found a way to construct a custom data source, I just have nowhere to shove it into :)
-construct a testcase on the fly from existing recording and/or code modules. I've figured it partly out (I can run test modules and test cases programmatically), but it's a little bit too little. If I had access to an artificial TestCase object, I could configure at initialization time, I could push relevant code modules (dynamically bound to variables from testcase fixture) to setup, testcase and teardown sequences. Just - how do I do it?
Adam Hepner
REC Solutions sp. z o.o.

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: How to: Plug custom data source in?

Post by Ciege » Mon Oct 24, 2011 8:41 pm

Forgive me for being daft but with your experience and what you are looking for it sure sounds like to me you want to be writing your own engine for handling all your datapools. You really dont need to use the SetupModule/CodeModule concept, but rather have your own engine designed to run the tests based on your datapool inputs.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

AdamHepner
Posts: 7
Joined: Thu Oct 20, 2011 1:55 pm

Re: How to: Plug custom data source in?

Post by AdamHepner » Tue Oct 25, 2011 9:21 am

Well, no :). I want to do almost exactly the same things that I can do in the Ranorex Studio. I just want to do them programmatically. I like the way that the tests are layed out in Ranorex, and I'd love to be able to use that. I just need to
-filter the data input programmatically at runtime
-dynamically change/create the content of a testcase
-programmatically bind the data source columns to variables in test modules

Is it possible that you provide me with a proof of concept, or any reference on how should I attempt to do it?
Adam Hepner
REC Solutions sp. z o.o.

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

Re: How to: Plug custom data source in?

Post by Support Team » Tue Oct 25, 2011 2:21 pm

Hi,
AdamHepner wrote: Is it possible that you provide me with a proof of concept, or any reference on how should I attempt to do it?
Attached you will find a small sample how to use the API to create a Test Suite with Data Binding. It is not really re-factored so maybe it is a bit hard to read. But you said you have coding experience, therefore it shouldn't be the challenge for you. :)
Just bring up to your mind again. As already said in the other post listed above, this is a not documented API and this is normally out of support. It can also happen that this API changes internally and then your script is broken.

Hopefully this is what you need.

Regards,
Peter
Ranorex Team
Attachments
CreateTestSuitewithAPI.7z
(24.74 KiB) Downloaded 365 times
.
Image

AdamHepner
Posts: 7
Joined: Thu Oct 20, 2011 1:55 pm

Re: How to: Plug custom data source in?

Post by AdamHepner » Thu Oct 27, 2011 2:18 pm

Great! This is exactly what I had in mind, and it had helped me greatly. I have come about another problem, which I don't seem to understand: creation of setup and teardown modules.

I mean, the TestSuiteModule class has a property ExecType, of type ModuleExecType, which contains values Setup, Execute and Teardown. I assumed that this is what I'm looking for, especially that the said property does have a setter available. However, whenever I try to set the ExecType to anything, then Ranorex fails to add such module to the global list, saying that an id (randomly generated) already exists. It is almost as if it tried to add the same module twice for some reason. What is the correct way of setting the execution type of a module?
Adam Hepner
REC Solutions sp. z o.o.

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

Re: How to: Plug custom data source in?

Post by Support Team » Thu Oct 27, 2011 3:53 pm

Hi,
AdamHepner wrote:What is the correct way of setting the execution type of a module?
After the
testSuite.AddEntryAndDescendantsToGlobalList(testSuite.TestSuiteEntry);
you can set the module type by setting the ExecType
testModule.ExecType = ModuleExecType.Teardown;
Regards,
Peter
Ranorex Team
.
Image

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

Re: How to: Plug custom data source in?

Post by Support Team » Tue Apr 24, 2012 3:20 pm

Hi,

This code doesn't work with Ranorex 3.2.3, because the API changed a little bit.
It will run again after editing the following line of code:
use:
testSuite.AddEntryAndDescendantsToGlobalList(testCase);
instead of:
testSuite.AddEntryAndDescendantsToGlobalList(testSuite.TestSuiteEntry);
Regards,
Markus
Ranorex Support Team
.
Image

bindusamira
Posts: 2
Joined: Wed Jul 09, 2014 7:46 pm

Re: How to: Plug custom data source in?

Post by bindusamira » Mon Jul 14, 2014 9:58 pm

Hi

I am looking for something similar . Tried code on 5.02 and it failed .Can you please help me

Thanks in advance

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

Re: How to: Plug custom data source in?

Post by Support Team » Fri Jul 18, 2014 1:23 pm

Hello bindusamira,

May I ask you to explain your issue as detailed as possible? This would really help us in analyzing your issue.

Thank you in advance.

Regards,
Robert
.
Image