package farekeypakg;

import java.io.File;
import java.io.IOException;
import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.io.FileHandler;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Mybooking {

	WebDriver driver;
	WebDriverWait wait;
	String LoginEmail = "amal.j@caxita.in";
	String LoginPassword = "Amal123!";
	String SearchReference = "TRP17853";
	String SearchEmail = "amal.j@caxita.in";
	String SearchPhoneNO = "98956465114";
	
	@BeforeTest
	public void chromeload() {
		driver=new ChromeDriver();
		wait=new WebDriverWait(driver, Duration.ofSeconds(5));
		driver.get("https://uat.farekey.com/");
		driver.manage().window().maximize();		
	}
	@Test
	public void mybookingpanel() throws InterruptedException, IOException {
		
		WebElement mybookingtab=driver.findElement(By.xpath("(//div[@class='menu_wrp']//li)[1]"));
		mybookingtab.click();
		System.out.println("My Booking Tab is selected.");
		WebDriverWait wait=new WebDriverWait(driver, Duration.ofSeconds(120));
		wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//div[@class='inner_sub_text']")));
           
		File src=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
		FileHandler.copy(src, new File("./Screenshot/Mybookingpage.png"));
		
		
//====================================================================================================================
		
// --------------------------searching transaction with reference details--------------------------------------- //
		//Field for the Reference number. 
//		WebElement searchref=driver.findElement(By.xpath("//input[@name='referenceId']"));
//		searchref.click();
//		Thread.sleep(1000);
//		searchref.sendKeys(SearchReference);
//		Thread.sleep(1000);
//		//-------------------------------------------------
//		//Search using Email.
//		WebElement searchemail=driver.findElement(By.xpath("(//input[@name='email'])[2]"));
//		searchemail.click();
//		Thread.sleep(1000);
//		searchemail.sendKeys(SearchEmail);
//		Thread.sleep(1000);
		//---------------------------------------------------
		
		//If selecting phone number for search
//		WebElement phonecode=driver.findElement(By.xpath("//select[@name='countryCode']"));
//		phonecode.click();
//		Thread.sleep(1000);
//		Select sc=new Select(phonecode);
//		sc.selectByVisibleText("+91");
//		Thread.sleep(1000);		
//		WebElement searchphoneno=driver.findElement(By.xpath("//input[@name='phonenumber']"));
//		searchphoneno.click();
//		Thread.sleep(1000);
//		searchphoneno.sendKeys(SearchPhoneNO);
//		Thread.sleep(1000);
//		
//		//View button for provide transaction search.
//		driver.findElement(By.xpath("//button[contains(@class,'mngbkngbtn2')]")).click();
//		System.out.println("View button clicked for get the transaction detail.");
//		WebDriverWait wait3=new WebDriverWait(driver, Duration.ofSeconds(120));
//		wait3.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("(//div[contains(@class,'myBook_bdr')])[1]")));
//	    File src2=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
//		FileHandler.copy(src2, new File("./Screenshot/Particulartransaction.png"));
		
//====================================================================================================================
		
		
		
// -------------------------login through checking the transaction in the  my booking.-------------------------------------//
		
		WebElement loginemail=driver.findElement(By.xpath("(//input[@name='email'])[1]"));
		loginemail.click();
		Thread.sleep(1000);
		loginemail.sendKeys(LoginEmail);
		Thread.sleep(1000);
		
		WebElement loginpassword=driver.findElement(By.xpath("(//input[@name='password'])"));
		loginpassword.click();
		Thread.sleep(1000);
		loginpassword.sendKeys(LoginPassword);
		Thread.sleep(1000);
		//login continue button
		driver.findElement(By.xpath("//button[contains(@class,'mngbkngbtn1')]")).click();
		
		WebDriverWait wait1=new WebDriverWait(driver, Duration.ofSeconds(120));
		wait1.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//input[@id='popup_ok']")));
		
		driver.findElement(By.xpath("//input[@id='popup_ok']")).click();
		System.out.println("Login Success.");
		
		
		WebDriverWait wait2=new WebDriverWait(driver, Duration.ofSeconds(120));
		wait2.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("(//div[@class='react-tabs']//li//a)[2]")));
		File src1=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
		FileHandler.copy(src1, new File("./Screenshot/Loginsection.png"));
		//selecting an transaction result by clicking the view button.
		driver.findElement(By.xpath("(//div[@class='myb_items_heading']//a)[1]")).click();
		System.out.println("Provided the itinerary details for the clicked transaction in Upcoming section");
		Thread.sleep(5000);
		
		driver.findElement(By.xpath("(//div[@class='react-tabs']//li//a)[2]")).click();// Button for show the travel completed transactions.
		Thread.sleep(2000);
		driver.findElement(By.xpath("(//div[@class='myb_items_heading']//a)[1]")).click();
		System.out.println("Provided the itinerary details for the clicked transaction in Completed section");
		
	
	}
}
