Greetings! I wanted to get people's opinion on how people tend to store locators and global variables such as a username or password:
The three main web elements you may want to select for, are:
- Username textbox: id = username // username is tomsmith
- Password textbox: id= password // password is SuperSecretPassword!
- Login Button: cssSelector is [type='submit'][class='radius']
If you were using Selenium / Java and a Page Object, for instance, LoginPage.java, how would you best store the locators? Or the username and password global variables?
Would you store the global variables in:
- public static final String userName = "tomsmith"?
- public static final String password = "SuperSecretPassword!"?
I have also seen it as:
public enum UserEnum {
TOM_SMITH("tomsmith","SuperSecretPassword!");
String userName;
String password;
private UserEnum(String UserName, String Password){
this.userName=UserName;
this.password=Password;
}
public String getUserName(){
return userName;
}
public String getPassword(){
return password;
}
And for storing the locators, in LoginPage.java I have in the bottom of the class:
public enum LoginPageEnum {
USERNAME("[name='username']"),
PASSWORD("[name='password']"),
LOGIN_BUTTON("[type='submit'][class='radius']");
String id;
private LoginPageEnum(String Id){
this.id = Id;
}
public String getId(){
return id;
}
public By selector() {
return By.cssSelector(getId());
... How have you done it? I was just trying to compare notes, and figuring out the pros and cons of one test philosophy over another.
Right now, I am at the stage of learning that I am just ridiculously happy simply when the test runs!
- T.J. Maher
Sr. QA Engineer, Fitbit
// 15+ yrs manual tester, Automation Engineer for [ 3 ] months and counting