Page 1 of 1

How to get booelans from an external data-source like Excel

Posted: Fri Apr 22, 2016 4:02 pm
by Mudhenn
Hello

I need to test an Web-App where the user can fill out different forms to request something. This works that way, that after some initial things he can check up to three checkboxes where each one enables another part of the form.

I created recording modules for every sub-form and want to switch them on and off dependend on some data in an sheet of some kind, so that I can set up different scenarios, where the user fills out part 1 and 3 for example.

So far I had some success with something like this:

Code: Select all

TestSuite.Current.GetTestCase("AN-EINVERA").Checked = Var_AN_EINVERA
My problem is, that for some reason, Ranorex seems to no longer accept my Booleans from Excel.

I changed the variable-generation-part that was done by Ranorex as so:

Code: Select all

 Dim _Var_AN_EINVERA As Boolean = False
        <TestVariable("C2E085E5-5EF9-4D06-841A-9CBE7FAE1D79")> _
        Public Property Var_AN_EINVERA As Boolean
        	Get
        		Return _Var_AN_EINVERA
        	End Get
        	Set(ByVal value As Boolean)
        		_Var_AN_EINVERA = value
        	End Set
        End Property
and for some time it worked well. I bound the data to an sheet in an excel-file but now, after I added some more excel-sheets and finished enough recorder-modules to test everything, it doesn't work anymore, the variables are sat false all the time, no matter what I try, even when I changed it to a simple data table inside ranorex, the value stay false.

Has anybody some tipps for me or maybe another way to check or uncheck recording-modules in accordance to some external data? ( I even tried csv, but no difference)

TIA,
Frank

PS: Please excuse my bad english, I'm no native speaker.

Re: How to get booelans from an external data-source like Excel

Posted: Mon Apr 25, 2016 9:51 am
by odklizec
Hi Frank,

I don't think you can change the variable type of module variable (connected to data connector) to boolean? The data connectors always return data as 'string', regardless of their format in data connector file (e.g. Excel cell format). So the variable connected to data connector must be string as well. You will have to change the variable type to expected type just before you wish to use it as a different type.

Re: How to get booelans from an external data-source like Excel

Posted: Mon Apr 25, 2016 11:56 am
by Mudhenn
Thank you for your advice! I changed the code as follows:

Code: Select all

        Dim _Var_TF_AN_ESSEN As String = "True"
        <TestVariable("D32AD5CB-8916-4928-BEB3-25FEDB64A9BE")> _
        Public Property Var_TF_AN_ESSEN As String
        	Get
        		Return _Var_TF_AN_ESSEN
        	End Get
        	Set(ByVal value As String)
        		_Var_TF_AN_ESSEN = value
        	End Set
        End Property
        
        ''' <summary>
        ''' Constructs a new instance.
        ''' </summary>
        Public Sub New()
            ' Do not delete - a parameterless constructor is required!

            TestSuite.Current.GetTestCase("AN-ESSEN").Checked = Convert.ToBoolean(Var_TF_AN_ESSEN)

        End Sub
This works as far as it converts the default value to an boolean and enables or disables the testcase according to the default-value of the variable. Sadly it doesn't seem to get some data from the excel-sheet, it stays always on the default-value. Is there a difference on how to load variables with data to the way it is done in "normal" recordings? In normal recordings I use variables all the time with no fuzz but in thar piece of code everything seems to be a bit different...

Thanks in advance & have a nice day!

Re: How to get booelans from an external data-source like Excel

Posted: Mon Apr 25, 2016 12:12 pm
by odklizec
Hi,

I'm not quite sure what exactly you mean with this:
"Sadly it doesn't seem to get some data from the excel-sheet, it stays always on the default-value."
Could you please be a bit more specific?
Which data exactly are not obtained from Excel?

If a module variable does not load a value from data connector, then my guess is that it's either not connected correctly, or you started the module without running entire test suite? Please upload your solution (with related excel file), so we can check your test suite configuration, variable binding and scripts, where you want to use the binded variables.

Re: How to get booelans from an external data-source like Excel

Posted: Mon Apr 25, 2016 12:38 pm
by Mudhenn
odklizec wrote:Hi,

I'm not quite sure what exactly you mean with this:
"Sadly it doesn't seem to get some data from the excel-sheet, it stays always on the default-value."
Could you please be a bit more specific?
Which data exactly are not obtained from Excel?
None for this .vb-module. The other recordings work fine (except from one format-problem which I postet here). The value of my variable doesn't change from the default-value regardles of what I change in the bound excel-sheet.
odklizec wrote: If a module variable does not load a value from data connector, then my guess is that it's either not connected correctly, or you started the module without running entire test suite? Please upload your solution (with related excel file), so we can check your test suite configuration, variable binding and scripts, where you want to use the binded variables.
It is connected (and says so in the overview) and I run the whole project as I know that in single-runs only default values are used.

I can upload it but I have to find some webspace for it. Is there anything I should know about what to upload?

Re: How to get booelans from an external data-source like Excel

Posted: Tue Apr 26, 2016 9:00 am
by odklizec
Hi,

Ideally, zip and upload entire solution directory, without bin, obj and reports folders.

Re: How to get booelans from an external data-source like Excel

Posted: Tue Apr 26, 2016 9:33 am
by Mudhenn
Hello

I sent you the links to the files as a pm.

Thanks again for your time!

best regards,
Frank

Re: How to get booelans from an external data-source like Excel

Posted: Tue Apr 26, 2016 10:04 am
by odklizec
Hi Frank,

I've checked the solution and the first thing I noticed is that the excel file is loaded from shared folder? In my opinion, this could a reason why the variables load incorrect values, even after you change and re-save the source file. It's definitely not recommended to use shared folders for data sources! I personally noticed that the edited files from shared folders are not updated immediately. It's a 'windows' thing ;)

Please try to use a local path instead. If it does not help, please let me know, which variables exactly (and in which modules) are using default values, instead of the values loaded from connected data source.

Re: How to get booelans from an external data-source like Excel

Posted: Tue Apr 26, 2016 1:28 pm
by Mudhenn
Solution to this Problem: I placed my code in the sub "new" which is the wrong one. Thanks to Pavels (oklizec) help I learned that it has to be placed under "Run", I did that and it worked!

Thank you very much for your help!