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
c83e927b
Commit
c83e927b
authored
Apr 13, 2021
by
Shaphen Pangburn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor code to use explicit wait statements
parent
3c0e1f16
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
110 additions
and
14 deletions
+110
-14
AccountSettingsPage.java
...um/pompagefactory/practice/pages/AccountSettingsPage.java
+42
-0
HomePage.java
...ava/com/nisum/pompagefactory/practice/pages/HomePage.java
+11
-3
LoginPage.java
...va/com/nisum/pompagefactory/practice/pages/LoginPage.java
+44
-0
TestConfirmAccountDetails.java
...pagefactory/practice/tests/TestConfirmAccountDetails.java
+13
-11
No files found.
src/main/java/com/nisum/pompagefactory/practice/
AccountSettings
.java
→
src/main/java/com/nisum/pompagefactory/practice/
pages/AccountSettingsPage
.java
View file @
c83e927b
package
com
.
nisum
.
pompagefactory
.
practice
;
package
com
.
nisum
.
pompagefactory
.
practice
.
pages
;
import
com.nisum.pompagefactory.practice.pages.HomePage
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebElement
;
import
org.openqa.selenium.WebElement
;
import
org.openqa.selenium.chrome.ChromeDriver
;
import
org.openqa.selenium.support.FindBy
;
import
org.openqa.selenium.support.FindBy
;
import
org.openqa.selenium.support.PageFactory
;
import
org.openqa.selenium.support.PageFactory
;
import
org.openqa.selenium.support.ui.ExpectedConditions
;
import
org.openqa.selenium.support.ui.WebDriverWait
;
import
java.io.IOException
;
import
java.util.concurrent.TimeUnit
;
import
java.util.List
;
public
class
AccountSettings
{
public
class
AccountSettings
Page
{
WebDriver
driver
;
WebDriver
driver
;
@FindBy
(
xpath
=
"//*[@id=\"input-firstName\"]"
)
@FindBy
(
xpath
=
"//*[@id=\"input-firstName\"]"
)
public
WebElement
accountFirstName
;
public
WebElement
accountFirstName
;
...
@@ -20,42 +21,22 @@ public class AccountSettings {
...
@@ -20,42 +21,22 @@ public class AccountSettings {
@FindBy
(
xpath
=
"//*[@id=\"phoneNumber\"]"
)
@FindBy
(
xpath
=
"//*[@id=\"phoneNumber\"]"
)
public
WebElement
accountPhoneNumber
;
public
WebElement
accountPhoneNumber
;
public
AccountSettings
(
WebDriver
driver
)
{
public
AccountSettings
Page
(
WebDriver
driver
)
{
this
.
driver
=
driver
;
this
.
driver
=
driver
;
driver
.
manage
().
timeouts
().
implicitlyWait
(
5
,
TimeUnit
.
SECONDS
);
PageFactory
.
initElements
(
this
.
driver
,
this
);
PageFactory
.
initElements
(
this
.
driver
,
this
);
}
}
public
void
goToAccountSettings
()
throws
InterruptedException
{
public
void
goToAccountSettings
()
{
WebDriverWait
wait
=
new
WebDriverWait
(
driver
,
5
);
// setup
HomePage
home
=
new
HomePage
(
driver
,
"https://www.safeway.com/"
,
false
);
HomePage
home
=
new
HomePage
(
driver
,
"https://www.safeway.com/"
,
false
);
wait
.
until
(
ExpectedConditions
.
elementToBeClickable
(
home
.
getAccountDropdown
()));
home
.
getAccountDropdown
().
click
();
home
.
getAccountDropdown
().
click
();
Thread
.
sleep
(
1000
);
// click account settings button
wait
.
until
(
ExpectedConditions
.
elementToBeClickable
(
home
.
getAccountSettingsButton
()));
home
.
getAccountSettingsButton
().
click
();
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);
//
// System.out.println(accountSettings.accountFirstName.getAttribute("value"));
// System.out.println(accountSettings.accountLastName.getAttribute("value"));
// System.out.println(accountSettings.accountEmail.getAttribute("value"));
// System.out.println(accountSettings.accountPhoneNumber.getAttribute("value"));
//
// driver.close();
// }
}
}
src/main/java/com/nisum/pompagefactory/practice/HomePage.java
→
src/main/java/com/nisum/pompagefactory/practice/
pages/
HomePage.java
View file @
c83e927b
package
com
.
nisum
.
pompagefactory
.
practice
;
package
com
.
nisum
.
pompagefactory
.
practice
.
pages
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebElement
;
import
org.openqa.selenium.WebElement
;
import
org.openqa.selenium.support.ui.ExpectedConditions
;
import
org.openqa.selenium.support.ui.WebDriverWait
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
...
@@ -20,9 +22,15 @@ public class HomePage {
...
@@ -20,9 +22,15 @@ public class HomePage {
public
WebElement
getAccountDropdown
()
{
return
driver
.
findElement
(
By
.
linkText
(
"Account"
));
}
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
WebElement
getAccountSettingsButton
()
{
return
driver
.
findElement
(
By
.
xpath
(
"//*[@id=\"menu\"]/div[1]/ul/li[4]/a"
));
}
public
void
navigateToLogin
()
throws
InterruptedException
{
public
void
navigateToLogin
()
{
WebDriverWait
wait
=
new
WebDriverWait
(
driver
,
5
);
// click dropdown menu
wait
.
until
(
ExpectedConditions
.
elementToBeClickable
(
getMenuNav
()));
getMenuNav
().
click
();
getMenuNav
().
click
();
Thread
.
sleep
(
1000
);
// click sign in button
wait
.
until
(
ExpectedConditions
.
elementToBeClickable
(
getSignInButton
()));
getSignInButton
().
click
();
getSignInButton
().
click
();
}
}
}
}
src/main/java/com/nisum/pompagefactory/practice/LoginPage.java
→
src/main/java/com/nisum/pompagefactory/practice/
pages/
LoginPage.java
View file @
c83e927b
package
com
.
nisum
.
pompagefactory
.
practice
;
package
com
.
nisum
.
pompagefactory
.
practice
.
pages
;
import
com.nisum.pompagefactory.practice.pages.HomePage
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebElement
;
import
org.openqa.selenium.WebElement
;
import
org.openqa.selenium.chrome.ChromeDriver
;
import
org.openqa.selenium.support.ui.ExpectedConditions
;
import
org.openqa.selenium.support.ui.WebDriverWait
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
public
class
LoginPage
{
public
class
LoginPage
{
...
@@ -21,35 +21,24 @@ public class LoginPage {
...
@@ -21,35 +21,24 @@ public class LoginPage {
public
WebElement
getUserEmail
()
{
return
driver
.
findElement
(
By
.
id
(
"label-email"
));
}
public
WebElement
getUserEmail
()
{
return
driver
.
findElement
(
By
.
id
(
"label-email"
));
}
public
WebElement
getUserPassword
()
{
return
driver
.
findElement
(
By
.
id
(
"label-password"
));
}
public
WebElement
getUserPassword
()
{
return
driver
.
findElement
(
By
.
id
(
"label-password"
));
}
public
WebElement
getS
ignIn
Button
()
{
return
driver
.
findElement
(
By
.
id
(
"btnSignIn"
));
}
public
WebElement
getS
ubmit
Button
()
{
return
driver
.
findElement
(
By
.
id
(
"btnSignIn"
));
}
public
void
loginUser
(
WebDriver
driver
,
String
url
,
String
username
,
String
password
)
throws
InterruptedException
{
public
void
loginUser
(
WebDriver
driver
,
String
url
,
String
username
,
String
password
)
throws
InterruptedException
{
WebDriverWait
wait
=
new
WebDriverWait
(
driver
,
5
);
// setup
HomePage
home
=
new
HomePage
(
driver
,
url
,
false
);
HomePage
home
=
new
HomePage
(
driver
,
url
,
false
);
home
.
navigateToLogin
();
home
.
navigateToLogin
();
// username
// enter credentials
wait
.
until
(
ExpectedConditions
.
elementToBeClickable
(
getUserEmail
()));
getUserEmail
().
sendKeys
(
username
);
getUserEmail
().
sendKeys
(
username
);
// password
wait
.
until
(
ExpectedConditions
.
elementToBeClickable
(
getUserPassword
()));
getUserPassword
().
sendKeys
(
password
);
getUserPassword
().
sendKeys
(
password
);
Thread
.
sleep
(
1000
);
// click submit button
getSignInButton
().
click
();
wait
.
until
(
ExpectedConditions
.
elementToBeClickable
(
getSubmitButton
()));
getSubmitButton
().
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/test/java/com/nisum/pompagefactory/practice/tests/TestConfirmAccountDetails.java
View file @
c83e927b
package
com
.
nisum
.
pompagefactory
.
practice
.
tests
;
package
com
.
nisum
.
pompagefactory
.
practice
.
tests
;
import
com.nisum.pompagefactory.practice.
AccountSettings
;
import
com.nisum.pompagefactory.practice.
pages.AccountSettingsPage
;
import
com.nisum.pompagefactory.practice.LoginPage
;
import
com.nisum.pompagefactory.practice.
pages.
LoginPage
;
import
com.nisum.pompagefactory.practice.PropertyValues
;
import
com.nisum.pompagefactory.practice.PropertyValues
;
import
org.junit.jupiter.api.Assertions
;
import
org.junit.jupiter.api.Assertions
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.chrome.ChromeDriver
;
import
org.openqa.selenium.chrome.ChromeDriver
;
import
org.openqa.selenium.support.ui.ExpectedConditions
;
import
org.openqa.selenium.support.ui.WebDriverWait
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.List
;
...
@@ -15,7 +17,7 @@ public class TestConfirmAccountDetails {
...
@@ -15,7 +17,7 @@ public class TestConfirmAccountDetails {
@Test
@Test
public
void
testAccountSettingsInformation
()
throws
InterruptedException
,
IOException
{
public
void
testAccountSettingsInformation
()
throws
InterruptedException
,
IOException
{
// get application.properties values and set
ChromeDriver
// get application.properties values and set
WebDriver properties
PropertyValues
properties
=
new
PropertyValues
();
PropertyValues
properties
=
new
PropertyValues
();
List
<
String
>
props
=
properties
.
getPropValues
();
List
<
String
>
props
=
properties
.
getPropValues
();
String
email
=
props
.
get
(
2
);
String
email
=
props
.
get
(
2
);
...
@@ -26,22 +28,22 @@ public class TestConfirmAccountDetails {
...
@@ -26,22 +28,22 @@ public class TestConfirmAccountDetails {
System
.
setProperty
(
"webdriver.chrome.driver"
,
"/Users/spangburn/drivers/chromedriver"
);
System
.
setProperty
(
"webdriver.chrome.driver"
,
"/Users/spangburn/drivers/chromedriver"
);
WebDriver
driver
=
new
ChromeDriver
();
WebDriver
driver
=
new
ChromeDriver
();
WebDriverWait
wait
=
new
WebDriverWait
(
driver
,
5
);
// login
// login
LoginPage
loginPage
=
new
LoginPage
(
driver
,
"https://www.safeway.com/"
,
true
);
LoginPage
loginPage
=
new
LoginPage
(
driver
,
"https://www.safeway.com/"
,
true
);
loginPage
.
loginUser
(
driver
,
"https://www.safeway.com/"
,
email
,
password
);
loginPage
.
loginUser
(
driver
,
"https://www.safeway.com/"
,
email
,
password
);
Thread
.
sleep
(
5000
);
// Navigate to account settings
// Navigate to account settings
AccountSettings
accountSettings
=
new
AccountSettings
(
driver
);
AccountSettingsPage
accountSettingsPage
=
new
AccountSettingsPage
(
driver
);
accountSettings
.
goToAccountSettings
();
accountSettingsPage
.
goToAccountSettings
();
Thread
.
sleep
(
5000
);
// Assert Information is correct
// Assert Information is correct
Assertions
.
assertEquals
(
firstName
,
accountSettings
.
accountFirstName
.
getAttribute
(
"value"
));
wait
.
until
(
ExpectedConditions
.
elementToBeClickable
(
accountSettingsPage
.
accountFirstName
));
Assertions
.
assertEquals
(
lastName
,
accountSettings
.
accountLastName
.
getAttribute
(
"value"
));
Assertions
.
assertEquals
(
firstName
,
accountSettingsPage
.
accountFirstName
.
getAttribute
(
"value"
));
Assertions
.
assertEquals
(
email
,
accountSettings
.
accountEmail
.
getAttribute
(
"value"
));
Assertions
.
assertEquals
(
lastName
,
accountSettingsPage
.
accountLastName
.
getAttribute
(
"value"
));
Assertions
.
assertEquals
(
phoneNumber
,
accountSettings
.
accountPhoneNumber
.
getAttribute
(
"value"
));
Assertions
.
assertEquals
(
email
,
accountSettingsPage
.
accountEmail
.
getAttribute
(
"value"
));
Assertions
.
assertEquals
(
phoneNumber
,
accountSettingsPage
.
accountPhoneNumber
.
getAttribute
(
"value"
));
driver
.
quit
();
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