-1

I am trying to automate the MakeMy trip website using Selenium Webdriver in Java with Google Chrome. My script is failing once I click on the Search button. Error message:

Access Denied
You don't have permission to access "http://www.makemytrip.com/flight/search?" on this server.
Reference #18.4d5ddb17.1557671136.2b95fb

I have tried running it manually on Chrome and found it to be running fine. However, through my Java code it's failing due to the above permissions issue. Any leads?

import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.NoSuchFrameException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import com.google.common.base.Function;
import com.qa.uiMap.AgentDetails;
import com.qa.uiMap.Flights;
import com.qa.uiMap.HomePage;
import com.qa.uiMap.PropertyDetails;
import com.qa.uiMap.PropertyListing;

import ExcelReader.ExcelReader;

public class SearchFlightResultsTest2 {

    WebDriver driver;
    String baseUrl;

    @BeforeTest
    public void setUp() throws Exception {
        System.setProperty("webdriver.chrome.driver", "./src/test/resources/drivers/chromedriver.exe");
        driver = new ChromeDriver();
        baseUrl = "https://www.makemytrip.com/";
        driver.manage().deleteAllCookies();
        driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.get(baseUrl);
        ExcelReader.testDataExcelFileName = "TestExcel.xlsx";
        ExcelReader.setExcelFileSheet("PropertySearchTest");
    }

    //  @BeforeMethod
    @Test(priority = 1)
    public void closePromoImages() throws NoSuchFrameException {

        try {
            driver.switchTo().frame("webklipper-publisher-widget-container-notification-frame");
            WebDriverWait wait = new WebDriverWait(driver, 60);
            wait.until(ExpectedConditions.visibilityOf(HomePage.imgPromotionClose(driver)));
            if (HomePage.imgPromotionClose(driver).isDisplayed()) {
                HomePage.imgPromotionClose(driver).click();
            }
            driver.switchTo().defaultContent();
            // Thread.sleep(5000);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @Test(priority = 2)
    public void selectTripOption() throws InterruptedException {

        //      WebDriverWait wait = new WebDriverWait(driver, 60);
        //      wait.until(ExpectedConditions.visibilityOf(HomePage.icnSelectOption(driver, "Flights")));

        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
                .withTimeout(Duration.ofSeconds(100))
                .pollingEvery(Duration.ofMillis(600))
                .ignoring(WebDriverException.class);

        WebElement we = wait.until(new Function<WebDriver, WebElement>() {
            public WebElement apply(WebDriver driver) {
                WebElement optionFlights = HomePage.icnSelectOption(driver, "Flights");
                if (optionFlights.isDisplayed()) {
                    optionFlights.click();
                } else {
                    System.out.println("Missing Flight Option");
                } 
                return optionFlights;
            }
        });

        //      we.click();
        Assert.assertEquals(HomePage.icnSelectOption(driver, "Flights").isDisplayed(), true,
                "Flight option is selectd sucessfully.");
    }

    @Test(priority = 3)
    public void selectTripType() throws InterruptedException {

        WebDriverWait wait = new WebDriverWait(driver, 30);
        wait.until(ExpectedConditions.visibilityOf(Flights.rdbSelectTripOption(driver, "Round Trip")));
        if (Flights.rdbSelectTripOption(driver, "Round Trip").isDisplayed()) {
            Flights.rdbSelectTripOption(driver, "Round Trip").click();
            Assert.assertEquals(Flights.rdbSelectTripOption(driver, "Round Trip").isDisplayed(), true,
                    "Round Type flight option is selected sucessfully.");
        } else {
            // System.out.println("Round Type flight option is not Available :: fail");
            Assert.assertEquals(Flights.rdbSelectTripOption(driver, "Round Trip").isDisplayed(), false,
                    "Round Type flight option is missing.");
        }

    }

    @Test(priority = 4)
    public void selectFromCity() throws InterruptedException {

        if (Flights.txtFromCity(driver).isDisplayed()) {
            Flights.txtFromCity(driver).sendKeys("Delhi");
            Flights.txtFromCity(driver).sendKeys(Keys.ENTER);
            Thread.sleep(1000);
            System.out.println("From City Delhi Selected");
        } else {
            // System.out.println("Round Type flight option is not Available :: fail");
            //          Assert.assertEquals(Flights.rdbSelectTripOption(driver, "Round Trip").isDisplayed(), false,
            //                  "Round Type flight option is missing.");
        }

    }

    @Test(priority = 5)
    public void selectToCity() throws InterruptedException {

        if (Flights.txtToCity(driver).isDisplayed()) {
            Flights.txtToCity(driver).sendKeys("Banglore");
            Flights.txtToCity(driver).sendKeys(Keys.ENTER);
            Thread.sleep(1000);
            System.out.println("To City Banglore Selected");
        } else {
        }

    }

    @Test(priority = 6)
    public void selectDepartureDate() throws InterruptedException {

        if (Flights.txtDepartureDate(driver).isDisplayed()) {
            Flights.txtDepartureDate(driver).click();
            Thread.sleep(1000);
            System.out.println("Departure Date is Clicked");

            System.out.println(driver.findElement(By.xpath("//div[@class='DayPicker-Month']/div/div[contains(text(),'May')]")).getText());

            driver.findElement(By.xpath("//div[contains(text(),'Jun')]/../../div/div/div[@aria-disabled='false']/div/p[1][contains(text(),'16')]")).click();            
        } else {
        }
    }
    @Test(priority = 6)
    public void selectReturnDate() throws InterruptedException {

        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
                .withTimeout(Duration.ofSeconds(100))
                .pollingEvery(Duration.ofMillis(600))
                .ignoring(WebDriverException.class);

        WebElement we = wait.until(new Function<WebDriver, WebElement>() {
            public WebElement apply(WebDriver driver) {
                WebElement returnDate = Flights.txtReturnDate(driver);
                if (returnDate.isDisplayed()) {
//                  returnDate.click();
                    System.out.println(driver.findElement(By.xpath("//div[@class='DayPicker-Month']/div/div[contains(text(),'May')]")).getText());              
                    driver.findElement(By.xpath("//div[contains(text(),'Jun')]/../../div/div/div[@aria-disabled='false']/div/p[1][contains(text(),'26')]")).click();

                } else {
                    System.out.println("Return Dates are not selected");
                } 
                return returnDate;
            }
        });
    }

    @Test(priority = 7)
    public void clickSearch() throws InterruptedException {
        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
                .withTimeout(Duration.ofSeconds(100))
                .pollingEvery(Duration.ofMillis(600))
                .ignoring(WebDriverException.class);

        WebElement we = wait.until(new Function<WebDriver, WebElement>() {
            public WebElement apply(WebDriver driver) {
                WebElement btnSearch = Flights.btnSearch(driver, "Search");
                if (btnSearch.isDisplayed()) {
                    btnSearch.click();

                } else {
                    System.out.println("Missing Search Button ");
                } 
                return btnSearch;
            }
        });

    }

    @AfterTest
    public void tearDown() {
        driver.quit();
    }

}
0

In the error message you have -> "http://www.makemytrip.com/flight/search" This link does not look like valid. (flights instead of flight worked for me) Can you try the url -> "https://www.makemytrip.com/flights/search"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.