I had a long pending issue in a selenium script. Problem was, after succesfully completing a flight booking transaction, I wanted to verify the confirmation message and get the pass result.This is the way I had implemented
public void isFlightConfirmationSuccessful(){
System.out.println(flightConfirmation.getText());
if(flightConfirmation.getText()==("Your itinerary has been booked!")){
System.out.println("Flight Booked Successfully");
if("more data" != null){
backToFlights.click();
}else
{
logOut.click();
}
}else{
System.out.println("Flight Not Booked");
}
}
Even though this method flightConfirmation.getText() would return the same string as expected "Your itinerary has been booked!" ,
still I would get the result false.
I was missing a java concept here "==" is not same as ".equals"
".equals" checks the equality of content
"==" checks the equality of references
This is the code that passes the test
public void isFlightConfirmationSuccessful(){
System.out.println(flightConfirmation.getText());
if(flightConfirmation.getText().equals("Your itinerary has been booked!")){
System.out.println("Flight Booked Successfully");
if("more data" != null){
backToFlights.click();
}else
{
logOut.click();
}
}else{
System.out.println("Flight Not Booked");
}
}
public void isFlightConfirmationSuccessful(){
System.out.println(flightConfirmation.getText());
if(flightConfirmation.getText()==("Your itinerary has been booked!")){
System.out.println("Flight Booked Successfully");
if("more data" != null){
backToFlights.click();
}else
{
logOut.click();
}
}else{
System.out.println("Flight Not Booked");
}
}
Even though this method flightConfirmation.getText() would return the same string as expected "Your itinerary has been booked!" ,
still I would get the result false.
I was missing a java concept here "==" is not same as ".equals"
".equals" checks the equality of content
"==" checks the equality of references
This is the code that passes the test
public void isFlightConfirmationSuccessful(){
System.out.println(flightConfirmation.getText());
if(flightConfirmation.getText().equals("Your itinerary has been booked!")){
System.out.println("Flight Booked Successfully");
if("more data" != null){
backToFlights.click();
}else
{
logOut.click();
}
}else{
System.out.println("Flight Not Booked");
}
}
No comments:
Post a Comment