Sunday, 18 January 2015

package testscript;

import java.util.concurrent.TimeUnit;


import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class KalyaniDoubt
{
private static String text="MakeMyTrip, India's No 1 Travel Site | Book Flights, Hotels, Holiday Packages & Bus Tickets";

@DataProvider(name="Authentication")
public static Object[][] credentials() {

        return new Object[][] { { "testuser_1", "Test@123" }, { "testuser_2", "Test@123" }};

  }

@Test(dataProvider = "Authentication")
public void test(String uname, String pwd) throws InterruptedException{
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.makemytrip.com/");

String title=driver.getTitle();
System.out.println("Title of the page:"+title);
Assert.assertEquals(text, title);
if (driver.getTitle().contains(text))
{
driver.findElement(By.id("login_dropOpenItem")).click();
driver.findElement(By.xpath("//*[@id='username']")).sendKeys(uname);
driver.findElement(By.xpath("//*[@id='password_text']")).sendKeys(pwd);


if(driver.findElement(By.xpath("//*[@id='login_btn']"))!= null)
{
    System.out.println("\n Continue button is PRESENT in the page");
}
else
{
 System.out.println("Continue Button is NOT PRESENT in the page");
}
driver.findElement(By.xpath("//*[@id='login_btn']")).click();
String errorMsg=driver.findElement(By.xpath("//*[@id='errormsg_password']")).getText();
System.out.println("Message displayed for not entering password:"+errorMsg);

// Code  for booking a flight and search /*
driver.findElement(By.xpath("//*[@id='widget_row']/div[1]/div/div[3]/div/div[2]/div[2]")).click();
Thread.sleep(2000);driver.findElement(By.xpath("//*[@id='one_way_button1']")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//*[@id='from_typeahead1']")).sendKeys("a");
driver.findElement(By.xpath("//*[@id='from_typeahead1']")).sendKeys(Keys.ARROW_DOWN);
driver.findElement(By.xpath("//*[@id='from_typeahead1']")).sendKeys(Keys.ENTER);
Thread.sleep(2000);


driver.findElement(By.xpath("//*[@id='to_typeahead1']")).sendKeys("b");

driver.findElement(By.xpath("//*[@id='to_typeahead1']")).sendKeys(Keys.ARROW_DOWN);
driver.findElement(By.xpath("//*[@id='to_typeahead1']")).sendKeys(Keys.ENTER);
Thread.sleep(2000);
// onward calender
driver.findElement(By.xpath("//*[@id='start_date_sec']/span[2]")).click();
//date pick
driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[2]/table/tbody/tr[3]/td[3]/a")).click();
// return calender

driver.findElement(By.xpath("//*[@id='return_date_sec']/span[2]")).click();

driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[2]/table/tbody/tr[5]/td[5]/a")).click();

Select dropdown = new Select(driver.findElement(By.xpath("//*[@id='class_selector']")));
dropdown.selectByVisibleText("Business");
driver.findElement(By.xpath("//*[@id='flights_submit']")).click();
*/
}
else{
System.out.println("Title of the page is different"+title);
}
}

}

No comments:

Post a Comment