import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class LoginPage {
  WebDriver driver;
  WebElement nameInput;
  WebElement passInput;
  WebElement submitBtn;

  public LoginPage(WebDriver driver) {
    this.driver = driver;
  }


  public WebElement getNameInput() {
    return driver.findElement(By.xpath("//input[@name='userId']"));
  }

  public WebElement getPassInput() {
    return driver.findElement(By.name("inputPassword"));
  }

  public WebElement getSubmitBtn() {
    return driver.findElement(By.id("btnSignIn"));
  }

  public WebDriverWait getWaiter() {
    return new WebDriverWait(this.driver, 5 );
  }

//  public void navigate(String url) {
//    this.driver.get(url);
//  }

  public void login(String username, String password) {

    getWaiter().until(ExpectedConditions.visibilityOfElementLocated(By.id("btnSignIn")));

    getNameInput().sendKeys(username);
    getPassInput().sendKeys(password);
    getSubmitBtn().click();
  }
}
