Junior — Middle
Have you used methods of data retrieval through getters in your projects?
sobes.tech AI
Answer from AI
Yes, getters are often used in test automation projects to retrieve the values of object fields or interface elements.
Getters help encapsulate access to data, which simplifies maintenance and modification of the code. For example, if you need to get the text from an input field on a page, you can use a getter method that returns the current value of that field.
Example in Java for Selenium:
public class LoginPage {
private WebDriver driver;
public LoginPage(WebDriver driver) {
this.driver = driver;
}
public String getUsername() {
return driver.findElement(By.id("username")).getAttribute("value");
}
}
This approach improves test readability and makes them easier to maintain.