Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
POM_page_factory_exercise
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shaphen Pangburn
POM_page_factory_exercise
Commits
a1624c3a
Commit
a1624c3a
authored
Apr 13, 2021
by
Shaphen Pangburn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor to follow a POM and try Page Factory
parent
7827e359
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
244 additions
and
52 deletions
+244
-52
build.gradle
build.gradle
+1
-0
AccountSettings.java
...va/com/nisum/pompagefactory/practice/AccountSettings.java
+55
-0
HomePage.java
...main/java/com/nisum/pompagefactory/practice/HomePage.java
+28
-0
LoginPage.java
...ain/java/com/nisum/pompagefactory/practice/LoginPage.java
+55
-0
PropertyValues.java
...ava/com/nisum/pompagefactory/practice/PropertyValues.java
+42
-0
application.properties
src/main/resources/application.properties
+5
-1
SafewayLogin.java
.../java/com/nisum/pompagefactory/practice/SafewayLogin.java
+0
-51
TestConfirmAccountDetails.java
...pagefactory/practice/tests/TestConfirmAccountDetails.java
+58
-0
No files found.
build.gradle
View file @
a1624c3a
plugins
{
id
'java'
}
...
...
src/main/java/com/nisum/pompagefactory/practice/AccountSettings.java
0 → 100644
View file @
a1624c3a
package
com
.
nisum
.
pompagefactory
.
practice
;
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
java.io.IOException
;
import
java.util.List
;
public
class
AccountSettings
{
WebDriver
driver
;
@FindBy
(
id
=
"input-firstName"
)
WebElement
accountFirstName
;
@FindBy
(
id
=
"input-lastName"
)
WebElement
accountLastName
;
@FindBy
(
id
=
"emailIdaccount"
)
WebElement
accountEmail
;
@FindBy
(
id
=
"phoneNumber"
)
WebElement
accountPhoneNumber
;
public
AccountSettings
(
WebDriver
driver
)
{
this
.
driver
=
driver
;
PageFactory
.
initElements
(
this
.
driver
,
this
);
}
public
void
goToAccountSettings
()
throws
InterruptedException
{
HomePage
home
=
new
HomePage
(
driver
,
"https://www.safeway.com/"
,
false
);
home
.
getAccountDropdown
().
click
();
Thread
.
sleep
(
1000
);
home
.
getAccountSettingsButton
().
click
();
}
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
,
IOException
{
// get application.properties values and set ChromeDriver
PropertyValues
properties
=
new
PropertyValues
();
List
<
String
>
props
=
properties
.
getPropValues
();
System
.
setProperty
(
"webdriver.chrome.driver"
,
"/Users/spangburn/drivers/chromedriver"
);
WebDriver
driver
=
new
ChromeDriver
();
// login
String
username
=
props
.
get
(
2
);
String
password
=
props
.
get
(
3
);
LoginPage
login
=
new
LoginPage
(
driver
,
"https://www.safeway.com/"
,
true
);
login
.
loginUser
(
driver
,
"https://www.safeway.com/"
,
username
,
password
);
Thread
.
sleep
(
5000
);
// Navigate to account settings
AccountSettings
accountSettings
=
new
AccountSettings
(
driver
);
accountSettings
.
goToAccountSettings
();
Thread
.
sleep
(
5000
);
driver
.
close
();
}
}
src/main/java/com/nisum/pompagefactory/practice/HomePage.java
0 → 100644
View file @
a1624c3a
package
com
.
nisum
.
pompagefactory
.
practice
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebElement
;
import
java.util.concurrent.TimeUnit
;
public
class
HomePage
{
WebDriver
driver
;
public
HomePage
(
WebDriver
driver
,
String
url
,
Boolean
newBrowser
)
{
this
.
driver
=
driver
;
driver
.
manage
().
timeouts
().
implicitlyWait
(
5
,
TimeUnit
.
SECONDS
);
if
(
newBrowser
){
driver
.
get
(
url
);
}
}
public
WebElement
getMenuNav
()
{
return
driver
.
findElement
(
By
.
linkText
(
"Sign In / Up"
));
}
public
WebElement
getSignInButton
()
{
return
driver
.
findElement
(
By
.
id
(
"sign-in-modal-link"
));
}
public
WebElement
getAccountDropdown
()
{
return
driver
.
findElement
(
By
.
linkText
(
"Account"
));
}
public
WebElement
getAccountSettingsButton
()
{
return
driver
.
findElement
(
By
.
xpath
(
"//*[@id=\"menu\"]/div[1]/ul/li[4]/a"
));
}
public
void
navigateToLogin
()
throws
InterruptedException
{
getMenuNav
().
click
();
Thread
.
sleep
(
1000
);
getSignInButton
().
click
();
}
}
src/main/java/com/nisum/pompagefactory/practice/LoginPage.java
0 → 100644
View file @
a1624c3a
package
com
.
nisum
.
pompagefactory
.
practice
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebElement
;
import
org.openqa.selenium.chrome.ChromeDriver
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
class
LoginPage
{
WebDriver
driver
;
String
url
;
public
LoginPage
(
WebDriver
driver
,
String
url
,
Boolean
newBrowser
)
{
this
.
driver
=
driver
;
driver
.
manage
().
timeouts
().
implicitlyWait
(
5
,
TimeUnit
.
SECONDS
);
if
(
newBrowser
){
driver
.
get
(
url
);
}
}
public
WebElement
getUserEmail
()
{
return
driver
.
findElement
(
By
.
id
(
"label-email"
));
}
public
WebElement
getUserPassword
()
{
return
driver
.
findElement
(
By
.
id
(
"label-password"
));
}
public
WebElement
getSignInButton
()
{
return
driver
.
findElement
(
By
.
id
(
"btnSignIn"
));
}
public
void
loginUser
(
WebDriver
driver
,
String
url
,
String
username
,
String
password
)
throws
InterruptedException
{
HomePage
home
=
new
HomePage
(
driver
,
url
,
false
);
home
.
navigateToLogin
();
// username
getUserEmail
().
sendKeys
(
username
);
// password
getUserPassword
().
sendKeys
(
password
);
Thread
.
sleep
(
1000
);
getSignInButton
().
click
();
}
public
static
void
main
(
String
[]
args
)
throws
IOException
,
InterruptedException
{
// get application.properties values and set ChromeDriver
PropertyValues
properties
=
new
PropertyValues
();
List
<
String
>
props
=
properties
.
getPropValues
();
System
.
setProperty
(
"webdriver.chrome.driver"
,
"/Users/spangburn/drivers/chromedriver"
);
WebDriver
driver
=
new
ChromeDriver
();
// set username and password variables and create login scenario
String
username
=
props
.
get
(
2
);
String
password
=
props
.
get
(
3
);
LoginPage
login
=
new
LoginPage
(
driver
,
"https://www.safeway.com/"
,
true
);
login
.
loginUser
(
driver
,
"https://www.safeway.com/"
,
username
,
password
);
// Thread.sleep(5000);
// driver.close();
}
}
src/main/java/com/nisum/pompagefactory/practice/PropertyValues.java
0 → 100644
View file @
a1624c3a
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
;
public
class
PropertyValues
{
List
<
String
>
results
;
InputStream
inputStream
;
public
List
<
String
>
getPropValues
()
throws
IOException
{
try
{
Properties
prop
=
new
Properties
();
String
propFileName
=
"application.properties"
;
inputStream
=
getClass
().
getClassLoader
().
getResourceAsStream
(
propFileName
);
if
(
inputStream
!=
null
)
{
prop
.
load
(
inputStream
);
}
else
{
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"
);
results
=
Arrays
.
asList
(
firstname
,
lastname
,
email
,
password
,
phone
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Exception: "
+
e
);
}
finally
{
inputStream
.
close
();
}
return
results
;
}
}
src/main/resources/application.properties
View file @
a1624c3a
firstname
=
Chef
lastname
=
Koo
email
=
zackroc@gmail.com
password
=
password123
phone
=
5103063656
src/test/java/com/nisum/pompagefactory/practice/SafewayLogin.java
deleted
100644 → 0
View file @
7827e359
package
com
.
nisum
.
pompagefactory
.
practice
;
import
org.junit.jupiter.api.*
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebElement
;
import
org.openqa.selenium.chrome.ChromeDriver
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
class
SafewayLogin
{
@Test
public
void
testSafewayLogin
()
throws
InterruptedException
{
// setup
System
.
setProperty
(
"webdriver.chrome.driver"
,
"/Users/spangburn/drivers/chromedriver"
);
WebDriver
driver
=
new
ChromeDriver
();
driver
.
get
(
"https://www.safeway.com/"
);
Thread
.
sleep
(
1000
);
// navigate Sign In
WebElement
signInDropdown
=
driver
.
findElement
(
By
.
linkText
(
"Sign In / Up"
));
signInDropdown
.
click
();
Thread
.
sleep
(
1000
);
WebElement
signInButton
=
driver
.
findElement
(
By
.
id
(
"sign-in-modal-link"
));
signInButton
.
click
();
Thread
.
sleep
(
2000
);
// login
WebElement
userEmail
=
driver
.
findElement
(
By
.
id
(
"label-email"
));
WebElement
userPassword
=
driver
.
findElement
(
By
.
id
(
"label-password"
));
WebElement
trySignIn
=
driver
.
findElement
(
By
.
id
(
"btnSignIn"
));
userEmail
.
sendKeys
(
"zackroc@gmail.com"
);
userPassword
.
sendKeys
(
"password123"
);
trySignIn
.
click
();
Thread
.
sleep
(
3000
);
// Navigate Account Settings
WebElement
accountDropdown
=
driver
.
findElement
(
By
.
linkText
(
"Account"
));
accountDropdown
.
click
();
Thread
.
sleep
(
1000
);
WebElement
accountSettingsButton
=
driver
.
findElement
(
By
.
xpath
(
"//*[@id=\"menu\"]/div[1]/ul/li[4]/a"
));
accountSettingsButton
.
click
();
Thread
.
sleep
(
3000
);
// Assert Account Information Exists
driver
.
quit
();
}
}
src/test/java/com/nisum/pompagefactory/practice/tests/TestConfirmAccountDetails.java
0 → 100644
View file @
a1624c3a
package
com
.
nisum
.
pompagefactory
.
practice
.
tests
;
import
org.junit.jupiter.api.*
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebElement
;
import
org.openqa.selenium.chrome.ChromeDriver
;
public
class
TestConfirmAccountDetails
{
@Test
public
void
testSafewayLogin
()
throws
InterruptedException
{
// setup
System
.
setProperty
(
"webdriver.chrome.driver"
,
"/Users/spangburn/drivers/chromedriver"
);
WebDriver
driver
=
new
ChromeDriver
();
driver
.
get
(
"https://www.safeway.com/"
);
Thread
.
sleep
(
1000
);
// navigate Sign In
WebElement
signInDropdown
=
driver
.
findElement
(
By
.
linkText
(
"Sign In / Up"
));
signInDropdown
.
click
();
Thread
.
sleep
(
1000
);
WebElement
signInButton
=
driver
.
findElement
(
By
.
id
(
"sign-in-modal-link"
));
signInButton
.
click
();
Thread
.
sleep
(
2000
);
// login
WebElement
userEmail
=
driver
.
findElement
(
By
.
id
(
"label-email"
));
WebElement
userPassword
=
driver
.
findElement
(
By
.
id
(
"label-password"
));
WebElement
trySignIn
=
driver
.
findElement
(
By
.
id
(
"btnSignIn"
));
userEmail
.
sendKeys
(
"zackroc@gmail.com"
);
userPassword
.
sendKeys
(
"password123"
);
trySignIn
.
click
();
Thread
.
sleep
(
3000
);
// Navigate Account Settings
WebElement
accountDropdown
=
driver
.
findElement
(
By
.
linkText
(
"Account"
));
accountDropdown
.
click
();
Thread
.
sleep
(
1000
);
WebElement
accountSettingsButton
=
driver
.
findElement
(
By
.
xpath
(
"//*[@id=\"menu\"]/div[1]/ul/li[4]/a"
));
accountSettingsButton
.
click
();
Thread
.
sleep
(
3000
);
// Assert Account Information Exists
WebElement
getAccountFirstName
=
driver
.
findElement
(
By
.
id
(
"input-firstName"
));
WebElement
getAccountLastName
=
driver
.
findElement
(
By
.
id
(
"input-lastName"
));
WebElement
getAccountEmail
=
driver
.
findElement
(
By
.
id
(
"emailIdaccount"
));
WebElement
getAccountPhoneNumber
=
driver
.
findElement
(
By
.
id
(
"phoneNumber"
));
Assertions
.
assertEquals
(
"Chef"
,
getAccountFirstName
.
getAttribute
(
"value"
));
Assertions
.
assertEquals
(
"Koo"
,
getAccountLastName
.
getAttribute
(
"value"
));
Assertions
.
assertEquals
(
"zackroc@gmail.com"
,
getAccountEmail
.
getAttribute
(
"value"
));
Assertions
.
assertEquals
(
"5103063656"
,
getAccountPhoneNumber
.
getAttribute
(
"value"
));
driver
.
quit
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment