package farekeypakg;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.io.FileHandler;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Searchmodule {

	WebDriver driver;
	WebDriverWait wait;
	
//Wait for fare  update 
	//WebDriverWait wait1 = new WebDriverWait(driver, Duration.ofSeconds(10));
	
    XSSFWorkbook wb;
    XSSFSheet sh;
    XSSFWorkbook wb1;
    XSSFSheet sh1;
    int totalRows;
    int Rowcount;
    String InputMonthYear = "October 2025";
    String InputDate = "22";
    String Returnmonthyear = "October 2025";
    String Returndate = "25";
    String adultCount = "1";
    String childCount = "0";
    String infantCount = "0";
    String EmailID = "amaljoseph935@gmail.com";
    String Phonenumber = "9074479355";
    String AdultFname = "Amal";
    String AdultLname = "Joseph";
    String ChildFname = "Yadu";
    String ChildLname = "Krishna";
    String Adultpassnumber = "F98523654";
    String Childpassnumber = "M85496523";
    String InfantFname = "Mohammed";
    String InfantLname = "Fayiz";
    String Infantpassnumber = "P85697458";
    
    

//	@BeforeTest
//	public void chromeloading() {
//		driver=new ChromeDriver();
//		driver.get("https://uat.farekey.com/");
//		driver.manage().window().maximize();
//		
//	}
    int Adultcount = Integer.parseInt(adultCount);
    int Childcount = Integer.parseInt(childCount);
    int Infantcount = Integer.parseInt(infantCount);
    
    @BeforeTest
    public void loadExcelData() throws IOException {
        FileInputStream f = new FileInputStream("C:\\Testdata\\Searchdata.xlsx");
        wb = new XSSFWorkbook(f);
        sh = wb.getSheet("Sheet1");
        totalRows = sh.getLastRowNum();  // For looping through rows
        
        //Excel details for fare key partners
        FileInputStream f1=new FileInputStream("C:\\Testdata\\Farekeypartners.xlsx");
        wb1 = new XSSFWorkbook(f1);
        sh1 = wb1.getSheet("Sheet1");
        Rowcount = sh1.getLastRowNum();
        
    }
    
    @Test(priority = 1)
    public void runSearchmultipleTimes() throws InterruptedException, IOException {
        //int executionCount = 13;

        for (int i = 0; i < totalRows; i++) {

            // Calculate Excel row index (looping if needed)
            int rowIndex = (i % totalRows) + 1; // +1 to skip header

            String fromCity = sh.getRow(rowIndex).getCell(0).getStringCellValue();
            String toCity = sh.getRow(rowIndex).getCell(1).getStringCellValue();

            System.out.println("Execution #" + (i + 1) + ": " + fromCity + " --> " + toCity);

            
            driver = new ChromeDriver();
            wait = new WebDriverWait(driver, Duration.ofSeconds(20)); 
            driver.get("https://uat.farekey.com/");
            driver.manage().window().maximize();
            
         File src2 =  (( TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
         FileHandler.copy(src2, new File("./Screenshot/Homepage.png"));
         //-----------------------------------------------------------------------------
          //one way
//            WebElement oneway=driver.findElement(By.xpath("//a[@id='OneWay']"));
//            oneway.click();
//            Thread.sleep(2000);
         //------------------------------------------------------------------------------   
            
            WebElement fromInput = driver.findElement(By.xpath("//div[@class='hm_col_01 ']/label"));
            fromInput.click();
            Thread.sleep(3000);
            fromInput.sendKeys(fromCity);
            Thread.sleep(2000);
            WebElement cityselection=driver.findElement(By.xpath("(//a[@id='async-example-item-0'])[1]"));
            cityselection.click();
            System.out.println("Selected from city");
            
            WebElement toInput = driver.findElement(By.xpath("//div[@class='hm_col_01']/label"));
            //Thread.sleep(3000);
            toInput.click();
            Thread.sleep(3000);
            //toInput.clear();
            toInput.sendKeys(toCity);
            Thread.sleep(2000);
            WebElement cityselection1=driver.findElement(By.xpath("(//a[@id='async-example-item-0'])[1]"));
            cityselection1.click();
            System.out.println("Selected To city");
            Thread.sleep(3000);
 //onward calendar============================================================================================================
            WebElement calendar1click=driver.findElement(By.xpath("(//div[@class='react-datepicker-wrapper'])[1]"));
       	    calendar1click.click();
       	    
       	
       	    selectonwardDate(InputMonthYear, InputDate);
       	    Thread.sleep(2000);
       	    WebElement calander1apply=driver.findElement(By.xpath("//button[@class='button-apply']"));
       	    calander1apply.click();
 //=========================================================================================================================
    //return calendar===================
       	    WebElement calendar2click=driver.findElement(By.xpath("(//div[@class='react-datepicker-wrapper'])[2]"));
       	    calendar2click.click();
       	    selectreturnDate(Returnmonthyear,Returndate);
       	    Thread.sleep(2000);
       	    WebElement calander2apply=driver.findElement(By.xpath("//button[@class='button-apply']"));
    	    calander2apply.click();
 //=========================================================================================================================      	    
    //Passenger selection
    	    Thread.sleep(2000);
    	    driver.findElement(By.xpath("//div[contains(@class,'hm_btm_psngr_col_01 bdr_btm HmTravel')]")).click();
    	    setPassengers(adultCount, childCount, infantCount);
    	    Thread.sleep(2000);
    	    WebElement cabinclass=driver.findElement(By.xpath("//select[@id=\" \"]"));
    	    cabinclass.click();
    	    Thread.sleep(1000);
    	    Select sc=new Select(cabinclass);
    	    sc.selectByIndex(0);
    	    System.out.println("Cabin is selected");
    	    Thread.sleep(2000);
    	    driver.findElement(By.xpath("//div[@class='psngr_applyBox']//button")).click();
    	    
 //=================================================================================================================================      	    
       	    //preffered airline option
//    	    Thread.sleep(2000);
//    	    WebElement prefferedairline=driver.findElement(By.xpath("(//div[@class='hm_btm_col_01 bdr_btm col_01_mrgn_lft preferedAirlineHm']//input)[1]"));
//    	    prefferedairline.click();
//    	    Thread.sleep(1000);
//    	    prefferedairline.sendKeys("XY");//Pass airline codes
//    	    Thread.sleep(1000);
//    	    prefferedairline.sendKeys(Keys.ARROW_DOWN);
//    	    prefferedairline.sendKeys(Keys.ENTER);
    	    
//===================================================================================================================================    	    
       	    //direct flight button
//    	    Thread.sleep(2000);
//    	    driver.findElement(By.xpath("//div[@class='hm_nonstop']")).click();
//==============================================================================================================================        
            //Search button
    	    Thread.sleep(2000);
    	    WebElement searchbutton=driver.findElement(By.xpath("//div[@class='hm_btm_col_01  ']//button"));
    	    searchbutton.click();
    	    System.out.println("Search Button Clicked");
    	    Thread.sleep(3000);
//========================================================================================================================   	    
    	     WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(120));
    	     WebElement loader=driver.findElement(By.xpath("//div[contains(@class,'progress mb-4')]"));
    	     
    	     wait.until(ExpectedConditions.invisibilityOf(loader));
    	     
    	     
    	     List<WebElement> resultList = driver.findElements(By.xpath("(//div[@class='result_panel'])[1]"));

    	     if (!resultList.isEmpty()) {
    	         WebElement resultcheck = resultList.get(0);
    	         //if condition for the 'result found' and 'no result found '.
    	         if (resultcheck.isDisplayed()) {
    	             System.out.println("Result found for particular search scenario");
    	            File src= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    	            FileHandler.copy(src, new File("./Screenshot/Resultfound.png"));
    	            Thread.sleep(2000);
    	            //scroll for present ''partners' filter
    	            WebElement scrollelement = driver.findElement(By.xpath("(//div[@class='Filterhead'])[5]"));
    	    		JavascriptExecutor js= (JavascriptExecutor) driver;
    	    		js.executeScript("arguments[0].scrollIntoView(true);",scrollelement);
    	    		
    	    		Thread.sleep(5000);
    	    																											
    	    		
    	    		
  //Path for the available partner in the result page.
    	    		List<WebElement> partnersdetail=driver.findElements(By.xpath("//div[@class=\"Filterbox\"]//span[text()=\"Partners\"]/ancestor::div[@class=\"Filterbox\"]//div[contains(@class,\"FilterContent\")]//li"));
    	    		
  //store data in list.
    	    		List<String> availablepartners = new ArrayList<>();
  //Specifying a partner name for check it was available if it is available and continue with it.
    	    		String selectpartner="Tripjet";

    	    		for (WebElement partnersdetail1 : partnersdetail) {
    	    		    String partnerss = partnersdetail1.getText().trim();
    	    		 // save it in the list
    	    		    availablepartners.add(partnerss);    	    		    
    	    		    
    	    		    System.out.println("Available Partners for the serach = " + partnerss);
    	    		    
    	    		 // Now compare this partner with all partners from Excel
    	    		    for (int j = 1; j <= Rowcount; j++) {   // start at 1 if row 0 = header
    	    		        String farekeypartners = sh1.getRow(j).getCell(0).getStringCellValue().trim();
    	    		        
    	    		        if (partnerss.equalsIgnoreCase(farekeypartners)) {
    	    		            System.out.println("MATCH FOUND: Partner for the search = " + partnerss + "  ||  Onboarded Partner = " + farekeypartners);
    	    		        } else {
    	    		            System.out.println("NO MATCH: Partner for the search = " + partnerss + "  ||  Onboarded Partner = " + farekeypartners);
    	    		        }
    	    		    }
    	    		
    	    		}
    	    		   	    		    	    		
    	    		System.out.println("All Available Partners in this search stored in List = " + availablepartners);
    	    		
    	    		if (availablepartners.contains(selectpartner)) {
    	    		    System.out.println("✔ SELECTED PARTNER FOUND: " + selectpartner + " is available in the search results.");
    	    		} else {
    	    		    System.out.println("❌ SELECTED PARTNER NOT FOUND: " + selectpartner + " is NOT available in the search results.");
    	    		}
    	    		//for checking the value given in the string is available in the List.
    	    		
    	    		
    	    		Thread.sleep(3000);
    	    		WebElement scrollelement1 = driver.findElement(By.xpath("//div[@class='sort_list']"));        
     	    		JavascriptExecutor js1= (JavascriptExecutor) driver;
     	    		js1.executeScript("arguments[0].scrollIntoView(true);",scrollelement1);
     	    		Thread.sleep(2000);
     	    		
     	    		
     	   //======================================================================================================= 		
   //condition for select airline based on given string.
     	    		List<WebElement> airlines=driver.findElements(By.xpath("(//div[@class='FilterContent packFilterType'])[2]//label"));    	    		
     	    		String Airline = "EE";
     	    		boolean airlinematch=false;
     	    		for(WebElement airlines1 : airlines) {
     	    			String airliness=airlines1.getAttribute("for");
     	    			System.out.println("Airlines available for the search result :" +airliness);
     	    			
     	    			if(airliness.equalsIgnoreCase(Airline)) {
     	    				airlines1.click();
     	    				System.out.println("Provided airline  = " +airliness+ " is available in result and Selected.");
     	    				airlinematch=true;
     	    			}    	    			
     	    		}
     	    		if(!airlinematch) {
     	    			System.out.println("The provided airline " +Airline+ " is not available in the result.");
     	    		}
  //===================================================================================================================		
     	    		
     	    		
     	    		Thread.sleep(3000);
     	    		//clicking on a Result
     	    		
//     	    		WebElement scroll = driver.findElement(By.xpath("(//div[@class='react-stacked-center-carousel-slide-0'])[3]"));
//     	    		JavascriptExecutor scc= (JavascriptExecutor) driver;
//     	    		scc.executeScript("arguments[0].scrollIntoView(true);",scroll);	    		
//     	    		Thread.sleep(2000);
     	    		
     	    		driver.findElement(By.xpath("(//div[@class='react-stacked-center-carousel-slide-0'])[2]")).click();
     	    		Thread.sleep(2000);
     	    		WebElement scrollelement2 = driver.findElement(By.xpath("(//div[@class='result_flightdtls'])[2]"));
     	    		JavascriptExecutor js2= (JavascriptExecutor) driver;
     	    		js2.executeScript("arguments[0].scrollIntoView(true);",scrollelement2);
     	    		
     	    		WebDriverWait wait1 = new WebDriverWait(driver, Duration.ofSeconds(120));
     	    		wait1.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("(//div[@class='w-100']//button)[1]")));
 //=====================================================================================================================
     	    //condition for selecting branded fare.		
     	    		String selectfare="ECO FLEX-ECO FLEX";
	
     	    		boolean fareMatched = false;

     	    		int maxNextClicks = 10;
     	    		int clickCount = 0;

     	    		// Track already checked fares to avoid re-checking duplicates
     	    		Set<String> checkedFares = new HashSet<>();

     	    		while (true) {
     	    		    // Get all currently visible branded fare boxes
     	    		    List<WebElement> fareBoxes = driver.findElements(By.xpath("//div[@class='brandedFareBox' and not(contains(@style,'display: none'))]"));

     	    		    for (WebElement brandedfare : fareBoxes) {
     	    		        String fareheading = brandedfare.findElement(By.xpath(".//div[@class='brandL']//h2")).getText().trim();

     	    		        // Skip duplicates already checked
     	    		        if (checkedFares.contains(fareheading)) {
     	    		            continue;
     	    		        }

     	    		        checkedFares.add(fareheading);

     	    		        if (!fareheading.isEmpty()) {
     	    		            System.out.println("Available branded fare name: " + fareheading);
     	    		        }

     	    		        if (fareheading.equalsIgnoreCase(selectfare)) {
     	    		        	
     	    		        	
     	    		        	WebElement fareoption=driver.findElement(By.xpath(".//div[@class='moreFaresAvailable']/span"));
     	        	    		String resultfaeropt= fareoption.getText();
     	        	    		String numberOnly = resultfaeropt.replaceAll("[^0-9]", "");
     	        	    		System.out.println("fare option text selected for the provided fare =" +numberOnly);
     	        	    		Thread.sleep(1000);
     	        	    		
     	        	    		
     	    		            brandedfare.findElement(By.xpath(".//button[contains(@class, 'brndedBookBtn')]")).click();
     	    		            System.out.println("Selected the branded fare based on provided input: " + selectfare);
     	    		            fareMatched = true;
     	    		            
     	    		            
     	    		           driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(20));
     	       	    		//fare option in review page
     	       	    		WebElement fareoption1=driver.findElement(By.xpath("//div[@class='fareOptionHead']"));
     	       	    		String reviewfareopt=fareoption1.getText();
     	       	    		String numberonly1 = reviewfareopt.replaceAll("[^0-9]", "");
     	       	    		System.out.println("fare option text in review page =" +numberonly1);
     	       	    		if(numberOnly.equals(numberonly1))
     	       	    		{
     	       	    			System.out.println("Selected fare option is same in result & review page");
     	       	    		}else {
     	       	    			System.out.println("Selected fare option is not same in result & review page");
     	       	    		}
        
     	    		            break;
     	    		        }   
     	    		    }

     	    		    if (fareMatched) break;

     	    		    // If not matched, click next button if available for check other branded fare.
     	    		    List<WebElement> nextArrow = driver.findElements(By.xpath("//button[@class='owl-next']"));
     	    		    if (!nextArrow.isEmpty() && nextArrow.get(0).isDisplayed() && nextArrow.get(0).isEnabled() && clickCount < maxNextClicks) {
     	    		        nextArrow.get(0).click();
     	    		        Thread.sleep(1200); 
     	    		        clickCount++;
     	    		    } else {
     	    		        break; // stop if no more arrows
     	    		    }
     	    		}

     	    		// After click the next arrow then no match found then click the back arrow for occure initial result.
     	    		if (!fareMatched) {
     	    		    System.out.println(" Branded fare not matched. Resetting branded fare section as initialy provided.");

     	    		    List<WebElement> prevArrow = driver.findElements(By.xpath("//button[contains(@class,'owl-prev')]"));
     	    		    int backClick = 0;
     	    		    while (!prevArrow.isEmpty() && prevArrow.get(0).isDisplayed() && prevArrow.get(0).isEnabled() && backClick < maxNextClicks) {
     	    		        prevArrow.get(0).click();
     	    		        Thread.sleep(1000); // allow transition
     	    		        backClick++;
     	    		        prevArrow = driver.findElements(By.xpath("//button[contains(@class,'owl-prev')]"));
     	    		    }

     	    	
     	    		    
     	    		   WebElement fareoption=driver.findElement(By.xpath("(//div[@class='moreFaresAvailable']/span)[1]"));
        	    		String resultfaeropt= fareoption.getText();
        	    		String numberOnly = resultfaeropt.replaceAll("[^0-9]", "");
        	    		System.out.println("fare option text for the first branded fare =" +numberOnly);
        	    		Thread.sleep(1000);
        	    		
        	    		//selecting first fare if the provided branded fare not found.
     	    		    driver.findElement(By.xpath("(//div[@class='w-100']//button)[1]")).click();
     	    		    System.out.println("No-Such branded fare matched as provided--Selected the first fare option .");
     	    		    
     	    		    
     	    		   driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(20));
        	    		//fare option in review page
        	    		WebElement fareoption1=driver.findElement(By.xpath("//div[@class='fareOptionHead']"));
        	    		String reviewfareopt=fareoption1.getText();
        	    		String numberonly1 = reviewfareopt.replaceAll("[^0-9]", "");
        	    		System.out.println("fare option text in review page =" +numberonly1);
        	    		if(numberOnly.equals(numberonly1))
        	    		{
        	    			System.out.println("Selected fare option is same in result & review page");
        	    		}else {
        	    			System.out.println("Selected fare option is not same in result & review page");
        	    		}
//        	    		
     	    		}

//======================================================================================================================      	    		

     	    		Thread.sleep(2000);
     	    		File src5=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
     	    		FileHandler.copy(src5, new File("./Screenshot/Reviewpage.png"));
     	    		WebElement scrollelement3 = driver.findElement(By.xpath("//div[@class='details_box_tittle']"));
     	    		JavascriptExecutor js3= (JavascriptExecutor) driver;
     	    		js3.executeScript("arguments[0].scrollIntoView(true);",scrollelement3);
     	    		Thread.sleep(2000);
     	    		
     	    		
     	    		
 //===================================================================================================================   	         
    	        
    //Checking the partners in the result page and review page is same. stored as List. select a particular partners select button.based on the partner name stored as string.
     	    		List<WebElement> partnerinreview = driver.findElements(By.xpath("//div[@class='details_list_clm_cntr']"));
     	    		List<String> Rpartners = new ArrayList<>();

     	    		int matchIndex = -1; // to store index if partner is found
     	    		for (int j = 0; j < partnerinreview.size(); j++) {
     	    		    WebElement partnerinreview1 = partnerinreview.get(j);
     	    		    String onboardedpartner = partnerinreview1.getText().trim();
     	    		    Rpartners.add(onboardedpartner);
     	    		    System.out.println("Displayed partner in review page: " + onboardedpartner);
     	    		    
     	    		   // Check for match
     	    		    if (onboardedpartner.equalsIgnoreCase(selectpartner)) {
     	    		        matchIndex = j;  // store index of matched partner
     	    		    }
     	    		}
     	    		
     	    		System.out.println("All Available Partners in the review page stored in List = " + Rpartners);

     	    	// Compare full list with result page partners
     	    	if (availablepartners.equals(Rpartners)) {
     	    	    System.out.println("✔ All result page partners are available in review page.");
     	    	} else {
     	    	    System.out.println("⚠ Some result page partners are missing in the review page.");
     	    	}
     	    	
     	    // Now decide which partner to select
     	    	if (matchIndex != -1) {
     	    	    // Found the partner, click its corresponding select button
     	    	    driver.findElement(By.xpath("(//div[@class='details_list_select']//button)[" + (matchIndex + 1) + "]")).click();
     	    	    System.out.println("✔ SELECTED: Clicked select button for partner: " + selectpartner);
     	    	} else {
     	    	    // Partner not found, click first select button
     	    	    if (!partnerinreview.isEmpty()) {
     	    	        driver.findElement(By.xpath("(//div[@class='details_list_select']//button)[1]")).click();
     	    	        System.out.println("❌ Partner '" + selectpartner + "' not found. Clicked select button for the first partner: " + Rpartners.get(0));
     	    	    } else {
     	    	        System.out.println("❌ No partners available on review page to select.");
     	    	    }
     	    	}
    	         }
 //================================================================================================================================================    	    	
	    		
     	    		
    	         Thread.sleep(30000);
    	         File src6=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    	         FileHandler.copy(src6, new File("./Screenshot/Passengerdetailspage.png"));
    	         WebElement partnerlogo=driver.findElement(By.xpath("//div[@class='flight_pax_head_logo']"));
    	         if(partnerlogo.isDisplayed())
    	         {
    	        	 System.out.println("Partner Logo is displayed in Details page");
    	         }
    	         else 
    	         {
    	        	 System.out.println("Partner Logo is not displayed in Details page");
    	         }
    	         driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(60));
    	         driver.findElement(By.xpath("//div[contains(@class,'d-flex')]//h3")).click();//For minimize the review your booking option.
    //Entering traveller details
    //email id , phone code , phone number in passenger details form.
    	         WebElement email=driver.findElement(By.xpath("//input[@name='email0']"));
    	         email.click();
    	         Thread.sleep(1000);
    	         email.sendKeys(EmailID);
    	         Thread.sleep(2000);
    	         
    	         WebElement phcode=driver.findElement(By.xpath("(//div[@class='css-13cymwt-control'])[1]"));
    	         Actions act1=new Actions(driver);
    	         phcode.click();
    	         Thread.sleep(1000);
    	         WebElement phcode1=driver.findElement(By.xpath("//input[@id='react-select-2-input']"));
    	         phcode1.click();
    	         phcode1.sendKeys("+91");
    	         Thread.sleep(2000);
    	         act1.sendKeys(Keys.ENTER);
    	         act1.perform();
    	         Thread.sleep(2000);
    	         
    	         WebElement phnumber=driver.findElement(By.xpath("(//input[@name='mobileNumber0'])"));
    	         phnumber.click();
    	         Thread.sleep(1000);
    	         phnumber.sendKeys(Phonenumber);
    	         Thread.sleep(1000);
    	         
    	         WebElement scrollelement3 = driver.findElement(By.xpath("//div[@class='acc__title']"));
  	    		JavascriptExecutor js3= (JavascriptExecutor) driver;
  	    		js3.executeScript("arguments[0].scrollIntoView(true);",scrollelement3);
  	    		Thread.sleep(1000);
  	    		
  	    		
//==================================================================================================================
  	    		//condition for single adult also the condition for 1 adult,1 child,1 infant
  	    		if (Adultcount == 1 && Childcount == 0 && Infantcount == 0) 
  	    		{
  	    			singleadultpax();
  	    		}
  	    		else if (Adultcount >= 1 || Childcount >= 1 || Infantcount >= 1) 
  	    		{
  	    			multipax();
  	    		}else 
  	    		{
  	    			 System.out.println("Invalid guest count.");
  	    		}
//======================================================================================================================

  	    		//after click the button for visible select Additional services / Seat option.
   	    		WebElement continuebutton=driver.findElement(By.xpath("//div[contains(@class,'fl_review_bkng')]//button"));
   	    		continuebutton.click();
   	    		Thread.sleep(5000);
   		
//----------------------------------------------------------------------------------------------------------------------		
   	    				//For Additional services selection if it was available.
   	    		    		
   	    	// Locator for the Additional Services heading
   	    		By additionalServicesHeading = By.xpath("//div[contains(@class,'paxdetails_box_tittle2')]//h2[contains(text(),'Additional Services')]");

   	    		// Check if heading is available
   	    		List<WebElement> serviceHeader = driver.findElements(additionalServicesHeading);

   	    		if (serviceHeader.isEmpty()) {
   	    		    System.out.println("Additional Services section not available for this search.");
   	    		} else {
   	    		    // Scroll to the heading for visibility
   	    		    WebElement header = serviceHeader.get(0);
   	    		    ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", header);
   	    		    System.out.println("Additional Services section available.");

   	    		    // Get all dropdowns inside Additional Services section
   	    		    List<WebElement> allDropdowns = driver.findElements(By.xpath("//div[@class='pax_additional_content']//select"));

   	    		    if (allDropdowns.isEmpty()) {
   	    		        System.out.println("Additional Services section found, but no services are available.");
   	    		    } else {
   	    		        System.out.println("Found " + allDropdowns.size() + " services under Additional Services.");

   	    		        for (WebElement dropdown : allDropdowns) {
   	    		            try {
   	    		                
   	    		                dropdown.click();
   	    		                Thread.sleep(2000); 

   	    		                Select select = new Select(dropdown);

   	    		                if (select.getOptions().size() > 1) {
   	    		                    select.selectByIndex(1);  // choose second option
   	    		                    System.out.println("Selected: " + select.getFirstSelectedOption().getText());
   	    		                } else {
   	    		                    System.out.println("Dropdown has only default option: " + 
   	    		                                        select.getFirstSelectedOption().getText());
   	    		                }

   	    		            } catch (Exception e) {
   	    		                System.out.println("No additional services are availabe: " + e.getMessage());
   	    		            }
   	    		        }
   	    		    }
   	    		}

   	    		
   	    		
   	    		
   	    		
