Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SeleniumTraining
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
Qazi Zain
SeleniumTraining
Commits
0e1105f1
Commit
0e1105f1
authored
Nov 18, 2024
by
Qazi Zain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Page object model code is added in repo in scr/main
parent
95fdb042
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
229 additions
and
95 deletions
+229
-95
.gitignore
.gitignore
+4
-2
HomePage.java
src/main/java/PageObjectClasses/HomePage.java
+39
-0
LoginPage.java
src/main/java/PageObjectClasses/LoginPage.java
+37
-0
LoginTest.java
src/main/java/TestClasses/LoginTest.java
+62
-0
BaseTest.java
src/main/java/Utils/BaseTest.java
+30
-0
DataProviderfromExcel.java
src/test/java/DataProvider/DataProviderfromExcel.java
+0
-81
DropDowns.java
src/test/java/DropDownsTypes/DropDowns.java
+2
-3
RobotClass.java
src/test/java/RobotClass/RobotClass.java
+50
-0
Waits.java
src/test/java/Synchronization/Waits.java
+2
-2
TakeScreenShot.java
...t/java/Techniques/ChildWindowHandling/TakeScreenShot.java
+0
-1
testng.xml
testng.xml
+3
-6
No files found.
.gitignore
View file @
0e1105f1
...
...
@@ -46,6 +46,8 @@ pom.xml
# Ignore build directory (target)
target/
# Ignore src/main directory (if you want to ignore specific files/folders in src/main)
src/main/
test.txt
allure-results
src/main/java/PageObjectClasses/HomePage.java
0 → 100644
View file @
0e1105f1
package
PageObjectClasses
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.WebDriver
;
public
class
HomePage
{
// Web driver object create
protected
WebDriver
obj
;
private
By
WelcomeMessage
=
By
.
xpath
(
"//div[@class='login-container']//h2"
);
private
By
LogoutButton
=
By
.
className
(
"logout-btn"
);
// create constructor
public
HomePage
(
WebDriver
obj
)
{
this
.
obj
=
obj
;
}
// methods.
public
String
getText
()
{
String
fulltext
=
obj
.
findElement
(
WelcomeMessage
).
getText
();
String
[]
text
=
fulltext
.
split
(
" "
);
return
text
[
0
];
}
public
void
clickLogout
()
{
obj
.
findElement
(
LogoutButton
).
click
();
}
}
src/main/java/PageObjectClasses/LoginPage.java
0 → 100644
View file @
0e1105f1
package
PageObjectClasses
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebElement
;
public
class
LoginPage
{
// driver object
WebDriver
obj
;
private
By
usernameF
=
By
.
id
(
"inputUsername"
);
private
By
passwordF
=
By
.
xpath
(
"//input[@placeholder='Password']"
);
private
By
loginButton
=
By
.
cssSelector
(
".submit.signInBtn"
);
// Updated this line to use cssSelector instead of className
// Constructor
public
LoginPage
(
WebDriver
obj
)
{
this
.
obj
=
obj
;
// this.obj means class obj assigning the parameter obj value in it.
}
// Methods
public
void
enterUsername
(
String
username
)
{
obj
.
findElement
(
usernameF
).
sendKeys
(
username
);
}
public
void
enterPassword
(
String
password
)
{
obj
.
findElement
(
passwordF
).
sendKeys
(
password
);
}
public
void
clickSignButton
()
{
obj
.
findElement
(
loginButton
).
click
();
}
}
src/main/java/TestClasses/LoginTest.java
0 → 100644
View file @
0e1105f1
package
TestClasses
;
import
PageObjectClasses.HomePage
;
import
PageObjectClasses.LoginPage
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeMethod
;
import
org.testng.annotations.AfterMethod
;
import
org.testng.annotations.DataProvider
;
import
org.testng.annotations.Test
;
import
Utils.BaseTest
;
public
class
LoginTest
extends
BaseTest
{
@BeforeMethod
public
void
setUpTest
()
{
setUp
();
}
@Test
(
dataProvider
=
"sendData"
)
public
void
LoginTest
(
String
Username
,
String
Password
)
{
obj
.
get
(
"https://rahulshettyacademy.com/locatorspractice/"
);
// create object of page classes for use;
LoginPage
login
=
new
LoginPage
(
obj
);
HomePage
home
=
new
HomePage
(
obj
);
//-------------> now write test.
login
.
enterUsername
(
Username
);
login
.
enterPassword
(
Password
);
login
.
clickSignButton
();
// --------------> Add Assertion.
Assert
.
assertEquals
(
Password
,
"rahulshettyacademy"
);
}
@DataProvider
public
Object
[][]
sendData
()
{
// Correct the index order for username and password in the array
Object
[][]
data
=
new
Object
[
3
][
2
];
data
[
0
][
0
]
=
"Zain"
;
// username
data
[
0
][
1
]
=
"rahulshettyacademy"
;
// password
data
[
1
][
0
]
=
"yawar"
;
// username
data
[
1
][
1
]
=
"rahulshettyacademy"
;
// password
data
[
2
][
0
]
=
"Haseeb"
;
// username
data
[
2
][
1
]
=
"hi"
;
// password
return
data
;
}
@AfterMethod
public
void
tearDownTest
()
{
tearDown
();
}
}
src/main/java/Utils/BaseTest.java
0 → 100644
View file @
0e1105f1
package
Utils
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.firefox.FirefoxDriver
;
import
org.openqa.selenium.support.ui.WebDriverWait
;
import
java.time.Duration
;
public
class
BaseTest
{
protected
WebDriver
obj
;
public
void
setUp
()
{
obj
=
new
FirefoxDriver
();
//Applying wait for synchronization
obj
.
manage
().
timeouts
().
implicitlyWait
(
Duration
.
ofSeconds
(
5
));
WebDriverWait
wait
=
new
WebDriverWait
(
obj
,
Duration
.
ofSeconds
(
8
));
}
public
void
tearDown
()
{
if
(
obj
!=
null
)
obj
.
close
();
}
}
src/test/java/DataProvider/DataProviderfromExcel.java
deleted
100644 → 0
View file @
95fdb042
package
DataProvider
;
import
org.apache.poi.xssf.usermodel.XSSFSheet
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebElement
;
import
org.openqa.selenium.firefox.FirefoxDriver
;
import
org.openqa.selenium.support.ui.ExpectedConditions
;
import
org.openqa.selenium.support.ui.WebDriverWait
;
import
org.testng.annotations.AfterClass
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.DataProvider
;
import
org.testng.annotations.Test
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.time.Duration
;
public
class
DataProviderfromExcel
{
WebDriver
obj
=
new
FirefoxDriver
();
WebDriverWait
wait
=
new
WebDriverWait
(
obj
,
Duration
.
ofSeconds
(
20
));
@BeforeClass
void
setup
()
{
obj
.
get
(
"https://rahulshettyacademy.com/locatorspractice/"
);
obj
.
manage
().
timeouts
().
implicitlyWait
(
Duration
.
ofSeconds
(
10
));
}
@Test
(
dataProvider
=
"dataStorage"
)
void
LoginTest
(
String
username
,
String
password
)
{
WebElement
usernameField
=
obj
.
findElement
(
By
.
id
(
"inputUsername"
));
wait
.
until
(
ExpectedConditions
.
visibilityOf
(
usernameField
));
usernameField
.
sendKeys
(
username
);
usernameField
.
clear
();
WebElement
passwordField
=
obj
.
findElement
(
By
.
xpath
(
"//input[@placeholder='Password']"
));
passwordField
.
sendKeys
(
password
);
usernameField
.
clear
();
obj
.
findElement
(
By
.
className
(
"submit"
)).
click
();
}
@DataProvider
(
name
=
"dataStorage"
)
public
Object
[][]
dataStorage
()
throws
IOException
{
String
filePath
=
"//Users//zain//Documents//dataproviderfile.xlsx"
;
FileInputStream
fileInputStream
=
new
FileInputStream
(
filePath
);
// Load workbook and sheet
XSSFWorkbook
workbook
=
new
XSSFWorkbook
(
fileInputStream
);
XSSFSheet
sheet
=
workbook
.
getSheetAt
(
0
);
int
rows
=
sheet
.
getPhysicalNumberOfRows
();
int
cols
=
sheet
.
getRow
(
0
).
getPhysicalNumberOfCells
();
Object
[][]
data
=
new
Object
[
rows
-
1
][
cols
];
for
(
int
i
=
1
;
i
<
rows
;
i
++)
{
for
(
int
j
=
0
;
j
<
cols
;
j
++)
{
data
[
i
-
1
][
j
]
=
sheet
.
getRow
(
i
).
getCell
(
j
).
toString
();
}
}
workbook
.
close
();
fileInputStream
.
close
();
return
data
;
}
@AfterClass
void
Exit
()
{
obj
.
quit
();
}
}
src/test/java/
Techniques_to_automate_web_Element/WebElementAutomation
.java
→
src/test/java/
DropDownsTypes/DropDowns
.java
View file @
0e1105f1
package
Techniques_to_automate_web_Element
;
package
DropDownsTypes
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.WebDriver
;
...
...
@@ -6,9 +6,8 @@ import org.openqa.selenium.WebElement;
import
org.openqa.selenium.firefox.FirefoxDriver
;
import
org.openqa.selenium.support.ui.Select
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
WebElementAutomation
{
public
class
DropDowns
{
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
WebDriver
obj
=
new
FirefoxDriver
();
// for maximizing the window.
...
...
src/test/java/RobotClass/RobotClass.java
0 → 100644
View file @
0e1105f1
package
RobotClass
;
import
java.awt.*
;
import
java.awt.event.KeyEvent
;
import
java.time.Duration
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.WebDriver
;
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
;
public
class
RobotClass
{
public
static
void
main
(
String
[]
args
)
{
WebDriver
obj
=
new
ChromeDriver
();
try
{
// Navigate to the URL
obj
.
get
(
"https://demo.automationtesting.in/Register.html"
);
// Set implicit wait
obj
.
manage
().
timeouts
().
implicitlyWait
(
Duration
.
ofSeconds
(
50
));
// Explicit wait for the file upload button
WebDriverWait
wait
=
new
WebDriverWait
(
obj
,
Duration
.
ofSeconds
(
50
));
WebElement
FileUpload
=
wait
.
until
(
ExpectedConditions
.
presenceOfElementLocated
(
By
.
xpath
(
"//input[@id='imagesrc']"
)));
// Use sendKeys() to upload the file
FileUpload
.
sendKeys
(
"/Users/zain/Documents/SeleniumTraining/screenshot.png"
);
// Optionally use Robot class for additional interactions if needed
try
{
Robot
robo
=
new
Robot
();
robo
.
keyPress
(
KeyEvent
.
VK_ENTER
);
robo
.
keyRelease
(
KeyEvent
.
VK_ENTER
);
}
catch
(
AWTException
e
)
{
e
.
printStackTrace
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
// Close the browser
obj
.
quit
();
}
}
}
src/test/java/
FunctionalTesting/Practice
.java
→
src/test/java/
Synchronization/Waits
.java
View file @
0e1105f1
package
FunctionalTesting
;
package
Synchronization
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.WebDriver
;
...
...
@@ -10,7 +10,7 @@ import org.testng.asserts.SoftAssert;
import
java.time.Duration
;
public
class
Practice
{
public
class
Waits
{
public
static
void
main
(
String
[]
args
)
{
WebDriver
obj
=
new
FirefoxDriver
();
...
...
src/test/java/Techniques/ChildWindowHandling/TakeScreenShot.java
View file @
0e1105f1
...
...
@@ -38,6 +38,5 @@ public class TakeScreenShot {
{
System
.
out
.
println
(
"File not found"
);
}
}
}
testng.xml
View file @
0e1105f1
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite
name=
"All Test Suite"
>
<test
verbose=
"2"
preserve-order=
"true"
name=
"/Users/zain/IdeaProjects/SeleniumTraining/src/test/java/AllureReporting"
>
<test
verbose=
"2"
preserve-order=
"true"
name=
"/Users/zain/Documents/SeleniumTraining/src/main/java"
>
<classes>
<class
name=
"
AllureReporting.Tests
"
>
<class
name=
"
TestClasses.LoginTest
"
>
<methods>
<include
name=
"correctRedirect"
/>
<include
name=
"login"
/>
<include
name=
"reg"
/>
<include
name=
"LoginTest"
/>
</methods>
</class>
</classes>
...
...
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