Commit f94de708 authored by Kyle Muldoon's avatar Kyle Muldoon

refactored to break entire login process into subcomponents

parent 07dedaad
......@@ -33,6 +33,12 @@
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
......
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.ui.WebDriverWait;
public class AccountSettingsPOM {
WebDriver driver;
WebDriverWait wdw;
WebElement expandAccountOptionsButton;
WebElement accountSettingsButton;
WebElement userNameInputBox;
WebElement userPasswordInputBox;
WebElement signInButton;
}
package PageComponents;
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 HomePagePF {
WebDriver driver;
WebDriverWait wdw;
@FindBy(how = How.PARTIAL_LINK_TEXT, using = "Sign In / Up")
WebElement expandLoginOptionsButton;
public HomePagePF(WebDriver driver) {
this.driver = driver;
this.wdw = new WebDriverWait(this.driver, 1);
PageFactory.initElements(driver, this);
}
public void visitSafewayHomepage() {
driver.get("https://www.safeway.com/");
}
public void revealRightSidebar() {
wdw.until(ExpectedConditions.elementToBeClickable(expandLoginOptionsButton));
expandLoginOptionsButton.click();
}
}
package PageComponents;
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.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import sun.security.util.Password;
import java.util.concurrent.TimeUnit;
public class LoginPF {
public class LoginModalPF {
WebDriver driver;
WebDriverWait wdw;
@FindBy(how = How.PARTIAL_LINK_TEXT, using = "Sign In / Up")
WebElement expandLoginOptionsButton;
@FindBy(how = How.ID, using = "sign-in-modal-link")
WebElement revealLoginModalButton;
@FindBy(how = How.ID, using = "label-email")
WebElement userNameInputBox;
......@@ -29,19 +21,12 @@ public class LoginPF {
@FindBy(how = How.ID, using = "btnSignIn")
WebElement signInButton;
public LoginPF(WebDriver driver) {
public LoginModalPF(WebDriver driver) {
this.driver = driver;
this.wdw = new WebDriverWait(this.driver, 1);
PageFactory.initElements(driver, this);
}
public void revealLoginModal() {
wdw.until(ExpectedConditions.elementToBeClickable(expandLoginOptionsButton));
expandLoginOptionsButton.click();
wdw.until(ExpectedConditions.elementToBeClickable(revealLoginModalButton));
revealLoginModalButton.click();
}
public void fillUserInfo(String userName, String password) {
wdw.until(ExpectedConditions.elementToBeClickable(userNameInputBox));
wdw.until(ExpectedConditions.elementToBeClickable(userPasswordInputBox));
......@@ -49,10 +34,7 @@ public class LoginPF {
this.userPasswordInputBox.sendKeys(password);
}
public void login(String username, String password) {
revealLoginModal();
fillUserInfo(username, password);
wdw.until(ExpectedConditions.elementToBeClickable(signInButton));
public void sendCredentials() {
signInButton.click();
}
......
package PageComponents;
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 RightSideBarPF {
WebDriver driver;
WebDriverWait wdw;
@FindBy(how = How.ID, using = "sign-in-modal-link")
WebElement revealLoginModalButton;
public RightSideBarPF(WebDriver driver) {
this.driver = driver;
this.wdw = new WebDriverWait(this.driver, 1);
PageFactory.initElements(driver, this);
}
public void revealLoginModal() {
wdw.until(ExpectedConditions.elementToBeClickable(revealLoginModalButton));
revealLoginModalButton.click();
}
}
import PageComponents.HomePagePF;
import PageComponents.LoginModalPF;
import PageComponents.RightSideBarPF;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
......@@ -19,15 +22,21 @@ public class SafewayLoginTest {
setup();
WebDriver driver = new ChromeDriver();
LoginPF loginPF = new LoginPF(driver);
driver.get("https://www.safeway.com/");
loginPF.login(safewayLoginCreds.getProperty("username"), safewayLoginCreds.getProperty("password"));
HomePagePF homePage = new HomePagePF(driver);
RightSideBarPF rightSideBar = new RightSideBarPF(driver);
LoginModalPF loginModal = new LoginModalPF(driver);
homePage.visitSafewayHomepage();
homePage.revealRightSidebar();
rightSideBar.revealLoginModal();
loginModal.fillUserInfo(safewayLoginCreds.getProperty("username"), safewayLoginCreds.getProperty("password"));
loginModal.sendCredentials();
Thread.sleep(10000);
driver.quit();
}
}
public void setup() {
/////////////////////
......@@ -76,5 +85,4 @@ public class SafewayLoginTest {
ex.printStackTrace();
}
}
}
\ No newline at end of file
Create a maven project and provide all the dependencies.
Use Selenium 3.x.x (latest).
Use TestNG / JUnit.
Write generic code which will work with any type of browser. Browser may be a parameter.
Make appropriate arrangements for identifying the OS and picking up the correct driver for that particular OS.
1. Assume that you have a user registered on safeway.com. All the details of the account that was registered are stored in a property file.
2. Create Page Classes for Home Page, Login Page, Account Settings Page.
3. Verify all the details from the property file using proper testNG/JUnit assertions.
use Page Object Model & Page Factory (like a couple classes using page object model and a couple using page factory.)
---------------
# verify account settings next:
- get account settings from webpage.
- assertEqual that they are the expected values.
\ No newline at end of file
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