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

Ranorex Spy, Recorder, and Studio.
kshekharkumar
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

Hi,

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.

Exception:
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;
[TestVariable("0B935733-C432-47AF-A7F0-F7F9AC6445E6")]
public bool ExecuteDynamic
{
get { return myExecuteDynamic; }
set { myExecuteDynamic = value;}
}
Let me know if there is any way to achieve this.
Attachments
EmptyBooleanVariable.jpg
EmptyBooleanVariable.jpg (75.49 KiB) Viewed 1256 times

krstcs
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...