Page Object HeroPattern

  • Cel: oddzielenie logiki interakcji z elementami strony od kodu testów.
  • Korzyści: ułatwia utrzymanie testów przy zmianach w UI.
public class LoginPage {
    private WebDriver driver;
    public LoginPage(WebDriver driver) { this.driver = driver; }
    public void login(String user, String pass) {
        driver.findElement(By.id("username")).sendKeys(user);
        driver.findElement(By.id("password")).sendKeys(pass);
        driver.findElement(By.id("loginBtn")).click();
    }
}