Automation Code Test 1
Core Automation:
Navigate to https://blazedemo.com/index.php
- Check if the title is displayed as ` Welcome to the Simple Travel Agency!`. This is the Home Page of application
- Click on ` destination of the week! The Beach!` hyperlink and see if a new tab opens in your browser & the url has string `vacation`. Navigate back to home page tab.
- Purchase a ticket:
- Select `Mexico City` in departure city & `London` in destination city.
- Click ‘Find Flights’. Select the flight with lowest price by clicking `Choose the flight` & see if we are navigated to purchase page (This should be dynamically handled and can work for any inputs in Step 3.a)
- Check if a field named ‘Total Cost’ is available with price available in xxx.xx format. Click on ‘Purchase flight’ button
- Check if the user is navigated to Purchase Confirmation page & store the `Id’ in the console or test report for future reference.
POINTS TO CONSIDER:
- Create a new Java, Maven, C# project with an appropriate test framework like Nunit, TestNG etc.,
- Automate tests in Chrome browser
- Use parameterized data instead of hardcoded test data
- Use Page Object Model with Selenium
- Make your functions more generic and use coding best practices as much as possible
- Once the test is done, please zip the entire project and send it to us
Solution:
- Create a new Project in Eclipse.
- Add the required libraries for Selenium.
Now in first you need to create an interface: driverHelp
import java.util.Properties;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public interface driverHelp {
public static WebDriver wd = new ChromeDriver();
public static String cd1 = "F:\\Work Environment\\MyProject\\chromedriver.exe";
public static String url = "https://blazedemo.com/index.php";
}
Once you create the interface, you need to create a new class “DemoTest” and implement the interface driverHelp.
Add the following code in your class file and run as TestNG project.
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.testng.annotations.AfterTest;
import org.openqa.selenium.support.ui.Select;
public class DemoTest implements driverHelp {
public static WebElement we1;
@BeforeTest
public void callDriver() {
System.setProperty("webdriver.chrome.driver", cd1);
wd.manage().deleteAllCookies();
wd.manage().window().maximize();
wd.get(url);
}
@Test
public void Test1() {
System.out.println(wd.getTitle());
String t1 = "Welcome to the Simple Travel Agency!";
if(t1.equals(wd.getTitle()) ) {
System.out.println("Title Matched the expected result");
}
}
@Test
public void Test2() {
wd.findElement(By.linkText("destination of the week! The Beach!")).click();
System.out.println(wd.getCurrentUrl());
wd.navigate().back();
System.out.println(wd.getCurrentUrl());
}
@Test
public void Test3() {
//d.findElement(By.className("form-inline")).click();
//.findElement(By.partialLinkText("Mexico City")).click();
Select scity = new Select(wd.findElement(By.className("form-inline")));
scity.selectByVisibleText("Mexico City");
scity.selectByIndex(4);
Select ecity = new Select(wd.findElement(By.name("toPort")));
ecity.selectByVisibleText("London");
ecity.selectByIndex(2);
wd.findElement(By.xpath("/html/body/div[3]/form/div/input")).click();
}
@Test
public void Test4() {
wd.findElement(By.xpath("/html/body/div[2]/table/tbody/tr[3]/td[1]/input")).click();
System.out.printf("Flight with the lowest fair",wd.getTitle());
}
@Test
public void Test5() {
if( wd.findElement(By.partialLinkText("Total Cost")).isDisplayed())
{
System.out.println("Total Coast is present");
}
}
@Test
public void Test6() {
wd.findElement(By.xpath("/html/body/div[2]/form/div[11]/div/input")).click();
System.out.println(wd.getCurrentUrl());
}
@AfterTest
public void afterTest() {
wd.quit();
}
}