Commit 3ae2fd1f authored by Alex Segers's avatar Alex Segers

Initial commit [@asegers] -- Assignment Complete

parents
*#
*.iml
*.ipr
*.iws
*.jar
*.sw?
*~
.#*
.*.md.html
.DS_Store
.attach_pid*
.classpath
.factorypath
.gradle
.idea
.metadata
.project
.recommenders
.settings
.springBeans
.vscode
/code
MANIFEST.MF
_site/
activemq-data
bin
build
!/**/src/**/bin
!/**/src/**/build
build.log
dependency-reduced-pom.xml
dump.rdb
interpolated*.xml
lib/
manifest.yml
out
overridedb.*
target
transaction-logs
.flattened-pom.xml
secrets.yml
.gradletasknamecache
.sts4-cache
*.properties
\ No newline at end of file
# Assignment Details
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.
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.nisum.asegers</groupId>
<artifactId>selenium-testng-pom-exercise</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.nisum.safeway.page_factories;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.concurrent.TimeUnit;
public class AccountSettingsPF {
WebDriver driver;
public AccountSettingsPF(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(this.driver, this);
}
@FindBy(id = "input-firstName")
WebElement inpFirstName;
@FindBy(id = "input-lastName")
WebElement inpLastName;
@FindBy(id = "emailIdaccount")
WebElement inpEmail;
@FindBy(xpath = "//p[contains(text(), 'Personal Information')]")
WebElement parPersonalInformation;
public void authenticateAndNavigate() {
HomePF homePF = new HomePF(driver);
homePF.navigateToAccountSettings();
new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOf(parPersonalInformation));
}
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/Users/asegers/Drivers/chromedriver");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
AccountSettingsPF accountSettingsPF = new AccountSettingsPF(driver);
accountSettingsPF.authenticateAndNavigate();
driver.quit();
}
}
package com.nisum.safeway.page_factories;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.FindBys;
import org.openqa.selenium.support.PageFactory;
import properties.UserProperties;
import java.util.concurrent.TimeUnit;
public class HomePF {
WebDriver driver;
public HomePF(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(this.driver, this);
}
@FindBys({
@FindBy(className = "menu-nav__profile-button"),
@FindBy(xpath = "//a[contains(text(), 'Account')]")
})
WebElement lnkAccount;
@FindBy(xpath = "//a[contains(text(), 'Account Settings')]")
WebElement menuItemAccountSettings;
@FindBy(className = "sidebar__user-welcome__message")
WebElement welcomeMsg;
public void authenticate() {
LoginPF loginPF = new LoginPF(driver);
loginPF.login(UserProperties.get("email"), UserProperties.get("password"));
}
public void navigateToAccountSettings() {
authenticate();
// PageFactory.initElements(this.driver, this);
lnkAccount.click();
menuItemAccountSettings.click();
}
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/Users/asegers/Drivers/chromedriver");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
HomePF homePF = new HomePF(driver);
homePF.navigateToAccountSettings();
driver.quit();
}
}
package com.nisum.safeway.page_factories;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.FindBys;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import properties.UserProperties;
import java.util.concurrent.TimeUnit;
public class LoginPF {
WebDriver driver;
final String HOME_URL = "https://www.safeway.com/";
public LoginPF(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(this.driver, this);
driver.navigate().to(HOME_URL);
}
@FindBys({
@FindBy(className = "menu-nav__profile-button"),
@FindBy(xpath = "//a[@title='Your profile']")
})
WebElement lnkSignIn;
@FindBy(id = "sign-in-modal-link")
WebElement menuItemSignIn;
@FindBy(id = "label-email")
WebElement inpEmail;
@FindBy(id = "label-password")
WebElement inpPassword;
@FindBy(id = "btnSignIn")
WebElement btnSignIn;
public void login(String email, String password) {
lnkSignIn.click();
menuItemSignIn.click();
new WebDriverWait(driver, 5).until(ExpectedConditions.elementToBeClickable(inpEmail));
inpEmail.sendKeys(email);
new WebDriverWait(driver, 5).until(ExpectedConditions.elementToBeClickable(inpPassword));
inpPassword.sendKeys(password);
btnSignIn.click();
// Wait for link w/ text "Sign In / Up" to be unattached from the DOM, signaling a page refresh and successful authentication
new WebDriverWait(driver, 20).until(ExpectedConditions.stalenessOf(lnkSignIn));
}
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/Users/asegers/Drivers/chromedriver");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
LoginPF loginPF = new LoginPF(driver);
loginPF.login(UserProperties.get("email"), UserProperties.get("password"));
driver.quit();
}
}
package com.nisum.safeway.pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class AccountSettingsPage {
WebDriver driver;
public AccountSettingsPage(WebDriver driver) {
this.driver = driver;
}
public WebElement getInpFirstName() {
return driver.findElement(By.id("input-firstName"));
}
public WebElement getInpLastName() {
return driver.findElement(By.id("input-lastName"));
}
public WebElement getInpEmail() {
return driver.findElement(By.id("emailIdaccount"));
}
public WebElement getParPersonalInformation() {
return driver.findElement(By.xpath("//p[contains(text(), 'Personal Information')]"));
}
public void authenticateAndNavigate() {
HomePage homePage = new HomePage(driver);
homePage.navigateToAccountSettings();
new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOf(getParPersonalInformation()));
}
}
package com.nisum.safeway.pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import properties.UserProperties;
public class HomePage {
WebDriver driver;
public HomePage(WebDriver driver) {
this.driver = driver;
}
public WebElement getLnkAccount() {
return driver.findElement(By.className("menu-nav__profile-button-sign-in-up"));
}
public WebElement getMenuItemAccountSettings() {
return driver.findElement(By.xpath("//a[contains(text(), 'Account Settings')]"));
}
public WebElement getWelcomeMsg() {
return driver.findElement(By.className("sidebar__user-welcome__message"));
}
public void authenticate() {
LoginPage loginPage = new LoginPage(driver);
loginPage.login(UserProperties.get("email"), UserProperties.get("password"));
}
public void navigateToAccountSettings() {
authenticate();
getLnkAccount().click();
getMenuItemAccountSettings().click();
}
}
package com.nisum.safeway.pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class LoginPage {
WebDriver driver;
final String HOME_URL = "https://www.safeway.com/";
public LoginPage(WebDriver driver) {
this.driver = driver;
driver.navigate().to(HOME_URL);
}
public WebElement getLnkSignIn() {
return driver.findElement(By.className("menu-nav__profile-button"));
}
public WebElement getMenuItemSignIn() {
return driver.findElement(By.id("sign-in-modal-link"));
}
public WebElement getInpEmail() {
return driver.findElement(By.id("label-email"));
}
public WebElement getInpPassword() {
return driver.findElement(By.id("label-password"));
}
public WebElement getBtnSignIn() { return driver.findElement(By.id("btnSignIn")); }
public void login(String email, String password) {
getLnkSignIn().click();
getMenuItemSignIn().click();
new WebDriverWait(driver, 5).until(ExpectedConditions.elementToBeClickable(getInpEmail()));
getInpEmail().sendKeys(email);
new WebDriverWait(driver, 5).until(ExpectedConditions.elementToBeClickable(getInpPassword()));
getInpPassword().sendKeys(password);
getBtnSignIn().click();
// Wait for link w/ text "Sign In / Up" to be unattached from the DOM, signaling a page refresh and successful authentication
new WebDriverWait(driver, 15).until(ExpectedConditions.stalenessOf(getLnkSignIn()));
}
}
package properties;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class UserProperties {
static public String get(String propertyName) {
try (InputStream input = new FileInputStream("src/main/resources/account.properties")) {
Properties properties = new Properties();
properties.load(input);
if (properties.containsKey(propertyName)) return properties.getProperty(propertyName);
} catch (IOException ex) {
ex.printStackTrace();
}
return null;
}
}
package com.nisum.safeway.page_factories;
import com.nisum.safeway.pages.SeleniumPageTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import properties.UserProperties;
import static org.testng.Assert.assertEquals;
public class AccountSettingsPFTests extends SeleniumPageTest {
AccountSettingsPF pageFactory;
@BeforeTest
public void authenticate() {
pageFactory = new AccountSettingsPF(driver);
pageFactory.authenticateAndNavigate();
}
@Test
public void userDetailsArePresent() {
assertEquals(UserProperties.get("firstName"), pageFactory.inpFirstName.getAttribute("value"));
assertEquals(UserProperties.get("lastName"), pageFactory.inpLastName.getAttribute("value"));
assertEquals(UserProperties.get("email"), pageFactory.inpEmail.getAttribute("value"));
}
}
package com.nisum.safeway.page_factories;
import com.nisum.safeway.pages.SeleniumPageTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import properties.UserProperties;
import static org.testng.Assert.assertEquals;
public class HomePFTests extends SeleniumPageTest {
HomePF pageFactory;
@BeforeTest
public void authenticate() {
pageFactory = new HomePF(driver);
pageFactory.authenticate();
}
@Test
public void welcomeMsgContainsUserFirstName() {
pageFactory.lnkAccount.click();
assertEquals("Hi " + UserProperties.get("firstName"), pageFactory.welcomeMsg.getText());
}
}
package com.nisum.safeway.page_factories;
import com.nisum.safeway.pages.SeleniumPageTest;
import org.openqa.selenium.WebElement;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import static org.testng.Assert.assertTrue;
import properties.UserProperties;
public class LoginPFTests extends SeleniumPageTest {
LoginPF pageFactory;
@BeforeTest
public void authenticate() {
pageFactory = new LoginPF(driver);
pageFactory.login(UserProperties.get("email"), UserProperties.get("password"));
}
@Test
public void lnkAccountShouldBeVisible() {
WebElement lnkAccount = new HomePF(driver).lnkAccount;
assertTrue(lnkAccount.isDisplayed(), "Account link is visible");
}
}
package com.nisum.safeway.pages;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
import properties.UserProperties;
public class AccountSettingsPageTests extends SeleniumPageTest {
AccountSettingsPage page;
@BeforeTest
public void authenticateAndNavigate() {
this.page = new AccountSettingsPage(driver);
page.authenticateAndNavigate();
}
@Test
public void userDetailsArePresent() {
assertEquals(UserProperties.get("firstName"), page.getInpFirstName().getAttribute("value"));
assertEquals(UserProperties.get("lastName"), page.getInpLastName().getAttribute("value"));
assertEquals(UserProperties.get("email"), page.getInpEmail().getAttribute("value"));
}
}
package com.nisum.safeway.pages;
import org.openqa.selenium.WebElement;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
import properties.UserProperties;
public class HomePageTests extends SeleniumPageTest {
HomePage page;
@BeforeTest
public void authenticate() {
page = new HomePage(driver);
page.authenticate();
}
@Test
public void welcomeMsgContainsUserFirstName() {
page.getLnkAccount().click();
WebElement welcomeMsg = page.getWelcomeMsg();
assertEquals("Hi " + UserProperties.get("firstName"), welcomeMsg.getText());
}
}
package com.nisum.safeway.pages;
import org.openqa.selenium.WebElement;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import static org.testng.Assert.assertTrue;
import properties.UserProperties;
public class LoginPageTests extends SeleniumPageTest {
LoginPage page;
@BeforeTest
public void authenticate() {
page = new LoginPage(driver);
page.login(UserProperties.get("email"), UserProperties.get("password"));
}
@Test
public void lnkAccountShouldBeVisible() {
WebElement lnkAccount = new HomePage(driver).getLnkAccount();
assertTrue(lnkAccount.isDisplayed(), "Account link is visible");
}
}
package com.nisum.safeway.pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import java.util.concurrent.TimeUnit;
public abstract class SeleniumPageTest {
public WebDriver driver;
@BeforeTest
public void setUp() {
System.setProperty("webdriver.chrome.driver", "/Users/asegers/Drivers/chromedriver");
this.driver = new ChromeDriver();
this.driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}
@AfterTest
public void tearDown() {
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