import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.io.IOException;
import java.util.Map;


public class TestSafeway {

  Map<String, String> props = new GetAccountProperties().getProps();
  String email = props.get("email");
  String password = props.get("password");
  String firstName = props.get("firstName");
  String lastName = props.get("lastName");

  public TestSafeway() throws IOException {
  }


  private static String getOS() {
    return System.getProperty("os.name");
  }

  @Test
  public void testSafewayLogin() {
    if (getOS().startsWith("Mac OS")) {
      System.out.println("mac");
      System.setProperty("webdriver.chrome.driver", "src/main/resources/chromedriver");
    }

    WebDriver driver = new ChromeDriver();
    WebDriverWait waiter = new WebDriverWait(driver, 5);
    driver.get("https://www.safeway.com");

    HomePage homePage = new HomePage(driver);
    homePage.openRightNav();

    RightNavBar rightNavBar = new RightNavBar(driver);
    rightNavBar.openLogin();

    LoginPage loginPage = new LoginPage(driver);
    loginPage.login(email, password);

    waiter.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Account")));
    homePage.openRightNav();
    rightNavBar.accountSettingsLink.click();

    waiter.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Account Settings")));
    AccountSettingsPage accountSettingsPage = new AccountSettingsPage(driver);
    accountSettingsPage.confirmLogin(firstName, lastName, email);



  }

}




