Bind empty cells in a CSV file to bool Test variable.

Ranorex Studio, Spy, Recorder, and Driver.
Posts: 24
Joined: Thu Feb 06, 2014 10:57 am

Bind empty cells in a CSV file to bool Test variable.

Post by kshekharkumar » Tue Jun 24, 2014 11:02 am


We are using CSV test data file and binding some columns to boolean test variables.
But this binding throws run time exception when the cell is empty.

Failed to set value '' to variable 'ExecuteDynamic'.
String was not recognized as a valid Boolean.

at Ranorex.Core.Data.ReflectionDataProvider.SetValue(CaseInsensitiveString variableName, String value, Boolean exceptionOnFail) at Ranorex.Core.Data.ReflectionDataProvider.SetValue(CaseInsensitiveString variableName, String value) at Ranorex.Core.Testing.TestSuiteModule.RunInternal(DataContext parentDataContext)

Test variable declaration:
bool myExecuteDynamic = false;
public bool ExecuteDynamic
get { return myExecuteDynamic; }
set { myExecuteDynamic = value;}
Let me know if there is any way to achieve this.
EmptyBooleanVariable.jpg (75.49 KiB) Viewed 2052 times

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

Re: Bind empty cells in a CSV file to bool Test variable.

Post by krstcs » Tue Jun 24, 2014 1:51 pm

Ranorex stores and passes ALL values as strings, so the values "true" and "false" are strings and will not work in conditional statements. In order to use the "true" and "false" values as a boolean you need to convert them.

You will probably need to do this in user code.

Code: Select all

bool myBool = bool.Parse("true");

string boolAsString = "false";
bool stringAsBool = bool.Parse(boolAsString);
Shortcuts usually aren't...