//--------------------------------------------------------------------------------------------------------------------------------		
   	    		
   	    		
   	    		Thread.sleep(2000);
   	    		//Scroll for select seat area.
   	    		WebElement scrolltoelement2 = driver.findElement(By.xpath("//div[contains(@class,'paxdetails_box_tittle2')]//h2[contains(normalize-space(.), 'Seat Select')]"));
  	    		JavascriptExecutor jr2= (JavascriptExecutor) driver;
  	    		jr2.executeScript("arguments[0].scrollIntoView(true);",scrolltoelement2);
  	    		
 	    		
  //==================================================================================================================
    		
  	    	//for seat selection.
  	    		
  	    		int seatsNeeded = Adultcount + Childcount;
  	    		System.out.println("Total seats to select for segments: " + seatsNeeded);

  	    		// Get all segment tabs (KWI→DXB, DXB→CDG, ...)
  	    		List<WebElement> segments = driver.findElements(By.xpath("//div[@class='flPaxSeatTabs']//ul//li"));
  	    		if(segments.isEmpty()) {
  	    			System.out.println("Seat selection for segments is not available for this booking.");
  	    		}else {

  	    		for (int segIndex = 0; segIndex < segments.size(); segIndex++) {
  	    		    WebElement segmentTab = segments.get(segIndex);

  	    		    // Click on the segment tab
  	    		    segmentTab.click();
  	    		    System.out.println("Switched to Segment: " + (segIndex + 1));

  	    		    // Reset counter for this segment
  	    		    int selectedSeats = 0;

  	    		    // Get all seats inside this segment
  	    		    List<WebElement> allSeats = driver.findElements(By.xpath("//div[contains(@class,'mob_wrap')]//ul//li"));

  	    		    for (WebElement seat : allSeats) {
  	    		        if (selectedSeats >= seatsNeeded) break;

  	    		        String seatid = seat.getAttribute("data-tooltip-id");

  	    		        if (seatid != null && !seatid.trim().isEmpty()) {
  	    		            try {
  	    		                seat.click();
  	    		                selectedSeats++;
  	    		                System.out.println(" Segment " + (segIndex + 1) + " → Seat selected (" + selectedSeats + "/" + seatsNeeded + ")");
  	    		            } catch (Exception e) {
  	    		                System.out.println(" Failed to click seat, skipping...");
  	    		            }
  	    		        }
  	    		    }

  	    		    if (selectedSeats < seatsNeeded) {
  	    		        System.out.println(" Segment " + (segIndex + 1) + ": Not enough seats available.");
  	    		    } else {
  	    		        System.out.println(" Segment " + (segIndex + 1) + ": Successfully selected all required seats.");
  	    		    }
  	    		}
  	    		}
  	    		
   	    		
  	    		
  	    		
  //===================================================================================================================	    		
   	    		
   	    		
   	    		//"continue to payment" button
   	    		WebElement scrolltoelement = driver.findElement(By.xpath("//div[@class='details_box_main']//button"));
  	    		JavascriptExecutor jr= (JavascriptExecutor) driver;
  	    		jr.executeScript("arguments[0].scrollIntoView(true);",scrolltoelement);
   	    		Thread.sleep(2000);
   	    		scrolltoelement.click();//continue to payment button.
   	    		//Thread.sleep(10000);
   	  
   	    		
 //===============================================================================================
   	    		//Payment method selection.
   	    		
   	   WebDriverWait wait3 = new WebDriverWait(driver, Duration.ofSeconds(20));
  		// Wait until payment section is visible
  		wait3.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(@class,'paymentSection')]")));

  	    // Get all payment method list items
  	    List<WebElement> paymentOptions = driver.findElements(By.xpath("//div[contains(@class,'paymentSection')]//ul/li"));
  	    Thread.sleep(3000);
  	  WebElement selectedImage = null;
      String selectedGateway = "";
      
   // First, try to find and click KNET payment method image
      for (WebElement option : paymentOptions) {
          WebElement img = option.findElement(By.xpath(".//label/img"));
          String imgSrc = img.getAttribute("src").toLowerCase();
          if (imgSrc.contains("hpmvae2wbb") || imgSrc.contains("knet")) {
              selectedImage = img;
              selectedGateway = "knet";
              break;
          }
      }

      // If KNET not found, click the first available payment method image
      if (selectedImage == null) {
          for (WebElement option : paymentOptions) {
              WebElement img = option.findElement(By.xpath(".//label/img"));
              String imgSrc = img.getAttribute("src").toLowerCase();
              selectedImage = img;
              if (imgSrc.contains("yiKFVlGS2u")) selectedGateway = "ottu";
              else if (imgSrc.contains("EOLrJXZYJD")) selectedGateway = "myfatoorah";
              //else if (imgSrc.contains("visa") || imgSrc.contains("master")) selectedGateway = "visa_master";
              else if (imgSrc.contains("5Oe6JCZyam")) selectedGateway = "visa_master";
              else selectedGateway = "unknown";
              break;  // break after first available image found
          }
      }

      if (selectedImage != null) {
          // Wait until image is clickable
          wait.until(ExpectedConditions.elementToBeClickable(selectedImage));
          selectedImage.click();
          System.out.println("✅ Selected Payment Gateway: " + selectedGateway);
      } else {
          throw new RuntimeException("❌ No available payment gateway found!");
      }
      
