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