I have xml file with specific steps and actions that have to be performed on html controls:
<Item control="Dropdown" action="Click" value=""/>
<Item control="Button" action="GetText" value=""/>
<Item control="Input" action="WriteText" value="Sample Text"/>
There is a lot of controls that I will use and each control has several methods like Click, GetText, Exsists..
Currently I use switches to deal with it, but I heard that this is not a good practice. I have one switch to select specific control and also each control has switch to call specific method.
switch (control)
{
case "button":
return new Button;
case "table":
return new Table;
(...)
}
(...)
switch (action)
{
case "click":
this.Click();
return true;
case "gettext":
this.GetText();
return true;
default:
return false;
}
I don’t have much experience with coding so I’m not sure whether it is good way to deal with this problem. Could you give me some suggestions how to do it better? Maybe there are some coding patterns which could be helpful here?
you could create a class for each type of control you have
and then when you read the XML