//===================================================================================
      
  		
  		WebElement scrolltoelement1 = driver.findElement(By.xpath("(//div[contains(@class,'fieldWrap')])[1]"));
  		JavascriptExecutor jr1= (JavascriptExecutor) driver;
  		jr1.executeScript("arguments[0].scrollIntoView(true);",scrolltoelement1);
           Thread.sleep(2000);
    	      // Click Pay Now button
    	      WebElement payNowBtn = driver.findElement(By.xpath("//button[contains(text(),'Pay Now')]"));
    	      payNowBtn.click();
    	      System.out.println("🟠 Pay Now button clicked.");
   	   	 	  
   	    		   
   	    	    
   	    	 if (isBookingFailed()) {
   	    	    System.out.println("❌ Booking Failed right after Pay Now");
   	    	}else {
   	    		boolean popupHandled = true;
   	    		while (popupHandled) {
   	    			
   	    			try {
   	    				WebDriverWait wait1 = new WebDriverWait(driver, Duration.ofSeconds(10));
   	   	    	    	wait1.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//div[@id='popup_overlay']")));
   	   	    	    	//Thread.sleep(2000);
   	   	    	    	WebElement okbutton=wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//div[@id='popup_panel']//input)[2]")));
   	   	    	    	okbutton.click();
   	   	    	    	System.out.println("Fare update pop-up clicked");
   	   	    	    	
   	   	    	  if (isBookingFailed()) {
   	                System.out.println("❌ Booking Failed after fare change popup");
   	                break; // stop checking further popups, continue with next iteration of data
   	            }
   	    			}
   	    			
   	    			catch (TimeoutException e) {
   	    	            popupHandled = false; // no more popups
   	    	            System.out.println("No more fare change popups");
   	    	         System.out.println(" Redirected to Payment Gateway page");
   	    	         Thread.sleep(2000);
   	    	         if(selectedGateway.equals("knet")) {
   	    	        	 System.out.println("Knet Payment GateWay");
   	    	        	 knettestcard();   	        	 
   	    	         }else if (selectedGateway.equals("ottu")) {
						System.out.println("Ottu Payment Gateway");
						ottuknet();
					}else if (selectedGateway.equals("myfatoorah")) {
						System.out.println("MyFatoorah Payment Gateway");
						myfatoorahknet();
					}else if (selectedGateway.equals("visa_master")) {
						System.out.println("VisaMaster Payment Gateway");
						visamaster();
					}else {
						System.out.println("No such payment gateway found");
					}
   	    	         try {
//checking for the ticket status [ticket success or ticket failed]
   	    	      WebDriverWait wait4 = new WebDriverWait(driver, Duration.ofSeconds(120));
   	     		// Wait until ticket details to visible
   	     		wait4.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='tkt_btns']")));
   	    	         
   	     		WebElement successmsg=driver.findElement(By.xpath("//div[@class='inner_sub_text']//h2"));
   	     		File src3=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
   	     		FileHandler.copy(src3, new File("./Screenshot/Ticketsuccesspage.png"));
   	     		if(successmsg.isDisplayed() && successmsg.getText().contains("Congratulations")) {
   	     			System.out.println("Ticket Booked Successfully!");
   	     			WebElement refnumber=driver.findElement(By.xpath("(//td[contains(text(),'Ref. Number')]/ancestor::tr/following-sibling::tr[1]/td)[1]"));
   	     			String refnumberelement= refnumber.getText();
   	     			System.out.println("Reference number =" +refnumberelement);
   	     		}    		
   	    	        }
   	    	         catch (Exception e1) {
   	    	        	 
   	       	     		 WebDriverWait wait5 = new WebDriverWait(driver, Duration.ofSeconds(120));    	     		
   	        	         wait5.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='booking_fail_icon']//img")));
   	       	     			WebElement failedmsg=driver.findElement(By.xpath("//div[contains(@class,'col-lg-9')]//h2"));
   	       	     		    File src4=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
   	    	     			FileHandler.copy(src4, new File("./Screenshot/FailedConditionpage.png"));
   	    	     			if(failedmsg.isDisplayed() && failedmsg.getText().contains("Ticketing Failed")) {
   	    	     				String failedtype=failedmsg.getText().trim();
   	    	     				System.out.println("Not Ticketed :- Condition----" +failedtype);
   	    	     			}
	 	 
					}
   	    			 	    	
   	    		}

   	    	
   	    	}
   	    		}
   	    	 

	    		
	    	
    		
   	    	 
    		
   	    	    
   	    	    
   	    	    
   
    	         
