Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
.idea
.gradle
.gradle
/target
15 changes: 15 additions & 0 deletions Review_Comment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
THIS FILE LISTS ALL THE REVIEW COMMENTS/ NEW CHANGES ON THE CURRENT FRAMEWORK
ALSO I HAVE IMPLEMENTED MOST OF THE REVIEW COMMENTS

=> Each test can be executed and is passing right now.
=> The thread.sleep is a hard pause, removed that to introduce dynamic waits.
=> Having selectors local to every test case is code repetition and hard to manage,
hence introduced POM framework.
=> Added surefire plugin to be able to get variables at runtime.
=> Action methods like click, sendKeys have been segregated to a new class "ActionSupport"
=> Added testng.xml file
=> Added BaseTest class to have framework level data initialization globally and
using inheritance to avail it throughout the classes.
=> Updated chromedriver to latest version to support latest chrome version.
=> Introduced property file which is also environment specific to store constants like URL.
=> Utility class to have the common methods like property initialization, getting web elements
Binary file modified chromedriver
Binary file not shown.
Binary file added chromedriver_
Binary file not shown.
91 changes: 65 additions & 26 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.testvagrant.codingRound</groupId>
<artifactId>codoingRound</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.6.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>compile</scope>
</dependency>
</dependencies>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.testvagrant.codingRound</groupId>
<artifactId>codoingRound</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<env>Stage</env>
<suiteXmlFile>testng.xml</suiteXmlFile>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<!-- Surefire plugin to run xml files -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<systemProperties>
<property>
<name>env</name>
<value>${env}</value>
</property>
</systemProperties>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.6.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
68 changes: 68 additions & 0 deletions src/main/java/ActionSupport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.Select;

import java.util.Calendar;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

public class ActionSupport {

WebDriver driver;
WebElement element = null;
Utility oUtility;

public ActionSupport(WebDriver driver) {
this.driver = driver;
oUtility = new Utility(driver);

}

public void clickElement(By selector) {

element = oUtility.getWebElement(selector);
try {
element.click();
} catch (Exception e) {
System.out.println("element could not be clicked, Exception - " + e.getMessage());
}
}

public void setTextToInputfield(By selector, String text) {

element = oUtility.getWebElement(selector);
try {
element.clear();
element.sendKeys(text);
} catch (Exception e) {
System.out.println("The text - " + text + " could not be set to element due to exception - " + e.getMessage());
}
}

public String getElementText(By selector) {
element = oUtility.getWebElement(selector);
return element.getText();
}

public void switchToFrameByWebElement(By selector) {
element = oUtility.getWebElement(selector);
try {
driver.switchTo().frame(element);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}

public void selectValueByTextInDropdown(By selector, String text) {
try {
Select dropdown = new Select(oUtility.getWebElement(selector));
dropdown.selectByVisibleText(text);
} catch (Exception e) {
System.out.println(e.getMessage());
}

}
}
62 changes: 62 additions & 0 deletions src/main/java/BaseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;

import java.util.Properties;
import java.util.concurrent.TimeUnit;


public class BaseTest {

WebDriver driver;
WebElement element = null;
Utility oUtility;
String BASE_URL = "";
Properties propObj;
String environment = "";
ChromeOptions options = null;
ActionSupport actions;
@BeforeSuite
public void setupSuiteConfig() {
setEnvironment();
options = new ChromeOptions();
options.addArguments("--disable-notifications");
driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
actions = new ActionSupport(driver);
oUtility = new Utility(driver);
oUtility.setDriverPath();
propObj = oUtility.getProperty(environment);
BASE_URL = propObj.getProperty("BASE_URL");
}

@BeforeTest
public void testSetup() {


}

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

@AfterSuite
public void tearSuiteConfig() {
driver.quit();
}

public void setEnvironment() {
environment = System.getProperty("env");
if (environment == null) {
environment = "stage";
}

}
}
74 changes: 21 additions & 53 deletions src/main/java/FlightBookingTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import com.sun.javafx.PlatformUtil;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
Expand All @@ -7,83 +6,52 @@
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;
import org.testng.annotations.Test;
import pom.HomePageElements;
import pom.SearchSummaryPOM;

import java.util.List;

public class FlightBookingTest {

WebDriver driver = new ChromeDriver();
public class FlightBookingTest extends BaseTest {


@Test
public void testThatResultsAppearForAOneWayJourney() {

setDriverPath();
driver.get("https://www.cleartrip.com/");
waitFor(2000);
driver.findElement(By.id("OneWay")).click();

driver.findElement(By.id("FromTag")).clear();
driver.findElement(By.id("FromTag")).sendKeys("Bangalore");
driver.get(BASE_URL);

//wait for the auto complete options to appear for the origin
oUtility.waitForElementToBeVisible(HomePageElements.one_way_radio_button());
actions.clickElement(HomePageElements.one_way_radio_button());

oUtility.waitForElementToBeVisible(HomePageElements.from_input_text_field());
actions.setTextToInputfield(HomePageElements.from_input_text_field(), propObj.getProperty("STARTING_DESTINATION"));

waitFor(2000);
List<WebElement> originOptions = driver.findElement(By.id("ui-id-1")).findElements(By.tagName("li"));
originOptions.get(0).click();
//wait for the auto complete options to appear for the origin
oUtility.waitForElementToBeVisible(HomePageElements.from_search_result());
actions.clickElement(HomePageElements.from_search_result());

driver.findElement(By.id("toTag")).clear();
driver.findElement(By.id("toTag")).sendKeys("Delhi");

//wait for the auto complete options to appear for the destination
actions.setTextToInputfield(HomePageElements.to_input_text_field(), propObj.getProperty("END_DESTINATION"));

waitFor(2000);
//select the first item from the destination auto complete list
List<WebElement> destinationOptions = driver.findElement(By.id("ui-id-2")).findElements(By.tagName("li"));
destinationOptions.get(0).click();
//wait for the auto complete options to appear for the origin
oUtility.waitForElementToBeVisible(HomePageElements.to_search_result());
actions.clickElement(HomePageElements.to_search_result());

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

//all fields filled in. Now click on search
driver.findElement(By.id("SearchBtn")).click();

waitFor(5000);
//verify that result appears for the provided journey search
Assert.assertTrue(isElementPresent(By.className("searchSummary")));
// remove the hard pause and introduced explicit wait

//close the browser
driver.quit();
//oUtility.waitFor(5000);
oUtility.waitForElementToBeVisible(SearchSummaryPOM.search_summary());

}
//verify that result appears for the provided journey search
Assert.assertTrue(oUtility.isElementPresent(SearchSummaryPOM.search_summary()));


private void waitFor(int durationInMilliSeconds) {
try {
Thread.sleep(durationInMilliSeconds);
} catch (InterruptedException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}


private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}

private void setDriverPath() {
if (PlatformUtil.isMac()) {
System.setProperty("webdriver.chrome.driver", "chromedriver");
}
if (PlatformUtil.isWindows()) {
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
}
if (PlatformUtil.isLinux()) {
System.setProperty("webdriver.chrome.driver", "chromedriver_linux");
}
}
}
Loading