Mini Project Cucumber-Selenium Handson
Mini Project Cucumber-Selenium Handson
hooks.driver.get("file:///./projects/challenge/web/log
in.html");
hooks.driver.manage().window().maximize();
String actualTitle=
hooks.driver.findElement(By.xpath("//h1[contains(text(
),'Hotel Booking Application')]")).getText();
if(actualTitle.contains("Hotel Booking
Application")){
System.out.println(actualTitle);
System.out.print("Title matched successfully");
}
}
@When("^I enter username only$")
public void I_enter_username_only() throws
Throwable{
hooks.driver.findElement(By.xpath("//input[@name='user
Name']")).sendKeys("Dips");
}
@When("^I click on Login button1$")
public void I_click_on_Login_button1() throws
Throwable{
hooks.driver.findElement(By.xpath("//input[@value='Log
in']")).click();
String error=
hooks.driver.findElement(By.xpath("//div[@id='pwdErrMs
g']")).getText();
String actualError = "* Please enter
password.";
if(error.equalsIgnoreCase(actualError)){
System.out.println(actualError);
System.out.println("Error Message is
validated");
}
}
@When("^I enter wrong password$")
public void I_enter_wrong_password() throws
Throwable{
hooks.driver.findElement(By.xpath("//input[@name='user
Pwd']")).sendKeys("check");
hooks.driver.findElement(By.xpath("//input[@value='Log
in']")).click();
String alertMsg
=hooks.driver.switchTo().alert().getText();
System.out.print(alertMsg);
hooks.driver.switchTo().alert().accept();
}
@When("^I enter correct details$")
public void I_enter_correct_details() throws
Throwable{
hooks.driver.findElement(By.xpath("//input[@name='user
Name']")).clear();
hooks.driver.findElement(By.xpath("//input[@name='user
Name']")).sendKeys("admin");
hooks.driver.findElement(By.xpath("//input[@name='user
Pwd']")).clear();
hooks.driver.findElement(By.xpath("//input[@name='user
Pwd']")).sendKeys("admin");
}
@When("^I click on Login Button3$")
public void I_click_on_Login_Button3() throws
Throwable{
hooks.driver.findElement(By.xpath("//input[@value='Log
in']")).click();
String newTitle =
hooks.driver.findElement(By.xpath("//h2[text()='Hotel
Booking Form']")).getText();
System.out.println(newTitle);
hooks.driver.get("file:///./projects/challenge/web/hot
elbooking.html");
hooks.driver.manage().window().maximize();
System.out.println(hooks.driver.getTitle());
}
@When("^I click confirm booking button$")
public void I_click_confirm_booking_button()
throws Throwable{
hooks.driver.findElement(By.xpath("//input[@id='btnPay
ment']")).click();
}
@When("^I check for alert for first name$")
public void I_check_for_alert_for_first_name()
throws Throwable{
String alertMsg1
=hooks.driver.switchTo().alert().getText();
System.out.print(alertMsg1);
hooks.driver.switchTo().alert().accept();
}
@When("^I enter first name and click confirm
booking$")
public void
I_enter_first_name_and_click_confirm_booking() throws
Throwable{
hooks.driver.findElement(By.xpath("(//input[@name='txt
FN'])[1]")).sendKeys("Puja");
hooks.driver.findElement(By.xpath("//input[@id='btnPay
ment']")).click();
}
@When("^I check for alert for last name$")
public void I_check_for_alert_for_last_name()
throws Throwable{
String alertMsg2
=hooks.driver.switchTo().alert().getText();
System.out.print(alertMsg2);
hooks.driver.switchTo().alert().accept();
}
@When("^I enter last name and click confirm
booking$")
public void
I_enter_last_name_and_click_confirm_booking() throws
Throwable{
hooks.driver.findElement(By.xpath("//input[@id='txtLas
tName']")).sendKeys("Kumari");
hooks.driver.findElement(By.xpath("//input[@id='btnPay
ment']")).click();
}
@When("^I check for alert for email$")
public void I_check_for_alert_for_email() throws
Throwable{
String alertMsg3
=hooks.driver.switchTo().alert().getText();
System.out.print(alertMsg3);
hooks.driver.switchTo().alert().accept();
}
@When("^I enter email and click confirm booking$")
public void
I_enter_email_and_click_confirm_booking() throws
Throwable{
hooks.driver.findElement(By.xpath("//input[@id='txtEma
il']")).sendKeys("[email protected]");
hooks.driver.findElement(By.xpath("//input[@id='btnPay
ment']")).click();
}
@When("^I check for alert for mobile number$")
public void I_check_for_alert_for_mobile_number()
throws Throwable{
String alertMsg4
=hooks.driver.switchTo().alert().getText();
System.out.print(alertMsg4);
hooks.driver.switchTo().alert().accept();
}
@When("^I enter invalid mobile no and click
confirm booking$")
public void
I_enter_invalid_mobile_no_and_click_confirm_booking()
throws Throwable{
hooks.driver.findElement(By.xpath("//input[@id='txtPho
ne']")).sendKeys("901451234");
hooks.driver.findElement(By.xpath("//input[@id='btnPay
ment']")).click();
}
@When("^I check for alert for contact no$")
public void I_check_for_alert_for_contact_no()
throws Throwable{
String alertMsg5
=hooks.driver.switchTo().alert().getText();
System.out.print(alertMsg5);
hooks.driver.switchTo().alert().accept();
}
@When("^I enter contact no and click confirm
booking$")
public void
I_enter_contact_no_and_click_confirm_booking() throws
Throwable{
hooks.driver.findElement(By.xpath("//input[@id='txtPho
ne']")).clear();
hooks.driver.findElement(By.xpath("//input[@id='txtPho
ne']")).sendKeys("9014512345");
hooks.driver.findElement(By.xpath("//input[@id='btnPay
ment']")).click();
}
@When("^I check alert for city$")
public void I_check_alert_for_city() throws
Throwable{
String alertMsg6
=hooks.driver.switchTo().alert().getText();
System.out.print(alertMsg6);
hooks.driver.switchTo().alert().accept();
}
@When("^I select city and click confirm booking$")
public void
I_select_city_and_click_confirm_booking() throws
Throwable{
dropCity.selectByVisibleText("Pune");
hooks.driver.findElement(By.xpath("//input[@id='btnPay
ment']")).click();
}
@When("^I check alert for state$")
public void I_check_alert_for_state() throws
Throwable{
String alertMsg7
=hooks.driver.switchTo().alert().getText();
System.out.print(alertMsg7);
hooks.driver.switchTo().alert().accept();
}
@When("^I select state and click confirm
booking$")
public void
I_select_state_and_click_confirm_booking() throws
Throwable{
dropState.selectByVisibleText("Maharashtra");
hooks.driver.findElement(By.xpath("//input[@id='btnPay
ment']")).click();
}
@When("^I check alert for cardholder name$")
public void I_check_alert_for_cardholder_name()
throws Throwable{
String alertMsg8
=hooks.driver.switchTo().alert().getText();
System.out.print(alertMsg8);
hooks.driver.switchTo().alert().accept();
}
@When("^I enter cardholder name and click confirm
booking$")
public void
I_enter_cardholder_name_and_click_confirm_booking()
throws Throwable{
hooks.driver.findElement(By.xpath("//input[@id='txtCar
dholderName']")).sendKeys("puja");
hooks.driver.findElement(By.xpath("//input[@id='btnPay
ment']")).click();
}
@When("^I check for alert for debit card number$")
public void
I_check_for_alert_for_debit_card_number() throws
Throwable{
String alertMsg9
=hooks.driver.switchTo().alert().getText();
System.out.print(alertMsg9);
hooks.driver.switchTo().alert().accept();
}
@When("^I enter card details and click confirm
booking$")
public void
I_enter_card_details_and_click_confirm_booking()
throws Throwable{
hooks.driver.findElement(By.xpath("//input[@id='txtDeb
it']")).sendKeys("9014512345123456");
hooks.driver.findElement(By.xpath("//input[@id='btnPay
ment']")).click();
}
@When("^I check alert for cvv")
public void I_check_alert_for_cvv() throws
Throwable{
String alertMsg10
=hooks.driver.switchTo().alert().getText();
System.out.print(alertMsg10);
hooks.driver.switchTo().alert().accept();
}
@When("^I enter cvv and click confirm booking")
public void
I_enter_cvv_and_click_confirm_booking() throws
Throwable{
hooks.driver.findElement(By.xpath("//input[@id='txtCvv
']")).sendKeys("123");
hooks.driver.findElement(By.xpath("//input[@id='btnPay
ment']")).click();
}
@When("^I check alert for exp month")
public void I_check_alert_for_exp_month() throws
Throwable{
String alertMsg11
=hooks.driver.switchTo().alert().getText();
System.out.print(alertMsg11);
hooks.driver.switchTo().alert().accept();
}
@When("^I enter exp month and click confirm
booking")
public void
I_enter_exp_month_and_click_confirm_booking() throws
Throwable{
hooks.driver.findElement(By.xpath("//input[@id='txtMon
th']")).sendKeys("11");
hooks.driver.findElement(By.xpath("//input[@id='btnPay
ment']")).click();
}
@When("^I check alert for exp year")
public void I_check_alert_for_exp_year() throws
Throwable{
String alertMsg12
=hooks.driver.switchTo().alert().getText();
System.out.print(alertMsg12);
hooks.driver.switchTo().alert().accept();
}
@When("^I enter exp year and click confirm
booking")
public void
I_enter_exp_year_and_click_confirm_booking() throws
Throwable{
hooks.driver.findElement(By.xpath("//input[@id='txtYea
r']")).sendKeys("2024");
hooks.driver.findElement(By.xpath("//input[@id='btnPay
ment']")).click();
}
@Then("^I should go to success page$")
public void I_should_go_to_success_page() throws
Throwable{
System.out.print(hooks.driver.getTitle());
hooks.driver.close();
hooks.driver.get("file:///./projects/challenge/web/suc
cess.html");
hooks.driver.manage().window().maximize();
}
System.out.println(hooks.driver.getTitle());
}
@Then("^close the browser")
public void close_the_browser() throws Throwable{
hooks.driver.close();