Change Data Source without re-bind all variables

Best practices, code snippets for common functionality, examples, and guidelines.
lucian.teodorescu
Posts: 82
Joined: Fri Oct 24, 2014 10:58 am
Location: Bucharest

Change Data Source without re-bind all variables

Post by lucian.teodorescu » Mon Nov 16, 2015 4:42 pm

Hi,

I've tried to find an answer on forum, but didn't succeed. Please redirect if this is a duplicated question.

In one of my [rather small] solution I use an Excel Data Connector. There are over 1k bindings.
There comes the time when I need to change the data source to a CSV file. (I need to run the tests on XP on a virtual machine, where Excel is not installed).
So the columns, variables, values are all the same but different file. Changing data source makes all 1000 variables unbound. Moreover, changing back to the Excel connector does not fix the bindings as they were in the beginning.

So the question is: how to change the data source without manually doing all the bindings? (Auto-Bind is not working)? As I said, all data is the same, only the file format is different.

Ranorex 5.4.2 (I can update to 5.4.3, but will this solve the issue?)

Thanks
Lucian Teodorescu
NetSun Software

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

Re: Change Data Source without re-bind all variables

Post by odklizec » Mon Nov 16, 2015 4:51 pm

Hi,

I think your only hope is to directly edit rxtst file?

Just open it in a good text editor (notepad++, pspad, etc...), find dataConnector(s), in which you want to replace excel with csv file and replace type from type="Ranorex.Core.Data.ExcelDataConnector" to type="Ranorex.Core.Data.CSVDataConnector" and of course filename with csv file you want to use instead of excel file.
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

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

Re: Change Data Source without re-bind all variables

Post by lucian.teodorescu » Mon Nov 16, 2015 5:17 pm

Hi Pavel,

I carefully made the changes, but it leads to "TestSuite XML format is invalid." error (see attachment for detailed error).
Attachments
Capture.PNG
detailed error
Capture.PNG (52.77 KiB) Viewed 1338 times
Lucian Teodorescu
NetSun Software

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Change Data Source without re-bind all variables

Post by krstcs » Mon Nov 16, 2015 6:04 pm

Due to the way Ranorex handles objects behind-the-scenes, there is really no way to do this outside of manually re-binding the variables to the new data-sources in Studio or the Test Suite Runner (which is essentially the same as Studio, but only allows you to edit the suite file - "*.rxtst").


**** I would strongly caution against directly editing the XML! ****

The issue is that Ranorex uses GUIDs to uniquely identify all objects, including variables and data sources. If you try to re-use the same GUIDs, you will get unexpected results. If you try to create new ones, you will need to manually make sure the GUIDs are all in sync, which is more work than just manually re-binding the variables.


EDIT TO ADD:
On a personal note, this is one of the (many!!) reasons that I will never use XLS files for my data. You can do exactly the same thing with CSV without the overhead and hassle.

I would also say that if you plan out how you want the tests to get their data in the future pretty thoroughly then this transition would be a one-time-cost.
Shortcuts usually aren't...

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

Re: Change Data Source without re-bind all variables

Post by lucian.teodorescu » Tue Nov 17, 2015 9:17 am

I agree with you on that directly editing the XML should not be a wise option.

But I also think that there should be an option to change the data source without losing all the bindings. I mean it should keep those which share the same variable-value pair.
Or at least a warning that once it is changed, it cannot be undone. (Thankfully I had everything checked in VCS before starting to mess with data sources and XML).

May this be an input for a feature request? If you have any thoughts on it and want to share, you are welcome.
Lucian Teodorescu
NetSun Software

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Change Data Source without re-bind all variables

Post by krstcs » Tue Nov 17, 2015 4:19 pm

First, all feature requests should be made via email. They don't handle feature requests from the forums any longer.

Second, Ranorex 6.0 will be changing the way data connectors are handled at the core of the Ranorex system, from what I hear, so I would reserve any requests in that area until 6.0 is out (which I'm hoping is SOON!!! :D ).
Shortcuts usually aren't...

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

Re: Change Data Source without re-bind all variables

Post by odklizec » Wed Nov 18, 2015 9:19 am

While I agree with Kelly that it's not a very good idea to directly edit rxtst file, there are times when it's very handy to make some changes directly in xml (like multi-rename of something or replacing data sources). As long as the file is backed-up before editing, one makes sure the file is correctly formatted and GUIDs are left intact, there is nothing to worry about ;)

As for the original request, I think the reason of the error is incorrectly formatted file, because I made a mistake in my suggestion ;) I've suggested replacing 'filename' with link to csv, but this is not correct. You must entirely delete the filename attribute (along with few more excel-related attributes) and add <file> tag, as shown in this screenshot...
Excel2CSV.png
Excel2CSV.png (50.17 KiB) Viewed 1299 times
If you are cereful and you change everything as suggested in the screenshot, data connectors should be correctly replaced and variables kept binded. At least it worked for me. Hope this helps?
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