Commit 9feaba17 authored by Shaphen Pangburn's avatar Shaphen Pangburn

Refactor Proterty results to key-value pairs for less cluttered logic in test file

parent 93ec5ee6
......@@ -3,15 +3,13 @@ package com.nisum.pompagefactory.practice;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.*;
public class PropertyValues {
List<String> results;
Map<String, String> mapResults = new HashMap<>();
InputStream inputStream;
public List<String> getPropValues() throws IOException {
public Map<String, String> getPropValues() throws IOException {
try {
Properties prop = new Properties();
String propFileName = "application.properties";
......@@ -24,13 +22,12 @@ public class PropertyValues {
throw new FileNotFoundException("property file " + propFileName + " not found");
}
String firstname = prop.getProperty("firstname");
String lastname = prop.getProperty("lastname");
String email = prop.getProperty("email");
String password = prop.getProperty("password");
String phone = prop.getProperty("phone");
mapResults.put("firstname", prop.getProperty("firstname"));
mapResults.put("lastname", prop.getProperty("lastname"));
mapResults.put("email", prop.getProperty("email"));
mapResults.put("password", prop.getProperty("password"));
mapResults.put("phone", prop.getProperty("phone"));
results = Arrays.asList(firstname, lastname, email, password, phone);
} catch (Exception e) {
System.out.println("Exception: " + e);
} finally {
......@@ -38,6 +35,6 @@ public class PropertyValues {
inputStream.close();
}
return results;
return mapResults;
}
}
......@@ -10,6 +10,7 @@ public class SetWebDriver {
switch (type){
case "chrome":
System.setProperty("webdriver.chrome.driver", "/Users/spangburn/drivers/chromedriver");
break;
case "firefox":
// code
case "Safari":
......
......@@ -14,6 +14,7 @@ import org.openqa.selenium.support.ui.WebDriverWait;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public class TestConfirmAccountDetails {
......@@ -21,13 +22,7 @@ public class TestConfirmAccountDetails {
public void testAccountSettingsInformation() throws InterruptedException, IOException {
// get application.properties values and set WebDriver properties
PropertyValues properties = new PropertyValues();
List<String> props = properties.getPropValues();
String email = props.get(2);
String password = props.get(3);
String firstName = props.get(0);
String lastName = props.get(1);
String phoneNumber = props.get(4);
Map<String, String> props = properties.getPropValues();
WebDriver driver = new SetWebDriver("chrome").driver;
WebDriverWait wait = new WebDriverWait(driver, 5);
......@@ -37,7 +32,7 @@ public class TestConfirmAccountDetails {
// Login Action Call
LoginPage loginPage = new LoginPage(driver, "https://www.safeway.com/", false);
loginPage.loginUser(email, password);
loginPage.loginUser(props.get("email"), props.get("password"));
// Navigation to Account Settings
AccountSettingsPage accountSettingsPage = new AccountSettingsPage(driver);
......@@ -45,10 +40,10 @@ public class TestConfirmAccountDetails {
// Assert Information Matches Application Properties
wait.until(ExpectedConditions.elementToBeClickable(accountSettingsPage.accountFirstName));
Assertions.assertEquals(firstName, accountSettingsPage.accountFirstName.getAttribute("value"));
Assertions.assertEquals(lastName, accountSettingsPage.accountLastName.getAttribute("value"));
Assertions.assertEquals(email, accountSettingsPage.accountEmail.getAttribute("value"));
Assertions.assertEquals(phoneNumber, accountSettingsPage.accountPhoneNumber.getAttribute("value"));
Assertions.assertEquals(props.get("firstname"), accountSettingsPage.accountFirstName.getAttribute("value"));
Assertions.assertEquals(props.get("lastname"), accountSettingsPage.accountLastName.getAttribute("value"));
Assertions.assertEquals(props.get("email"), accountSettingsPage.accountEmail.getAttribute("value"));
Assertions.assertEquals(props.get("phone"), accountSettingsPage.accountPhoneNumber.getAttribute("value"));
driver.quit();
}
......
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