Desperately trying to pass data from one iteration to next

Ranorex Spy, Recorder, and Studio.
carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Re: Desperately trying to pass data from one iteration to next

Post by carsonw » Tue Sep 25, 2012 8:45 pm

Hi there - hmm what do you mean when you say Test Case?

I want to pass data from iteration to iteration, is that a test case?

I've included a screenshot. I'm just passing data from iteration to iteration inside the highlighted area. If you believe this is possible, I can send over our solution. Thanks :)
Attachments
testcase.jpg
testcase.jpg (78.52 KiB) Viewed 2905 times

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

Re: Desperately trying to pass data from one iteration to next

Post by Support Team » Thu Sep 27, 2012 9:40 am

Hello,

I modified your example (solution2) from your first post and attached a little project. The source code is placed within the Recording1.UserCode.cs file. The value for the next iteration is set in the current iteration. The report file shows the table before the value for the next iteration is set and the table after setting the value.
I hope this is what you want to do.

Regards,
Bernhard
Ranorex Support Team
Attachments
SetDataForNextIteration.zip
(184.26 KiB) Downloaded 314 times
.
Image

carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Re: Desperately trying to pass data from one iteration to next

Post by carsonw » Fri Sep 28, 2012 4:32 pm

Hello, thank you so much for your efforts and the reply, but this does not solve our problem unfortunately.

I've already tried the solution you've suggested. In the example you've provided, you're directly updating the values in the dataconnector but that won't work for us. In our case we have to update the excel object and then feed that object back into the connector.

Here again is the reason why:

Imagine you have a test with 20 rows / iterations.

In the first iteration you get an orderID. Subsequent iterations have a cell reference (that's the key point) to the value in the first reference. Updating the dataconnector directly does not respect those references, it just has a the values themselves. This is my problem, and this is why I need to be able to update the object in memory (which I can already do), and then pass that object back into the connector (which I can't do).

So, my data would be like this:

Header Row:

Amount (A) OrderId (B)


Row:

1 100 12345
2 200 =B1


It's that =B1 that causes the problem. I would have to find all references and update them somehow which is not really feasible.

Although... I suppose I could update the excel object in memory, and then iterate through the excel columns and just overwrite all columns in the dataconnector (similar to your example but a bit more involved).

That COULD just do it... I'll try it and if it works I'll post back the code in case it's useful to other people.

Thanks again :)

carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Re: Desperately trying to pass data from one iteration to next

Post by carsonw » Wed Oct 17, 2012 12:03 am

Ok, I have figured it out now. The only thing I'm stuck on is how to update the bound variables for the current iteration so that they reflect the newly updated values. The subsequent iterations seem fine, but I need the current one to also work.

If you look at the attached screenshot, you will see that my bound variables match the TestCase.Current.DataContext.Source.Rows prior to the update rather than matching the TestCase.Current.DataContext.Source.Rows AFTER the update (in other words, the two red boxes match, where the bottom red box should match with the blue box).