//    	         else 
//    	         {
//    	             System.out.println("Result panel present but not visible.");
//    	         }
    	     } else {
    	         System.out.println("NO result found for particular search scenario.");
    	         File src1= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
 	             FileHandler.copy(src1, new File("./Screenshot/Noresultfound.png"));
    	     }
    	    
    	     
    	    
    	    Thread.sleep(20000); // Wait for 20 seconds

           // driver.quit(); // Close the browser
        }
        
    }
 //Method for onward calendar  
    public void selectonwardDate(String monthYear, String day) throws InterruptedException{
   	 while (true) {
   		 //left calendar heading
   	        WebElement leftMonthEl = wait.until(ExpectedConditions.visibilityOfElementLocated(
   	                By.xpath("(//div[@class='react-datepicker__header ']//h2)[1]")));
   	        String left = leftMonthEl.getText();
         //right calendar heading
   	        WebElement rightMonthEl = wait.until(ExpectedConditions.visibilityOfElementLocated(
   	                By.xpath("(//div[@class='react-datepicker__header ']//h2)[2]")));
   	        String right = rightMonthEl.getText();

   	        System.out.println("Left: " + left + " | Right: " + right);
   	        // Stop only when the target month is on the LEFT calendar
   	        if (left.equals(monthYear)) {
   	            break;
   	        }else {

   	        // If the target is in right, we still need to click next to bring it to left
   	        WebElement nextButton = wait.until(ExpectedConditions.elementToBeClickable(
   	                By.xpath("//button[contains(@class,'react-datepicker__navigation--next')]")));
   	        nextButton.click();

   	        // Wait for calendar update
   	        wait.until(ExpectedConditions.not(ExpectedConditions.or(
   	                ExpectedConditions.textToBePresentInElement(leftMonthEl, left),
   	                ExpectedConditions.textToBePresentInElement(rightMonthEl, right)
   	        )));
   	        Thread.sleep(500);
   	        }
   	    }
   	 // Now target month is on the left side → calendarIndex = 1
   	    String calendar1Index = "1";
     //select day
   	    List<WebElement> days = driver.findElements(By.xpath(
   	            "(//div[contains(@class,'react-datepicker__month')])[" + calendar1Index + "]" +
   	            "//div[contains(@class,'react-datepicker__day') and not(contains(@class,'--outside-month')) and not(contains(@class,'--disabled'))]"
   	    ));

   	    boolean dateFound = false;
   	    for (WebElement d : days) {
   	        if (d.getText().equals(day)) {
   	            d.click();
   	            dateFound = true;
   	            System.out.println("Selected date: " + day);
   	            break;
   	        }
   	    }
   	    if (!dateFound) {
   	        System.out.println("Date " + day + " not found in calendar " + monthYear);
   	    }
   	}
 ////Method for Return calendar     
   public void selectreturnDate(String Rmonthyear, String Rdate) throws InterruptedException {
	   while (true) {
		   WebElement leftMonthheading = wait.until(ExpectedConditions.visibilityOfElementLocated(
  	                By.xpath("(//div[@class='react-datepicker__header ']//h2)[1]")));
  	        String leftside = leftMonthheading.getText();
  	        
  	      WebElement rightMonthheading = wait.until(ExpectedConditions.visibilityOfElementLocated(
 	                By.xpath("(//div[@class='react-datepicker__header ']//h2)[2]")));
 	        String rightside = rightMonthheading.getText();
 	       System.out.println("Left: " + leftside + " | Right: " + rightside);
 	       
 	      if (leftside.equals(Rmonthyear)) {
 	            break;
 	        }else {
 	      
 	     WebElement nextButton = wait.until(ExpectedConditions.elementToBeClickable(
	                By.xpath("//button[contains(@class,'react-datepicker__navigation--next')]")));
	        nextButton.click();
	        
	        // Wait for calendar update
   	        wait.until(ExpectedConditions.not(ExpectedConditions.or(
   	                ExpectedConditions.textToBePresentInElement(leftMonthheading, leftside),
   	                ExpectedConditions.textToBePresentInElement(rightMonthheading, rightside)
   	        )));
   	        Thread.sleep(500);
		   
		   }
	   }
	// Now target month is on the left side → calendarIndex = 1
  	    String calendar2Index = "1";

  	    List<WebElement> days = driver.findElements(By.xpath(
  	            "(//div[contains(@class,'react-datepicker__month')])[" + calendar2Index + "]" +
  	            "//div[contains(@class,'react-datepicker__day') and not(contains(@class,'--outside-month')) and not(contains(@class,'--disabled'))]"
  	    ));
	   
  	  boolean dateFound = false;
 	    for (WebElement d : days) {
 	        if (d.getText().equals(Rdate)) {
 	            d.click();
 	            dateFound = true;
 	            System.out.println("Selected date: " + Rdate);
 	            break;
 	        }
 	    }
 	   if (!dateFound) {
  	        System.out.println("Date " + Rdate + " not found in calendar " + Rmonthyear);
  	    }
  	}

   
   
   
   
 //=======================================  
   //passenger selection
   public void setPassengers(String adults, String children, String infants) {
	   
	   setPassengerCount("Adults", Integer.parseInt(adults));        //converting string to integer
	    setPassengerCount("children", Integer.parseInt(children));  // case-sensitive based on your HTML
	    setPassengerCount("Infants", Integer.parseInt(infants));
   }
   public void setPassengerCount(String passengerType, int desiredCount) {
	   try {
		   
		   // XPath to current count based on passengerType
	        String countXPath = "//p[contains(text(),'" + passengerType + "')]/following::div[contains(@class,'psnrs_travel')][1]";
	        WebElement countElement = driver.findElement(By.xpath(countXPath));
	        int currentCount = Integer.parseInt(countElement.getText().trim());

	        // XPath to + and - buttons for the passengerType
	        String plusXPath = "//p[contains(text(),'" + passengerType + "')]/following::button[contains(@class,'plus-plus-button')][1]";
	        String minusXPath = "//p[contains(text(),'" + passengerType + "')]/following::button[contains(@class,'plus-minus-button')][1]";
	        

	        while (currentCount < desiredCount) {
	            driver.findElement(By.xpath(plusXPath)).click();
	            currentCount++;
	            Thread.sleep(300);
	        }
	        while (currentCount > desiredCount) {
	            driver.findElement(By.xpath(minusXPath)).click();
	            currentCount--;
	            Thread.sleep(300);
	   }
	        System.out.println("Passenger type " + passengerType + " set to " + desiredCount);
	   
   }catch (Exception e) {

	   System.out.println("Error setting " + passengerType + " count");
       e.printStackTrace();
   }
}
   
   
   //method for single adult condition.
   public void singleadultpax() throws InterruptedException {
	   
	 //Adult passenger details
 		WebElement adulttitle= driver.findElement(By.xpath("(//select[@id='exampleFormControlSelect1'])[1]"));
 		adulttitle.click();
 		Thread.sleep(1000);
 		Select sc1=new Select(adulttitle);
 		sc1.selectByVisibleText("Mr");
 		Thread.sleep(1000);
 		WebElement adultfname=driver.findElement(By.xpath("//input[@name='firstName0']"));
 		adultfname.click();
 		Thread.sleep(1000);
 		adultfname.sendKeys(AdultFname);
 		Thread.sleep(1000);
 		WebElement adultlname=driver.findElement(By.xpath("//input[@name='lastName0']"));
 		adultlname.click();
 		Thread.sleep(1000);
 		adultlname.sendKeys(AdultLname);
 		Thread.sleep(1000);
//Adult Date of Birth
 		WebElement Aday=driver.findElement(By.xpath("(//select[@id='rsd__select-day'])[1]"));
 		Aday.click();
 		Thread.sleep(1000);
 		Select sc2=new Select(Aday);
 		sc2.selectByVisibleText("20");
 		Thread.sleep(1000);
 		
 		WebElement Amonth=driver.findElement(By.xpath("(//select[@id='rsd__select-month'])[1]"));
 		Amonth.click();
 		Thread.sleep(1000);
 		Select sc3=new Select(Amonth);
 		sc3.selectByVisibleText("08");
 		Thread.sleep(1000);
 		
 		WebElement Ayear=driver.findElement(By.xpath("(//select[@id='rsd__select-year'])[1]"));
 		Ayear.click();
 		Thread.sleep(1000);
 		Select sc4=new Select(Ayear);
 		sc4.selectByVisibleText("2002");
 		Thread.sleep(1000);
 		
 		WebElement adultnationality=driver.findElement(By.xpath("(//div[@class='css-13cymwt-control'])[2]"));
 		Actions act=new Actions(driver);
 		adultnationality.click();
 		Thread.sleep(2000);
 		WebElement adultnationality1=driver.findElement(By.xpath("//input[@id='react-select-3-input']"));
 		adultnationality1.click();
 		Thread.sleep(1000);
 		adultnationality1.sendKeys("india");
 		Thread.sleep(2000);
 		act.sendKeys(Keys.ARROW_DOWN);
 		act.sendKeys(Keys.ENTER);
 		act.perform();
 		Thread.sleep(2000);
 		
 		WebElement adultpassportno=driver.findElement(By.xpath("//input[@name='passportNumber0']"));
 		adultpassportno.click();
 		Thread.sleep(1000);
 		adultpassportno.sendKeys(Adultpassnumber);
 		Thread.sleep(1000);
//adult passport expiry date
 		WebElement adultpassdate=driver.findElement(By.xpath("(//select[@id='rsd__select-day'])[2]"));
 		adultpassdate.click();
 		Thread.sleep(1000);
 		Select sc5=new Select(adultpassdate);
 		sc5.selectByVisibleText("15");
 		Thread.sleep(1000);
 		
 		WebElement adultpassmonth=driver.findElement(By.xpath("(//select[@id='rsd__select-month'])[2]"));
 		adultpassmonth.click();
 		Thread.sleep(1000);
 		Select sc6=new Select(adultpassmonth);
 		sc6.selectByVisibleText("05");
 		Thread.sleep(1000);
 		
 		WebElement adultpassyear=driver.findElement(By.xpath("(//select[@id='rsd__select-year'])[2]"));
 		adultpassyear.click();
 		Thread.sleep(1000);
 		Select sc7=new Select(adultpassyear);
 		sc7.selectByVisibleText("2038");
 		Thread.sleep(1000);
 		
 		WebElement adultpassissuecntry=driver.findElement(By.xpath("(//div[@class='css-13cymwt-control'])[3]"));
 		Actions act2=new Actions(driver);
 		adultpassissuecntry.click();
 		Thread.sleep(1000);
 		WebElement adultpassissuecntry1=driver.findElement(By.xpath("//input[@id='react-select-4-input']"));
 		adultpassissuecntry1.click();
 		Thread.sleep(1000);
 		adultpassissuecntry1.sendKeys("india");
 		Thread.sleep(1000);
 		act2.sendKeys(Keys.ARROW_DOWN);
 		act2.sendKeys(Keys.ENTER);
 		act2.perform();
 		System.out.println("Passenger details are entered");
 		Thread.sleep(2000);
// 		 WebElement scrollelement4 = driver.findElement(By.xpath("//input[@name='passportNumber0']"));
//  		JavascriptExecutor js4= (JavascriptExecutor) driver;
//  		js4.executeScript("arguments[0].scrollIntoView(true);",scrollelement4);
//  		Thread.sleep(1000);
	   
   }
   
   //method for the 1 adult, 1 child, 1 infant condition.
   public void multipax() throws InterruptedException {
	   
	   
	 //Adult passenger details
 		WebElement adulttitle= driver.findElement(By.xpath("(//select[@id='exampleFormControlSelect1'])[1]"));
 		adulttitle.click();
 		Thread.sleep(1000);
 		Select sc1=new Select(adulttitle);
 		sc1.selectByVisibleText("Mr");
 		Thread.sleep(1000);
 		WebElement adultfname=driver.findElement(By.xpath("//input[@name='firstName0']"));
 		adultfname.click();
 		Thread.sleep(1000);
 		adultfname.sendKeys(AdultFname);
 		Thread.sleep(1000);
 		WebElement adultlname=driver.findElement(By.xpath("//input[@name='lastName0']"));
 		adultlname.click();
 		Thread.sleep(1000);
 		adultlname.sendKeys(AdultLname);
 		Thread.sleep(1000);
//Adult Date of Birth
 		WebElement Aday=driver.findElement(By.xpath("(//select[@id='rsd__select-day'])[1]"));
 		Aday.click();
 		Thread.sleep(1000);
 		Select sc2=new Select(Aday);
 		sc2.selectByVisibleText("20");
 		Thread.sleep(1000);
 		
 		WebElement Amonth=driver.findElement(By.xpath("(//select[@id='rsd__select-month'])[1]"));
 		Amonth.click();
 		Thread.sleep(1000);
 		Select sc3=new Select(Amonth);
 		sc3.selectByVisibleText("08");
 		Thread.sleep(1000);
 		
 		WebElement Ayear=driver.findElement(By.xpath("(//select[@id='rsd__select-year'])[1]"));
 		Ayear.click();
 		Thread.sleep(1000);
 		Select sc4=new Select(Ayear);
 		sc4.selectByVisibleText("2002");
 		Thread.sleep(1000);
 		
 		WebElement adultnationality=driver.findElement(By.xpath("(//div[@class='css-13cymwt-control'])[2]"));
 		Actions act=new Actions(driver);
 		adultnationality.click();
 		Thread.sleep(2000);
 		WebElement adultnationality1=driver.findElement(By.xpath("//input[@id='react-select-3-input']"));
 		adultnationality1.click();
 		Thread.sleep(1000);
 		adultnationality1.sendKeys("india");
 		Thread.sleep(2000);
 		act.sendKeys(Keys.ARROW_DOWN);
 		act.sendKeys(Keys.ENTER);
 		act.perform();
 		Thread.sleep(2000);
 		
 		WebElement adultpassportno=driver.findElement(By.xpath("//input[@name='passportNumber0']"));
 		adultpassportno.click();
 		Thread.sleep(1000);
 		adultpassportno.sendKeys(Adultpassnumber);
 		Thread.sleep(1000);
//adult passport expiry date
 		WebElement adultpassdate=driver.findElement(By.xpath("(//select[@id='rsd__select-day'])[2]"));
 		adultpassdate.click();
 		Thread.sleep(1000);
 		Select sc5=new Select(adultpassdate);
 		sc5.selectByVisibleText("15");
 		Thread.sleep(1000);
 		
 		WebElement adultpassmonth=driver.findElement(By.xpath("(//select[@id='rsd__select-month'])[2]"));
 		adultpassmonth.click();
 		Thread.sleep(1000);
 		Select sc6=new Select(adultpassmonth);
 		sc6.selectByVisibleText("05");
 		Thread.sleep(1000);
 		
 		WebElement adultpassyear=driver.findElement(By.xpath("(//select[@id='rsd__select-year'])[2]"));
 		adultpassyear.click();
 		Thread.sleep(1000);
 		Select sc7=new Select(adultpassyear);
 		sc7.selectByVisibleText("2038");
 		Thread.sleep(1000);
 		
 		WebElement adultpassissuecntry=driver.findElement(By.xpath("(//div[@class='css-13cymwt-control'])[3]"));
 		Actions act2=new Actions(driver);
 		adultpassissuecntry.click();
 		Thread.sleep(1000);
 		WebElement adultpassissuecntry1=driver.findElement(By.xpath("//input[@id='react-select-4-input']"));
 		adultpassissuecntry1.click();
 		Thread.sleep(1000);
 		adultpassissuecntry1.sendKeys("india");
 		Thread.sleep(1000);
 		act2.sendKeys(Keys.ARROW_DOWN);
 		act2.sendKeys(Keys.ENTER);
 		act2.perform();
 		Thread.sleep(2000);
 		 WebElement scrollelement4 = driver.findElement(By.xpath("//input[@name='passportNumber0']"));
  		JavascriptExecutor js4= (JavascriptExecutor) driver;
  		js4.executeScript("arguments[0].scrollIntoView(true);",scrollelement4);
  		Thread.sleep(1000);
  		
  		
  		
  	//Child passenger details
   		WebElement childtitle=driver.findElement(By.xpath("(//select[@id='exampleFormControlSelect1'])[2]"));
   		childtitle.click();
   		Thread.sleep(1000);
   		Select sc8=new Select(childtitle);
   		sc8.selectByVisibleText("Mstr");
   		Thread.sleep(1000);
   		WebElement childfname=driver.findElement(By.xpath("//input[@name='firstName1']"));
   		childfname.click();
   		Thread.sleep(1000);
   		childfname.sendKeys(ChildFname);
   		Thread.sleep(1000);
   		WebElement childlname=driver.findElement(By.xpath("//input[@name='lastName1']"));
   		childlname.click();
   		Thread.sleep(1000);
   		childlname.sendKeys(ChildLname);
   		Thread.sleep(1000);
   		
 //Child passenger date of birth
   		WebElement childdate=driver.findElement(By.xpath("(//select[@id='rsd__select-day'])[3]"));
   		childdate.click();
   		Thread.sleep(1000);
   		Select sc9=new Select(childdate);
   		sc9.selectByVisibleText("25");
   		Thread.sleep(1000);
   		
   		WebElement childmonth=driver.findElement(By.xpath("(//select[@id='rsd__select-month'])[3]"));
   		childmonth.click();
   		Thread.sleep(1000);
   		Select sc10=new Select(childmonth);
   		sc10.selectByVisibleText("10");
   		Thread.sleep(1000);
   		
   		WebElement childyear=driver.findElement(By.xpath("(//select[@id='rsd__select-year'])[3]"));
   		childyear.click();
   		Thread.sleep(1000);
   		Select sc11=new Select(childyear);
   		sc11.selectByVisibleText("2014");
   		Thread.sleep(1000);
   		
   		WebElement childnationality=driver.findElement(By.xpath("(//div[@class='css-13cymwt-control'])[4]"));
   		Actions act3=new Actions(driver);
   		childnationality.click();
   		Thread.sleep(1000);
   		WebElement childnationality1=driver.findElement(By.xpath("//input[@id='react-select-5-input']"));
   		childnationality1.click();
   		Thread.sleep(1000);
   		childnationality1.sendKeys("india");
   		Thread.sleep(1000);
   		act3.sendKeys(Keys.ARROW_DOWN);
   		act3.sendKeys(Keys.ENTER);
   		act3.perform();
   		Thread.sleep(2000);
   		WebElement childpassno=driver.findElement(By.xpath("//input[@name='passportNumber1']"));
   		childpassno.click();
   		Thread.sleep(1000);
   		childpassno.sendKeys(Childpassnumber);
   		Thread.sleep(1000);
//Child passport expiry date
   		WebElement childpassdate=driver.findElement(By.xpath("(//select[@id='rsd__select-day'])[4]"));
   		childpassdate.click();
   		Thread.sleep(1000);
   		Select sc12=new Select(childpassdate);
   		sc12.selectByVisibleText("18");
   		Thread.sleep(1000);
   		
   		WebElement childpassmonth=driver.findElement(By.xpath("(//select[@id='rsd__select-month'])[4]"));
   		childpassmonth.click();
   		Thread.sleep(1000);
   		Select sc13=new Select(childpassmonth);
   		sc13.selectByVisibleText("11");
   		Thread.sleep(1000);
   		
   		WebElement childpassyear=driver.findElement(By.xpath("(//select[@id='rsd__select-year'])[4]"));
   		childpassyear.click();
   		Thread.sleep(1000);
   		Select sc14=new Select(childpassyear);
   		sc14.selectByVisibleText("2036");
   		Thread.sleep(1000);
   		
   		WebElement childpassissuecntry=driver.findElement(By.xpath("(//div[@class='css-13cymwt-control'])[5]"));
   		Actions act4=new Actions(driver);
   		childpassissuecntry.click();
   		Thread.sleep(1000);
   		WebElement childpassissuecntry1=driver.findElement(By.xpath("//input[@id='react-select-6-input']"));
   		childpassissuecntry1.click();
   		Thread.sleep(1000);
   		childpassissuecntry1.sendKeys("india");
   		Thread.sleep(1000);
   		act4.sendKeys(Keys.ARROW_DOWN);
   		act4.sendKeys(Keys.ENTER);
   		act4.perform();
   		Thread.sleep(2000);
   		WebElement scrollelement5 = driver.findElement(By.xpath("//input[@name='passportNumber1']"));
   		JavascriptExecutor js5= (JavascriptExecutor) driver;
   		js5.executeScript("arguments[0].scrollIntoView(true);",scrollelement5);
   		Thread.sleep(1000);
   		
   
   		
   		
   		
   		
//infant passenger details
   		WebElement infanttitle=driver.findElement(By.xpath("(//select[@id='exampleFormControlSelect1'])[3]"));
   		infanttitle.click();
   		Thread.sleep(1000);
   		Select sc15=new Select(infanttitle);
   		sc15.selectByVisibleText("Mstr");
   		Thread.sleep(1000);
   		WebElement infantfname=driver.findElement(By.xpath("//input[@name='firstName2']"));
   		infantfname.click();
   		Thread.sleep(1000);
   		infantfname.sendKeys(InfantFname);
   		Thread.sleep(1000);
   		WebElement infantlname=driver.findElement(By.xpath("//input[@name='lastName2']"));
   		infantlname.click();
   		Thread.sleep(1000);
   		infantlname.sendKeys(InfantLname);
   		Thread.sleep(1000);
//infant passenger date of birth
   		
   		WebElement infantdate=driver.findElement(By.xpath("(//select[@id='rsd__select-day'])[5]"));
   		infantdate.click();
   		Thread.sleep(1000);
   		Select sc16=new Select(infantdate);
   		sc16.selectByVisibleText("13");
   		Thread.sleep(1000);
   		
   		WebElement infantmonth=driver.findElement(By.xpath("(//select[@id='rsd__select-month'])[5]"));
   		infantmonth.click();
   		Thread.sleep(1000);
   		Select sc17=new Select(infantmonth);
   		sc17.selectByVisibleText("09");
   		Thread.sleep(1000);
   		
   		WebElement infantyear=driver.findElement(By.xpath("(//select[@id='rsd__select-year'])[5]"));
   		infantyear.click();
   		Thread.sleep(1000);
   		Select sc18=new Select(infantyear);
   		sc18.selectByVisibleText("2024");
   		Thread.sleep(1000);
   		
   		WebElement infantnationality=driver.findElement(By.xpath("(//div[@class='css-13cymwt-control'])[6]"));
   		Actions act5=new Actions(driver);
   		infantnationality.click();
   		Thread.sleep(1000);
   		WebElement infantnationality1=driver.findElement(By.xpath("//input[@id='react-select-7-input']"));
   		infantnationality1.click();
   		Thread.sleep(1000);
   		infantnationality1.sendKeys("india");
   		Thread.sleep(1000);
   		act5.sendKeys(Keys.ARROW_DOWN);
   		act5.sendKeys(Keys.ENTER);
   		act5.perform();
   		Thread.sleep(2000);
   		WebElement infantpassno=driver.findElement(By.xpath("//input[@name='passportNumber2']"));
   		infantpassno.click();
   		Thread.sleep(1000);
   		infantpassno.sendKeys(Infantpassnumber);
   		Thread.sleep(1000);
   		
   	//Infant passport expiry date
   		WebElement infantpassdate=driver.findElement(By.xpath("(//select[@id='rsd__select-day'])[6]"));
   		infantpassdate.click();
   		Thread.sleep(1000);
   		Select sc19=new Select(infantpassdate);
   		sc19.selectByVisibleText("11");
   		Thread.sleep(1000);
   		
   		WebElement infantpassmonth=driver.findElement(By.xpath("(//select[@id='rsd__select-month'])[6]"));
   		infantpassmonth.click();
   		Thread.sleep(1000);
   		Select sc20=new Select(infantpassmonth);
   		sc20.selectByVisibleText("07");
   		Thread.sleep(1000);
   		
   		WebElement infantpassyear=driver.findElement(By.xpath("(//select[@id='rsd__select-year'])[6]"));
   		infantpassyear.click();
   		Thread.sleep(1000);
   		Select sc21=new Select(infantpassyear);
   		sc21.selectByVisibleText("2037");
   		Thread.sleep(1000);
   		
   		WebElement infantpassissuecntry=driver.findElement(By.xpath("(//div[@class='css-13cymwt-control'])[7]"));
   		Actions act6=new Actions(driver);
   		infantpassissuecntry.click();
   		Thread.sleep(1000);
   		WebElement infantpassissuecntry1=driver.findElement(By.xpath("//input[@id='react-select-8-input']"));
   		infantpassissuecntry1.click();
   		Thread.sleep(1000);
   		infantpassissuecntry1.sendKeys("india");
   		Thread.sleep(1000);
   		act6.sendKeys(Keys.ARROW_DOWN);
   		act6.sendKeys(Keys.ENTER);
   		act6.perform();
   		System.out.println("Passenger details are entered");
   		Thread.sleep(2000);
	   
	   
   }
   
   //booking failed method
