I am doing test automation in C# inside Ranorex software.
I get the name of a button to click on from an XML file and the method :
string deviceName = device.SelectSingleNode("./ButtonInTTS").InnerText.Replace(" ", "");
I get a string whose name tells me which button to click in my application, then there is this method :
repo.TiTouchScreenApp.ToolbarListBox.Button.DoubleClick();
In fact in Ranorex you have the library of all the buttons and I need to change the name of Button to the result of deviceName.
For example if deviceName == “Automation”, it will do
repo.TiTouchScreenApp.ToolbarListBox.Automation.DoubleClick();
deviceName == “Temperature”
repo.TiTouchScreenApp.ToolbarListBox.Temperature.DoubleClick();
BUT I want to do this without a IF. Because I have a lots of button and I don’t want :
if(deviceName == "Automation"){
repo.TiTouchScreenApp.ToolbarListBox.Automation.DoubleClick();
} else if(deviceName == "Temperature") {
repo.TiTouchScreenApp.ToolbarListBox.Temperature.DoubleClick();
} etc etc...
Do you see a solution ?
If repo.TiTouchScreenApp.ToolbarListBox returns a list of control e.g. Buttons then do something like this :