Commit 07dedaad authored by Kyle Muldoon's avatar Kyle Muldoon

got page factory working

parent 22ed1353
demoPF.jpg

70.3 KB

package PACKAGE_NAME;public class Login {
}
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 {
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;
@FindBy(how = How.ID, using = "label-password")
WebElement userPasswordInputBox;
@FindBy(how = How.ID, using = "btnSignIn")
WebElement signInButton;
public LoginPF(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));
this.userNameInputBox.sendKeys(userName);
this.userPasswordInputBox.sendKeys(password);
}
public void login(String username, String password) {
revealLoginModal();
fillUserInfo(username, password);
wdw.until(ExpectedConditions.elementToBeClickable(signInButton));
signInButton.click();
}
}
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class SafewayLoginTest {
}
String OS;
String browser;
Properties safewayLoginCreds;
@Test
public void testSafewayLogin() throws InterruptedException {
setup();
WebDriver driver = new ChromeDriver();
LoginPF loginPF = new LoginPF(driver);
driver.get("https://www.safeway.com/");
loginPF.login(safewayLoginCreds.getProperty("username"), safewayLoginCreds.getProperty("password"));
Thread.sleep(10000);
driver.quit();
}
public void setup() {
/////////////////////
// Get environment information
/////////////////////
this.OS = System.getProperty("os.name");
this.browser = "Chrome";
switch (this.OS) {
case "Mac OS X":
System.setProperty("webdriver.chrome.driver",
"/Users/kmuldoon/Dev/practice/testing/Selenium/Selenium-POM-Safeway/src/test/resources/chromedriver");
break;
case "Windows":
;
break;
case "Linux":
;
break;
default:
System.out.println("Unsupported OS");
}
System.out.printf("Running login test using %s on %s\n", browser, OS);
/////////////////////
// Get Login Credentials
/////////////////////
try (InputStream input = new FileInputStream("src/test/resources/credentials.properties")) {
this.safewayLoginCreds = new Properties();
// load a properties file
this.safewayLoginCreds.load(input);
// get the property value and print it out
System.out.println("username:\t" + this.safewayLoginCreds.getProperty("username"));
System.out.println("password:\t" + this.safewayLoginCreds.getProperty("password"));
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
\ No newline at end of file
username=vkrijegccvsknuvnpv@miucce.com
password=12345678
\ 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