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
41bf91e4
Commit
41bf91e4
authored
Nov 25, 2024
by
Qazi Zain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated nisum code
parent
c369b476
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
197 additions
and
74 deletions
+197
-74
Nisum.feature
src/main/java/NisumWebTest/Cucumber/Nisum.feature
+9
-9
TestRunner.java
src/main/java/NisumWebTest/Cucumber/TestRunner.java
+11
-6
NisumPage.java
src/main/java/NisumWebTest/PageObject/NisumPage.java
+46
-43
StepDefination.java
...main/java/NisumWebTest/StepDefination/StepDefination.java
+30
-16
BaseTestNisum.java
src/main/java/NisumWebTest/Utils/BaseTestNisum.java
+30
-0
DataProviderExcel.java
src/test/java/DataProvider/DataProviderExcel.java
+71
-0
No files found.
src/main/java/NisumWebTest/Cucumber/Nisum.feature
View file @
41bf91e4
@Navigate
Feature
:
Navigate Functionality
Feature
:
Hiring validation Validate that Nisum Pakistan is hiring.
@PositiveScenario
Scenario Outline
:
Validate the links navigate to the correct page
Given
User is Present on nisum Website
When
User click on Global Career and then click on pakistan
Then
User Should see
"<expectedText>"
on Page
Scenario Outline
:
Validate hiring
Given
user is on the Google home page
When
user enters
"<text>"
in the search bar and clicks on search
And
user selects the top search result for Nisum and clicks on it
And
user hovers over Global Careers and clicks on Pakistan
Then
the user should see the text hiring on the page
Examples
:
|
expectedText
|
|
We're
Hiring
Now!
|
|
text
|
|
nisum
|
\ No newline at end of file
src/main/java/NisumWebTest/Cucumber/TestRunner.java
View file @
41bf91e4
package
NisumWebTest
.
Cucumber
;
import
io.cucumber.testng.AbstractTestNGCucumberTests
;
import
io.cucumber.testng.CucumberOptions
;
import
io.cucumber.testng.AbstractTestNGCucumberTests
;
@CucumberOptions
(
features
=
"src/main/java/NisumWebTest/Cucumber/Nisum.feature"
,
// Path to your feature file
glue
=
"NisumWebTest/StepDefination"
,
// Path to your step definition package
plugin
=
{
"pretty"
,
"html:target/cucumber-reports/cucumber.html"
,
// "io.qameta.allure.cucumber6jvm.AllureCucumber6Jvm" // Allure plugin
})
@CucumberOptions
(
features
=
"src/main/java/NisumWebTest/Cucumber"
,
glue
=
"NisumWebTest.StepDefination"
,
monochrome
=
true
,
plugin
=
{
"html:target/Nisumcucumber.html"
})
public
class
TestRunner
extends
AbstractTestNGCucumberTests
{
public
class
TestRunner
extends
AbstractTestNGCucumberTests
{
}
}
\ No newline at end of file
src/main/java/NisumWebTest/PageObject/NisumPage.java
View file @
41bf91e4
package
NisumWebTest
.
PageObject
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebElement
;
import
org.openqa.selenium.interactions.Actions
;
import
org.openqa.selenium.support.FindBy
;
import
org.openqa.selenium.support.PageFactory
;
import
org.openqa.selenium.support.ui.ExpectedCondition
;
import
org.openqa.selenium.support.ui.ExpectedConditions
;
import
org.openqa.selenium.support.ui.WebDriverWait
;
import
javax.swing.*
;
import
java.time.Duration
;
public
class
NisumPage
{
public
class
NisumPage
{
WebDriver
obj
;
Actions
mouse
;
WebDriverWait
wait
;
// locators
@FindBy
(
css
=
"textarea[class='gLFyf']"
)
WebElement
googleSearchBar
;
@FindBy
(
css
=
"a[href='https://www.nisum.com/']"
)
WebElement
nisumWeb
;
@FindBy
(
xpath
=
"(//a[@href='https://www.nisum.com/careers'])[1]"
)
WebElement
globalCareers
;
@FindBy
(
xpath
=
"(//a[@href='https://www.nisum.com/careers/careers-pakistan'])[1]"
)
WebElement
pakistanCareer
;
@FindBy
(
xpath
=
"//div[@class='hhs-rich-text-in']//h1"
)
WebElement
hiring
;
@FindBy
(
xpath
=
"(//a[@href='javascript:void(0);'])[3]"
)
WebElement
declineAll
;
@FindBy
(
xpath
=
"(//input[@class='gNO89b'])[2]"
)
WebElement
searchButton
;
public
NisumPage
(
WebDriver
obj
)
{
this
.
obj
=
obj
;
PageFactory
.
initElements
(
obj
,
this
);
wait
=
new
WebDriverWait
(
obj
,
Duration
.
ofSeconds
(
8
));
}
@FindBy
(
xpath
=
"//div[@class='hhs-header-menu custom-menu-primary js-enabled']//*[text()='Global Careers']"
)
WebElement
CareerDropDown
;
@FindBy
(
xpath
=
"(//div[@class='hhs-header-menu custom-menu-primary js-enabled']//*[@href='https://www.nisum.com/careers/careers-pakistan'])[1]"
)
WebElement
PakistanCareer
;
@FindBy
(
xpath
=
"//div[@class='hhs-rich-text wow fadeIn']//h1"
)
WebElement
HiringHeading
;
//---------------------------------------> Action Flow.
public
void
RunFlow
()
{
Actions
mouse
=
new
Actions
(
obj
);
mouse
.
moveToElement
(
CareerDropDown
).
build
().
perform
();
PakistanCareer
.
click
();
}
public
String
PassText
()
{
wait
.
until
(
ExpectedConditions
.
visibilityOf
(
HiringHeading
));
return
HiringHeading
.
getText
();
}
}
mouse
=
new
Actions
(
obj
);
wait
=
new
WebDriverWait
(
obj
,
Duration
.
ofSeconds
(
10
));
}
// action methods.
public
void
searchNisum
(
String
search
)
{
wait
.
until
(
ExpectedConditions
.
visibilityOf
(
googleSearchBar
));
googleSearchBar
.
sendKeys
(
search
);
searchButton
.
click
();
}
public
void
clickOnNisum
()
{
nisumWeb
.
click
();
}
public
void
click_pakistan_career
()
{
declineAll
.
click
();
mouse
.
moveToElement
(
globalCareers
).
build
().
perform
();
wait
.
until
(
ExpectedConditions
.
elementToBeClickable
(
pakistanCareer
));
mouse
.
moveToElement
(
pakistanCareer
);
pakistanCareer
.
click
();
}
public
String
hiringValidation
()
{
wait
.
until
(
ExpectedConditions
.
visibilityOf
(
hiring
));
return
hiring
.
getText
();
}
}
\ No newline at end of file
src/main/java/NisumWebTest/StepDefination/StepDefination.java
View file @
41bf91e4
package
NisumWebTest
.
StepDefination
;
import
NisumWebTest.PageObject.NisumPage
;
import
NisumWebTest.Utils.BaseTest
;
import
NisumWebTest.Utils.BaseTestNisum
;
import
io.cucumber.java.en.And
;
import
io.cucumber.java.en.Given
;
import
io.cucumber.java.en.When
;
import
io.cucumber.java.en.Then
;
import
io.cucumber.java.en.When
;
import
org.testng.Assert
;
public
class
StepDefination
extends
BaseTest
{
public
class
StepDefination
extends
BaseTestNisum
{
NisumPage
page
;
NisumPage
object
;
@Given
(
"user is on the Google home page"
)
public
void
user_is_on_the_google_home_page
()
{
setUp
();
}
@Given
(
"User is Present on nisum Website"
)
public
void
user_is_present_on_nisum_website
()
{
setUp
();
// Setup WebDriver and navigate to the site
object
=
new
NisumPage
(
driver
);
// Initialize the page object after WebDriver is set up
@When
(
"user enters {string} in the search bar and clicks on search"
)
public
void
user_enter_text_in_the_search_bar_and_clicks_on_search
(
String
text
)
{
page
=
new
NisumPage
(
obj
);
page
.
searchNisum
(
text
);
}
@And
(
"user selects the top search result for Nisum and clicks on it"
)
public
void
user_selects_the_top_search_result_for_Nisum_and_clicks_on_it
()
{
page
.
clickOnNisum
();
}
@When
(
"User click on Global Career and then click on pakistan"
)
public
void
user_click_on_global_career_and_then_click_on_pakistan
()
{
object
.
RunFlow
();
// Perform actions on the page object
@And
(
"user hovers over Global Careers and clicks on Pakistan"
)
public
void
user_hovers_over_Global_Careers_and_clicks_on_Pakistan
()
{
page
.
click_pakistan_career
();
}
@Then
(
"User Should see {string} on Page"
)
public
void
user_should_see_we_re_hiring_now_on_page
(
String
expectedText
)
{
Assert
.
assertEquals
(
object
.
PassText
(),
expectedText
);
// Validate the text on the page
@Then
(
"the user should see the text hiring on the page"
)
public
void
the_user_should_see_the_text_hiring_on_the_page
()
{
Assert
.
assertEquals
(
page
.
hiringValidation
(),
"We're Hiring Now!"
);
}
}
}
\ No newline at end of file
src/main/java/NisumWebTest/Utils/BaseTest.java
→
src/main/java/NisumWebTest/Utils/BaseTest
Nisum
.java
View file @
41bf91e4
package
NisumWebTest
.
Utils
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.
firefox.Firefox
Driver
;
import
org.openqa.selenium.support.ui.WebDriverWait
;
import
org.openqa.selenium.
chrome.Chrome
Driver
;
import
org.testng.annotations.AfterMethod
;
import
org.testng.annotations.BeforeMethod
;
import
java.time.Duration
;
public
class
BaseTest
{
public
WebDriver
driver
;
public
class
BaseTestNisum
{
protected
WebDriver
obj
;
@BeforeMethod
public
void
setUp
()
{
driver
=
new
FirefoxDriver
();
driver
.
get
(
"https://www.nisum.com/"
);
obj
=
new
ChromeDriver
();
obj
.
manage
().
window
().
maximize
();
obj
.
get
(
"https://www.google.com.pk/"
);
}
@AfterMethod
public
void
tearDown
()
{
if
(
driver
!=
null
)
{
driver
.
quit
();
}
if
(
obj
!=
null
)
{
obj
.
close
();
obj
.
manage
().
deleteAllCookies
();
}
}
}
}
\ No newline at end of file
src/test/java/DataProvider/DataProviderExcel.java
0 → 100644
View file @
41bf91e4
package
DataProvider
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.WebElement
;
import
org.openqa.selenium.firefox.FirefoxDriver
;
import
org.testng.annotations.AfterClass
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.DataProvider
;
import
org.testng.annotations.Test
;
import
java.io.BufferedReader
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
DataProviderExcel
{
WebDriver
obj
;
@BeforeClass
void
before
()
{
obj
=
new
FirefoxDriver
();
obj
.
get
(
"https://rahulshettyacademy.com/locatorspractice/"
);
}
@Test
(
dataProvider
=
"getData"
)
// adding data provider name on the test.
void
Test1
(
String
Username
,
String
Password
)
{
WebElement
username
=
obj
.
findElement
(
By
.
id
(
"inputUsername"
));
username
.
clear
();
// --------> for next value to be test.
username
.
sendKeys
(
Username
);
WebElement
password
=
obj
.
findElement
(
By
.
xpath
(
"//input[@placeholder='Password']"
));
password
.
clear
();
//---------> clearing for next value to be test.
password
.
sendKeys
(
Password
);
obj
.
findElement
(
By
.
className
(
"signInBtn"
)).
click
();
// clicking on button.
}
@DataProvider
Object
[][]
getData
()
throws
IOException
{
String
csv
=
"/Users/zain/Documents/Copy of dataproviderfile.csv"
;
BufferedReader
br
=
new
BufferedReader
(
new
FileReader
(
csv
));
List
<
String
[]>
data
=
new
ArrayList
<>();
String
line
;
while
((
line
=
br
.
readLine
())
!=
null
)
{
String
[]
lineData
=
line
.
split
(
","
);
data
.
add
(
lineData
);
}
br
.
close
();
// Convert List to a 2D array and return it
return
data
.
toArray
(
new
Object
[
0
][
0
]);
}
@AfterClass
void
tearDown
()
{
obj
.
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