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