3/06/2012

Flexible selecting item for listbox and radio group

For listbox and radio group, SelDotNet has implemented some useful methods, such as:
SelectByValue(value);
SelectByIndex(index);
SelectByText(text);
SelectFirstItem();
SelectLastItem();
AutoSelect();
Actually, it is not the most useful. Since, sometime you have to write much code like this.

if (testcase==AUTOSELECT_JOBTITLE)
jobTitle = Listbox("JobTitle").AutoSelect();
else
jobTitle = Listbox("JobTitle").SelectByText(aJobTitle);
to avoid this much waste of time, SelDotNet provide an alternative solution. By that, you just assign to jobTitle one of these value:
Listbox.FIRST_ITEM
Listbox.LAST_ITEM
Listbox.RANDOM_ITEM
Listbox.SELECT_NOTHING
Listbox.ITEM_INDEX + anumber

Example
void MakeTestData(TestCase testcase){
    MemberInfo member = MemberInfo.MakeStandardTestData();
    switch(testcase){

    case: EMPTY_JOBTILE:
         member.JobTitle =  Listbox.SELECT_NOTHING; 
    break;
    }
}

void SubmitData(MemberInfo member){
     ...
     //We dont need branching here
      Listbox("JobTitle Listbox").SelectByText(member.JobTitle);
      ...
}

No comments:

Post a Comment