sel2/src/test/java/ru/ibs/tests/LoginPage.java
Александров Александр Владимирович c9ecb2466a v2-2 Page Object
2025-06-23 23:48:16 +03:00

40 lines
1.3 KiB
Java

package ru.ibs.tests;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;
public class LoginPage {
private final WebDriver driver;
private final WebDriverWait wait;
@FindBy(id = "prependedInput")
private WebElement usernameInput;
@FindBy(id = "prependedInput2")
private WebElement passwordInput;
@FindBy(xpath = "//button[@type='submit']")
private WebElement loginButton;
public LoginPage(WebDriver driver) {
this.driver = driver;
this.wait = new WebDriverWait(driver, Duration.ofSeconds(10));
PageFactory.initElements(driver, this);
}
public DashboardPage login(String username, String password) {
wait.until(ExpectedConditions.visibilityOf(usernameInput)).clear();
usernameInput.sendKeys(username);
wait.until(ExpectedConditions.visibilityOf(passwordInput)).clear();
passwordInput.sendKeys(password);
wait.until(ExpectedConditions.elementToBeClickable(loginButton)).click();
return new DashboardPage(driver);
}
}