1 year ago

#368498

test-img

shubham sharma

second Test case is not call in testng maven project with selenium

I am trying to automate Justdial.com with the TestNG Maven project. My first test case "VerifyFlightClickTest" is working fine it is clicking on the Flight option by justdial the home page. After that, I created a new class for my second test searching the flight for my input(e.g - New Delhi to Jaipur on 04-April-2022). the test case name is "Validation_Flight_Booking" and the class name is "VerifyFlightBook". help me to find out what I am doing wrong

only one test is pass

------- This code is for driver location ------

package com.Automation.GenericUtils;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;


public class DriverUtils {
    
        static WebDriver driver;
        
        public static void createDriver()
        {
            System.setProperty("webdriver.chrome.driver", "C:\\Users\\ss49655\\eclipse-workspace\\JustDial_Shubham\\Driver\\chromedriver.exe");
            
            ChromeOptions option = new ChromeOptions();
            option.addArguments("start-maximized");
            option.addArguments("--disable-blink-features=AutomationControlled");
            option.addArguments("--disable-notifications");// Disabling any notifications
            driver=new ChromeDriver(option);
            driver.manage().window().maximize();    
        }
        
        public static WebDriver getDriver()
        {
            if(driver== null) {
            createDriver();
            }
            return driver;
        }

    }

------- This code is for Base page ----

package com.Automation.Pages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;

import com.Automation.GenericUtils.DriverUtils;

public class BasePage {
     WebDriver driver;

    public BasePage()
    {
        driver=DriverUtils.getDriver();
        PageFactory.initElements(driver,this);
        
    }
}

----- This code is for Home page (JustDial home page)------

package com.Automation.Pages;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class HomePage extends BasePage{

    @FindBy(xpath="//*[@id=\"hotkeys_text_25\"]")
    private WebElement KeyClick;
    
    public void clickOnFlights() {
        KeyClick.click();
    }
}

-------- this code is for base test---

package com.Automation.Test;

import java.io.FileNotFoundException;
import java.io.IOException;

import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;


public class BaseTest {
    WebDriver driver;
    
    @BeforeMethod
    
    public void setUp() throws FileNotFoundException, IOException
    {
        com.Automation.GenericUtils.DriverUtils.createDriver();
        
}
    /*@AfterMethod
    public void Close()
    {
        driver.quit();
    }*/
}

----------- This code is for clicking on the flights page -----

package com.Automation.Test;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;

import com.Automation.GenericUtils.DriverUtils;
import com.Automation.Pages.HomePage;

public class VerifyFlightClickTest extends BaseTest {
    @Test
    public void ValidateFlightClick () throws InterruptedException
    {
        DriverUtils.getDriver().get("https://www.justdial.com/");
    
    
        HomePage hp= new HomePage();
        
        hp.clickOnFlights();
}}

****** This code is for flight book page after clicking on the flights in home page----

package com.Automation.Pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class FlightBookPage extends BasePage{


    @FindBy(xpath="//input[@placeholder='Type Departure City']")
    private WebElement DC;
    
    
    @FindBy(xpath="//li[text()='New Delhi, IN - Indira Gandhi Airport (DEL)']")
    private WebElement Select_Airport;
    
    public void DepartureCity(String username)
    {
        DC.sendKeys(username);
        }
@FindBy(xpath="//input[@placeholder='Type Departure City']")
    private WebElement CityName1;
    
    @FindBy(xpath="//li[text()='New Delhi, IN - Indira Gandhi Airport (DEL)']")
    private WebElement airPort1;
    
    @FindBy(xpath="//input[@placeholder='Type Destination City']")
    private WebElement clickOnDestinationCity;
    
    @FindBy(xpath="//input[@placeholder='Type Destination City']")
    private WebElement typeDestinationCity;
    
    @FindBy(xpath="//li[text()='Jaipur, IN - Sanganeer (JAI)']")
    private WebElement selectDestinationCity;
    
    
    // SELECT DATE 
    
    @FindBy(xpath="//input[@placeholder='Select Date']")
    private WebElement dateClick;
    
    @FindBy(xpath="//*[@id=\"second_2022-04-04\"]")
    private WebElement myDate;
    
    //CLICK ON SEARCH BUTTON
    
    @FindBy(xpath="//input[@value='SEARCH']")
    private WebElement search;
    
    public void clickOnDeparture() {
        DC.click();
    }
    public void typeName(String username) {
        CityName1.sendKeys(username);
    }
    
    public void selectName() {
        airPort1.click();
    }
    
    public void DestinationCity() {
        clickOnDestinationCity.click();
    }
    
    public void typeName2(String username) {
        typeDestinationCity.sendKeys(username);
    }
    
    public void selectdescity() {
        selectDestinationCity.click();
    }
    
    public void clickOnDate() {
        dateClick.click();
    }
    
    public void MyDate() {
        myDate.click();
    }
    
    public void btnsearch() {
        search.click();
    }
    
}

This is for test flight book page ----

package com.Automation.Test;

import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;

import com.Automation.GenericUtils.DriverUtils;
import com.Automation.Pages.FlightBookPage;
import com.Automation.Pages.HomePage;

public class VerifyFlightBook extends BaseTest {

    
    
    @Test
            

    public void Validation_Flight_Booking() throws InterruptedException
    {   
        
        FlightBookPage fb=new FlightBookPage();
        
        fb.clickOnDeparture();
        fb.DepartureCity("New Delhi");
        /*fb.SelectAirport();
        fb.DestinationCity("Jaipur");
        fb.Destination();
        fb.Selectdate();
        fb.Date();
        fb.Flight_search();*/
        
        
        Thread.sleep(5000);
        fb.selectName();
        fb.DestinationCity();
        fb.typeName2("Jaipur");
        Thread.sleep(5000);
        fb.selectdescity();
        Thread.sleep(5000);
        fb.clickOnDate();
        fb.MyDate();
        Thread.sleep(5000);
        fb.btnsearch();
        
        
    }
    
    
    
}

java

windows

maven

selenium-webdriver

testng

0 Answers

Your Answer

Accepted video resources