//   public void bookingfailed() {
//	   
//	   WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(120));
//	   wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//img[@src='https://uat.farekey.com/images/booking_failed.png']")));
//	   WebElement bookingfailedheading=driver.findElement(By.xpath("//div[@class='inner_sub_text']//h2"));
//	   String  bookingfailedheading1=bookingfailedheading.getText();
//   }
   public boolean isBookingFailed() throws IOException {
	   try {
		   WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
	        wait.until(ExpectedConditions.or(
	            ExpectedConditions.urlContains("BookingFailed"),
	            ExpectedConditions.visibilityOfElementLocated(By.xpath("//img[@src='https://uat.farekey.com/images/booking_failed.png']"))
	        ));
	     
	        WebElement heading = driver.findElement(By.xpath("//div[@class='inner_sub_text']//h2"));
	        System.out.println("❌ Booking Failed page detected: " + heading.getText());
	        File src=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
	        FileHandler.copy(src, new File("./Screenshot/Bookingfailed.png"));
	        return true;  
	    } catch (TimeoutException e) {
	        return false; // No booking failed page
	    }
	}
   
   public void knettestcard() throws InterruptedException, IOException {
	   
	   WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(120));
	   wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("(//div[@class='contentBox']//img[@class='logoHead'])[1]")));
	   File src=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
	   FileHandler.copy(src, new File("./Screenshot/Paymentgatewaypage.png"));
	   WebElement selectbank=driver.findElement(By.xpath("(//select[contains(@class,'paymentselect')])[1]"));
	   selectbank.click();
	   Thread.sleep(1000);
	   Select sc=new Select(selectbank);
	   sc.selectByIndex(12);
	   Thread.sleep(8000);
	   WebElement cardnumber=driver.findElement(By.xpath("//input[@id='debitNumber']"));
	   cardnumber.click();
	   Thread.sleep(1000);
	   cardnumber.sendKeys("0000000001");
	   Thread.sleep(1000);
	   WebElement cardexpiryday=driver.findElement(By.xpath("(//select[contains(@class,'paymentselect')])[3]"));
	   cardexpiryday.click();
	   Thread.sleep(1000);
	   Select sc1=new Select(cardexpiryday);
	   sc1.selectByVisibleText("09");
	   Thread.sleep(1000);
	   WebElement cardexpiryyear=driver.findElement(By.xpath("(//select[contains(@class,'paymentselect')])[4]"));
	   cardexpiryyear.click();
	   Thread.sleep(1000);
	   Select sc2=new Select(cardexpiryyear);
	   sc2.selectByVisibleText("2030");
	   Thread.sleep(1000);
	   WebElement pin=driver.findElement(By.xpath("//input[@id='cardPin']"));
	   pin.click();
	   Thread.sleep(1000);
	   pin.sendKeys("1234");
	   Thread.sleep(1000);
	   WebElement submitbutton=driver.findElement(By.xpath("//input[@id='proceed']"));
	   submitbutton.click();
	   Thread.sleep(3000);
	   WebElement confirm=driver.findElement(By.xpath("//input[@id='proceedConfirm']"));
	   confirm.click();
	   System.out.println("Knet Payment gate way confirm button clicked");
	   
   }
   
   public void myfatoorahknet() throws InterruptedException{
	   WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(120));
	   wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("(//div[@class='contentBox']//img[@class='logoHead'])[1]")));
	   WebElement selectbank=driver.findElement(By.xpath("(//select[contains(@class,'paymentselect')])[1]"));
	   selectbank.click();
	   Thread.sleep(1000);
	   Select sc=new Select(selectbank);
	   sc.selectByIndex(12);
	   Thread.sleep(8000);
	   WebElement cardnumber=driver.findElement(By.xpath("//input[@id='debitNumber']"));
	   cardnumber.click();
	   Thread.sleep(1000);
	   cardnumber.sendKeys("0000000001");
	   Thread.sleep(1000);
	   WebElement cardexpiryday=driver.findElement(By.xpath("(//select[contains(@class,'paymentselect')])[3]"));
	   cardexpiryday.click();
	   Thread.sleep(1000);
	   Select sc1=new Select(cardexpiryday);
	   sc1.selectByVisibleText("09");
	   Thread.sleep(1000);
	   WebElement cardexpiryyear=driver.findElement(By.xpath("(//select[contains(@class,'paymentselect')])[4]"));
	   cardexpiryyear.click();
	   Thread.sleep(1000);
	   Select sc2=new Select(cardexpiryyear);
	   sc2.selectByVisibleText("2030");
	   Thread.sleep(1000);
	   WebElement pin=driver.findElement(By.xpath("//input[@id='cardPin']"));
	   pin.click();
	   Thread.sleep(1000);
	   pin.sendKeys("1234");
	   Thread.sleep(1000);
	   WebElement submitbutton=driver.findElement(By.xpath("//input[@id='proceed']"));
	   submitbutton.click();
	   Thread.sleep(3000);
	   WebElement confirm=driver.findElement(By.xpath("//input[@id='proceedConfirm']"));
	   confirm.click();
	   System.out.println("MyFatoorah payment gateway confirm button clicked.");
	   
   }
   
   public void visamaster() throws InterruptedException {
	   WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(120));
	   wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//img[@src='https://mfstoragemedia.blob.core.windows.net/mfdmfiles/Files/Vendors//2_Logo_59358cda-0d7e-4769-a974-ac6419709c83.jpg']")));
	   WebElement cardholdername=driver.findElement(By.xpath("//input[@id='cardholdername']"));
	   cardholdername.click();
	   Thread.sleep(1000);
	   cardholdername.sendKeys(AdultFname);
	   Thread.sleep(1000);
	   WebElement cardnumber=driver.findElement(By.xpath("//input[@id='cardnumber']"));
	   cardnumber.click();
	   Thread.sleep(1000);
	   cardnumber.sendKeys("5453010000095539");
	   Thread.sleep(1000);
	   WebElement cardexpiry=driver.findElement(By.xpath("//input[@id='expirationdate']"));
	   cardexpiry.click();
	   Thread.sleep(1000);
	   cardexpiry.sendKeys("1225");
	   Thread.sleep(1000);
	   WebElement cvv=driver.findElement(By.xpath("//input[@id='securitycode']"));
	   cvv.click();
	   Thread.sleep(1000);
	   cvv.sendKeys("300");
	   Thread.sleep(1000);
	   //paynow button click
	   driver.findElement(By.xpath("//button[@onClick='cardViewPay()']")).click();
	   System.out.println("VisaMaster payment gateway paynow button clicked");
	   
   }
   public void ottuknet() throws InterruptedException {
//	   driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
//	   WebElement pay1button=driver.findElement(By.xpath("//div[@id='ottu__sdk-block-buttons']//button"));
//	   pay1button.click();
	   Thread.sleep(5);
	   WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(120));
	   wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("(//div[@class='contentBox']//img[@class='logoHead'])[1]")));
	   WebElement selectbank=driver.findElement(By.xpath("(//select[contains(@class,'paymentselect')])[1]"));
	   selectbank.click();
	   Thread.sleep(1000);
	   Select sc=new Select(selectbank);
	   sc.selectByIndex(12);
	   Thread.sleep(8000);
	   WebElement cardnumber=driver.findElement(By.xpath("//input[@id='debitNumber']"));
	   cardnumber.click();
	   Thread.sleep(1000);
	   cardnumber.sendKeys("0000000001");
	   Thread.sleep(1000);
	   WebElement cardexpiryday=driver.findElement(By.xpath("(//select[contains(@class,'paymentselect')])[3]"));
	   cardexpiryday.click();
	   Thread.sleep(1000);
	   Select sc1=new Select(cardexpiryday);
	   sc1.selectByVisibleText("09");
	   Thread.sleep(1000);
	   WebElement cardexpiryyear=driver.findElement(By.xpath("(//select[contains(@class,'paymentselect')])[4]"));
	   cardexpiryyear.click();
	   Thread.sleep(1000);
	   Select sc2=new Select(cardexpiryyear);
	   sc2.selectByVisibleText("2030");
	   Thread.sleep(1000);
	   WebElement pin=driver.findElement(By.xpath("//input[@id='cardPin']"));
	   pin.click();
	   Thread.sleep(1000);
	   pin.sendKeys("1234");
	   Thread.sleep(1000);
	   WebElement submitbutton=driver.findElement(By.xpath("//input[@id='proceed']"));
	   submitbutton.click();
	   Thread.sleep(3000);
	   WebElement confirm=driver.findElement(By.xpath("//input[@id='proceedConfirm']"));
	   confirm.click();
	   System.out.println("Ottu payment gateway confirm button clicked.");
	   
   }

   
   
   

//============================
   
   @AfterTest
   public void closeWorkbook() throws IOException {
       wb.close();
       
   }
   	
   	
   }