Commit d2acb5ae authored by Darrick Yong's avatar Darrick Yong

refactor property helper and implicit wait

parent 3f6c1d29
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class AccountSettingsPage {
WebDriver driver;
WebDriverWait waiter;
@FindBy(how = How.ID, using = "input-firstName")
WebElement firstNameInput;
......@@ -24,10 +29,14 @@ public class AccountSettingsPage {
public AccountSettingsPage(WebDriver driver) {
this.driver = driver;
// this.waiter = new WebDriverWait(this.driver, 5);
PageFactory.initElements(driver, this);
}
public void confirmLogin(String firstName, String lastName, String email, String phone) {
// this.waiter.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Account Settings")));
assertAll("First name, last name, and email should match account props",
() -> assertEquals(firstName, firstNameInput.getAttribute("value")),
() -> assertEquals(lastName, lastNameInput.getAttribute("value")),
......
......@@ -6,12 +6,11 @@ import org.openqa.selenium.support.ui.WebDriverWait;
public class LoginPage {
WebDriver driver;
WebElement nameInput;
WebElement passInput;
WebElement submitBtn;
WebDriverWait waiter;
public LoginPage(WebDriver driver) {
this.driver = driver;
this.waiter = new WebDriverWait(this.driver, 5);
}
public WebElement getNameInput() {
......@@ -26,17 +25,19 @@ public class LoginPage {
return driver.findElement(By.id("btnSignIn"));
}
public WebDriverWait getWaiter() {
return new WebDriverWait(this.driver, 5 );
}
// public WebDriverWait getWaiter() {
// return new WebDriverWait(this.driver, 5 );
// }
public void login(String username, String password) {
getWaiter().until(ExpectedConditions.visibilityOfElementLocated(By.id("btnSignIn")));
// this.waiter.until(ExpectedConditions.visibilityOfElementLocated(By.id("btnSignIn")));
getNameInput().sendKeys(username);
getPassInput().sendKeys(password);
getSubmitBtn().click();
this.waiter.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Account")));
}
}
......@@ -24,11 +24,9 @@ public class GetAccountProperties {
throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");
}
res.put("email", props.getProperty("email"));
res.put("password", props.getProperty("password"));
res.put("firstName", props.getProperty("firstName"));
res.put("lastName", props.getProperty("lastName"));
res.put("phone", props.getProperty("phone"));
props.stringPropertyNames().forEach(prop -> {
res.put(prop, props.getProperty(prop));
});
} catch (Exception e) {
System.out.println(e);
......
import helpers.GetAccountProperties;
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;
import java.util.concurrent.TimeUnit;
public class TestSafeway {
......@@ -31,7 +29,7 @@ public class TestSafeway {
}
WebDriver driver = new ChromeDriver();
WebDriverWait waiter = new WebDriverWait(driver, 5);
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
driver.get("https://www.safeway.com");
HomePage homePage = new HomePage(driver);
......@@ -43,11 +41,9 @@ public class TestSafeway {
LoginPage loginPage = new LoginPage(driver);
loginPage.login(email, password);
waiter.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Account")));
homePage.openRightNav();
rightNavBar.openAccountSettings();
waiter.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Account Settings")));
AccountSettingsPage accountSettingsPage = new AccountSettingsPage(driver);
accountSettingsPage.confirmLogin(firstName, lastName, email, phone);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment