Commit 41bf91e4 authored by Qazi Zain's avatar Qazi Zain

Updated nisum code

parent c369b476
@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
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
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
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
package NisumWebTest.Utils;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.chrome.ChromeDriver;
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
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();
}
}
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