I work as an automation engineer for my company. Recently, I wrote a piece of code that my manager absolutely did not accept.
I was asked to write several scripts for test cases involving different parts of the GUI. Part of the code that my manager did not accept was an expression if/elsedesigned to check the current hint language in the GUI.
I was instructed to use Sikuli, and therefore it is very important that I know what language the application is currently configured so that my scripts can click on the correct buttons (which vary depending on the language).
My thoughts were that the code iterates through the instruction if/elseand then points to the correct button. Example: the operator if/elsedetermines that the "ok" button is currently a Suomi translation, so it will be than clicking on the right button.
Here is an example of my code:
switch (button) {
case "ok":
if (s.exists("imagerepo/language/catalan_ok.png") != null) {
s.click("imagerepo/language/catalan_ok.png");
} else if (s.exists("imagerepo/language/suomi_ok.png") != null) {
s.click("imagerepo/language/suomi_ok.png");
} else if (s.exists("imagerepo/language/italian_ok.png") != null) {
s.click("imagerepo/language/italian_ok.png");
} else if (s.exists("imagerepo/language/portuguese_ok.png") != null) {
s.click("imagerepo/language/portuguese_ok.png");
} else if (s.exists("imagerepo/language/english_ok.png") != null) {
s.click("imagerepo/language/english_ok.png");
} else if (s.exists("imagerepo/language/dutch_ok.png") != null) {
s.click("imagerepo/language/dutch_ok.png");
} else if (s.exists("imagerepo/language/spanish_ok.png") != null) {
s.click("imagerepo/language/spanish_ok.png");
} else if (s.exists("imagerepo/language/french_ok.png") != null) {
s.click("imagerepo/language/french_ok.png");
} else if (s.exists("imagerepo/language/latina_ok.png") != null) {
s.click("imagerepo/language/latina_ok.png");
} else if (s.exists("imagerepo/language/chinese_ok.png") != null) {
s.click("imagerepo/language/chinese_ok.png");
}
break;
...etc..
My only problem with the code above is that it is pretty ugly. Functionally, he does exactly what I would like, in 100% of cases.
EDIT: I believe that having a switch that adapts to a potentially changing button would be better than having 10 switches for the same button. Perhaps, against what I just said, if I write scripts, I will always know what language the system will be in.
, , "" ?
, , , , , if/else ?