1 year ago
#249460
tibhasha
How to read variables with same names from different lists
I'm new to the world of coding and this is my first post on stackoverflow. So please bear with me. So here's the problem.
I've got a list of variables for some text values in one language (denoted as EnglishList in the sample code below). and then another list using the same variable names but the values are different e.g. text translation in another language. (denoted as FrenchList in the sample code below).
I am writing an automated test in Java to set the value of some fields in my website.The values will need to be obtained from EnglishList first. Once the values are set, I want to set them to values obtained from FrenchList.
So basically, I have 2 questions:
- How do I define these EnglishList and FrenchList. I have declared them as a class in my sample code below but I am sure this is not the right way.
- How do I ensure the variables are read from the EnglishList and then from the FrenchList
Please note the is a very simplified version of what I'm trying to achieve. The number of languages, the number of variables in the lists and the number of tests/methods that need to be run in each language will be a lot more and hence the need to ensure I can modularise as much as I can.
import com.codeborne.selenide.SelenideElement;
import static com.codeborne.selenide.Selenide.$;
class EnglishList{
String text1= "Name";
String text2 = "JobTitle";
}
class FrenchList{
String text1= "FrenchName";
String text2= "FrenchJobTitle";
}
public class Test{
public void main() {
//I want to read values from EnglishList
setAndAssert(LangOption.ENGLISH);
//Now I want to read values from FrenchList
setAndAssert(LangOption.FRENCH);
}
private void setAndAssert(LangOption langOption){
//How to ensure the values of text1 and text 2 are obtained from correct language option...??
switch (langOption){
case ENGLISH:
// use EnglishList - How ? ;
break;
case FRENCH:
//use FrenchList - How ? ;
break;
}
//set and assert details based on the list chosen above
setName(text1);
setJob(text2);
//more code here to assert....
}
private void setName(String text){
SelenideElement field= $("#someId1");
field.setValue(text);
}
private void setJob(String text){
SelenideElement field= $("#someId2");
field.setValue(text);
}
enum LangOption{
ENGLISH,
FRENCH
}
}
java
list
modularization
0 Answers
Your Answer