I know that the data is there because I can see it in the TestCase.Current.DataContext.Source.Rows AND on the final iteration (i.e. Row #2 or Iteration #3), the Bound variables are the values in the green box (row #2).

This means that I was able to successfully update the TestCase.Current.DataContext.Source.Rows using an excel object while maintaining the fomulas, links etc. without having to save and reload the spreadsheet (yay! This is exactly what I wanted). Now I just need to know how to reload the variables for the current iteration so it will take the newly updated TestCase.Current.DataContext.Source.Rows.

Note that I tried all of the following, none of which was successful:

Code: Select all

//THIS DOES NOT REBIND THE DATA VARIABLES
				//Refresh the data connector so that any bound variables or other data is available immediately, rather than next iteration.				
				foreach (Ranorex.Core.Data.DataCache cache in TestSuite.Current.DataConnectorCaches)
				{					
					if(cache.Connector.Name == connector.Name)
					{
						cache.Load();
					}
				}
				
				//THESE ALSO DO NOT REBIND THE DATA VARIABLES
				
				TestCase.Current.DataContext.ReloadData();
				TestCase.Current.DataContext.Source.Load();
The weird thing is, I did get it to work ONCE with the foreach loop above. However once I moved it all into its own function it never worked again (even moving it back etc. I could not get it to work again). So I know it can be done "somehow".

Attached is a screenshot of the report with the coloured boxes, as well as a copy of the function. I will do more testing, but so far it's working :). Help on this last step would be greatly appreciated!

EDIT: Oh, just a point of interest because I saw it mentioned in another thread... I was using the EPLus Excel Library because I thought it would make my life easier (http://epplus.codeplex.com/) - it did not. It turns out that EPlus just takes the raw data as well, so when I updated the "excel" object using EPLus it just updated the single cell - there are no formulas or links etc. preserved so what I was trying to do was not possible with this plug in. I found that you HAVE to use the Microsoft one - the one that is included with Ranorex works just fine, that is what's used in my example.
ANOTHER EDIT: I just realized that I can't keep reloading the Excel object from the file whenever the method is caused because subsequent updates will wipe out previous updates. So I'm going to add a bit of code to keep the excel sheet in memory and only load it if it's not loaded previously. You only care about this if you plan on using this as an example, if not then don't worry about it! If there's interest, I can upload the newer version if not, that's fine too (or if you figure it out for yourself).
Attachments
UpdateIterationData.cs
(3.95 KiB) Downloaded 299 times
RefreshBoundVariables.jpg
RefreshBoundVariables.jpg (185.08 KiB) Viewed 2869 times

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

Re: Desperately trying to pass data from one iteration to next

Post by Support Team » Fri Oct 19, 2012 3:40 pm

Hello,

Thank you for your solution. Unfortunately it is not possible to use the value of the variable within the same module, but it should be possible to get the changed values in the next module. Please try to create a new module after your module and create new variables which are bound to the same data column as the variable in the original module. The updated value should be available there without loading the cache manually.

Regards,
Bernhard
Ranorex Support Team
.
Image

carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Re: Desperately trying to pass data from one iteration to next

Post by carsonw » Mon Oct 22, 2012 5:33 pm

Hi there - that's not quite what I was asking. What I was asking was how can I get the current iteration to refresh (or when you say module do you mean iteration - sometimes the language is confusing).

Everything is done within the same code module, and within the same test case. It's just that the bound variables for that iteration are not updated BUT the bound variables are updated on the next iteration.

So, somehow something happens on the next iteration (again same code module, same test case, just different iteration as in, the next row on the datasheet bound to that module) to load those values into the bound variables.

I just need to know how to load that myself for the current iteration - once I have that this will all work perfectly.

Thanks!

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

Re: Desperately trying to pass data from one iteration to next

Post by Support Team » Wed Oct 24, 2012 2:56 pm

Hello,

Sorry if my explanation wasn't clear.
I didn't mean iteration, I meant module. Please try to create a new recording module after your UpdateIterationData.cs module. The changed values should be available in the new module within the same iteration.

Regards,
Bernhard
Ranorex Support Team
.
Image

carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Re: Desperately trying to pass data from one iteration to next

Post by carsonw » Wed Oct 24, 2012 6:56 pm

Hmmm - either I'm not understanding what you're saying, or you're not understanding what I'm asking or it's a bit of both :)

There's no new module necessary or being created. Essentially my test is driven by a single code module that calls the UpdateIterationData method (in our test data class). Once that method is invoked, all the test data in the in the datarows are updated (this works fine, and it is updated for the current iteration as well) - but the variables bound to the code module I'm in aren't being updated for that iteration, however once it goes to the next (the next row of data in Excel), the variables are updated correctly.

I'm not wanting to create a new code module (we don't use recordings at all), or have anything execute anywhere else except in the current module.

Here's what the code to call the method looks like just from my code development suite (just used to test new classes). If I can't communicate it well enough here, I could send you my whole solution but it's pretty big.

Code: Select all

 //Testing overwriting test data.
            if (TestCase.Current.DataContext.CurrentRowIndex == 1)
            {
            	Ranorex.Core.Data.RowCollection testCollection = TestCase.Current.DataContext.Source.Rows;
            	
            	Reporting.LogInfoMessage("BEFORE update is applied");
            	for (int i = 0; i < testCollection.Count; i++)
				{
					Report.Info("Row #: " + i.ToString() + ": " + string.Join(",", testCollection[i].Values));
				}
            	
            	TestData.UpdateIterationData("Modifier", "5");
            	
            	Reporting.LogInfoMessage("AFTER update is applied");
            	for (int i = 0; i < testCollection.Count; i++)
				{
					Report.Info("Row #: " + i.ToString() + ": " + string.Join(",", testCollection[i].Values));
				}
			}
            if (TestCase.Current.DataContext.CurrentRowIndex == 2)
            {
            	Ranorex.Core.Data.RowCollection testCollection = TestCase.Current.DataContext.Source.Rows;
            	
            	Reporting.LogInfoMessage("BEFORE update is applied");
            	for (int i = 0; i < testCollection.Count; i++)
				{
					Report.Info("Row #: " + i.ToString() + ": " + string.Join(",", testCollection[i].Values));
				}
            	
            	TestData.UpdateIterationData("Modifier", "6");
            	
            	Reporting.LogInfoMessage("AFTER update is applied");
            	for (int i = 0; i < testCollection.Count; i++)
				{
					Report.Info("Row #: " + i.ToString() + ": " + string.Join(",", testCollection[i].Values));
				}
			}
            Reporting.LogInfoMessage("Bound Variables: " + TDValue + "," + TDModifier + "," + TDFinal);
At the end here:

Code: Select all

 Reporting.LogInfoMessage("Bound Variables: " + TDValue + "," + TDModifier + "," + TDFinal);
you can see my bound module variables. The "TDModifier" value is bound to the column in excel that I updated with the "TestData.UpdateIterationData("Modifier", "5");" method call. On the CURRENT iteration, this change is not reflected. However on subsequent iterations the change is reflected.

I hope that clarifies it enough. Really need to get this working. Thanks kindly! :D

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

Re: Desperately trying to pass data from one iteration to next

Post by Support Team » Tue Oct 30, 2012 4:02 pm

Hello,

In general Ranorex sets module variable values when the module is started and updates the data source variables when the module finishes. I am afraid it is not possible to realize it this way without breaking the design of Ranorex.
Another way to pass data from one iteration to the next one is to use 'Global Parameters'. For further information please read the section Additional Editing Options and Ranorex Test Suite
Sorry for the bad news.

Regards,
Bernhard
.
Image

carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Re: Desperately trying to pass data from one iteration to next

Post by carsonw » Tue Oct 30, 2012 11:25 pm

Ok, just so I understand:

Each time you iterate over a row of data, the module starts up, reads the module data, does something, then closes.

When it moves to the next item in the datasource, the module starts up again, does something, then closes again.

Is that right?

The datasource is static from each starting/stopping of the module, it does not reload from the sheet (this much I can see for sure).

So the issue for me is not passing iteration data from one iteration to the next, that works perfectly right now. The issue is changing the bound variables for the current iteration. The datasource is changed and works for the current and future iterations. Bound variables work for future iterations, it's bound variables for the current iteration.

If that is not possible then I don't know what to do. I do have to say that the excel implementation does feel quite limited and is frustrating to use at times. It's the weakest area of Ranorex (for us) right now and that's really unfortunately because it's such a critical part of the application.

My biggest concern is that what I'm trying to communicate is still not understood (again, I have no issue with passing data between iterations), and so I worry there is an answer if my question is understood.

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

Re: Desperately trying to pass data from one iteration to next

Post by Support Team » Wed Oct 31, 2012 5:47 pm

Hello,

I suggest to make an online meeting to avoid additional communication problems. You should have received an e-mail with possible time slots for an online session with Roland. I hope we can help you to solve your issue this way.

Regards,
Bernhard
.
Image

User avatar
iskrenpp
Posts: 11
Joined: Fri Aug 17, 2012 4:36 am

Re: Desperately trying to pass data from one iteration to next

Post by iskrenpp » Tue Mar 11, 2014 9:29 pm

hi, I have been in your position and here is the solution that works for me in many different cases:

I simply store the value that I need to reuse in a global parameter during run time and re-use when /where needed.


1. Create a global parameter - it does not matter if it has value or not. In some cases you may assign it a default value which can be used until it is updated. IMPORTANT: global parameters are updated and stay updated only during run time. Once the test stops they are again equal to their default value or null if are blank by default.

2. Store the value to pass for one iteration to another with this code. (it should always be converted to string before assigning to global parameter)

TestSuite.Current.Parameters["exactCaseAsCreatedGlobalParameter"]=valueToPassToAnotherIteration.ToString();

3. Then you can retrieve it in any other iteration and pass accordingly with

valueFromGlobalParameter=TestSuite.Current.Parameters["exactCaseAsCreatedGlobalParameter"];

lucian.teodorescu
Posts: 82
Joined: Fri Oct 24, 2014 10:58 am
Location: Bucharest

Re: Desperately trying to pass data from one iteration to next

Post by lucian.teodorescu » Thu Feb 05, 2015 2:18 pm

This is the KEY: global parameters are strings!
I wish I could read this before in User Guide.

Thank you very much for this post.
Lucian Teodorescu
NetSun Software