Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull Request for the Coding Round in TestVagrant #75

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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.
21 changes: 21 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

Have used the Various Testng annotations like @BeforeClass ,@Afterclass as per the requirements.

// Create a new file TestBase.java.

Create a new setup method which is used to set the following things.
Used to maximize the browser size.
User to disable the google chrome browser Notifications.
Have used the concept of the Inheritance




// Create New xml file to run the regression parallely.

// create a new HotelBookingTest File which uses the concept of the page factory model.


//Instead of the Thread. sleep functionality have used the concept of the Implicit wait and the explicit wait.

//Have fixed the various Web elements Xpath which are more accurate then the previous one.
15 changes: 15 additions & 0 deletions SuiteXml/SanityTest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="ClearTripTestSuite" thread-count="1" parallel="classes">


<test name="HotelBooking">
<classes>

<class name="SignInTest"></class>
<class name="HotelBookingTest"></class>
<class name="FlightBookingTest"></class>
</classes>
</test>
</suite>
Binary file modified chromedriver
Binary file not shown.
42 changes: 42 additions & 0 deletions codoingRound.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: junit:junit:4.11" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-java:3.6.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-api:3.6.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-chrome-driver:3.6.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-edge-driver:3.6.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-firefox-driver:3.6.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-ie-driver:3.6.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-opera-driver:3.6.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-remote-driver:3.6.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-safari-driver:3.6.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-support:3.6.0" level="project" />
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.7.5" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-exec:1.3" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:23.0" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.0.18" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.1" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.14" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.3" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.6" level="project" />
<orderEntry type="library" name="Maven: net.java.dev.jna:jna:4.1.0" level="project" />
<orderEntry type="library" name="Maven: net.java.dev.jna:jna-platform:4.1.0" level="project" />
<orderEntry type="library" name="Maven: org.testng:testng:6.11" level="project" />
<orderEntry type="library" name="Maven: com.beust:jcommander:1.64" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.17" level="project" />
</component>
</module>
50 changes: 20 additions & 30 deletions src/main/java/FlightBookingTest.java
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
import com.sun.javafx.PlatformUtil;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.util.List;

public class FlightBookingTest {
public class FlightBookingTest extends TestBase {

WebDriver driver = new ChromeDriver();


@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");

//wait for the auto complete options to appear for the origin
// explicitWait(By.xpath("//li[@class='list']"));

explicitWait(By.xpath("//ul[@id='ui-id-1']"));

waitFor(2000);
List<WebElement> originOptions = driver.findElement(By.id("ui-id-1")).findElements(By.tagName("li"));

originOptions.get(0).click();

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

//wait for the auto complete options to appear for the destination
explicitWait(By.xpath("//*[@id=\"ui-id-2\"]"));

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();
WebElement element1 = driver.findElement(By.xpath("//*[@id=\"DepartDate\"]"));

element1.sendKeys("29/11/2019");


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")));

//close the browser
Expand All @@ -75,15 +75,5 @@ private boolean isElementPresent(By by) {
}
}

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");
}
}

}
62 changes: 62 additions & 0 deletions src/main/java/HotelBooking.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.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class HotelBooking {


@FindBy(linkText = "Hotels")
private WebElement hotelLink;

@FindBy(id = "Tags")
private WebElement localityTextBox;

@FindBy(xpath = "//input[@id='SearchHotelsButton']")
private WebElement searchButton;


@FindBy(id = "travellersOnhome")
private WebElement travellerSelection;

@FindBy(xpath = "//input[@id='CheckInDate']")
private WebElement checkInDate;

@FindBy(xpath = "//div[contains(@class,'monthBlock first')]//a[contains(@class,'ui-state-default')][contains(text(),'28')]")
private WebElement date;


@FindBy(xpath = "//tr[1]//td[7]//a[1]")
private WebElement checkOutDate1;

@FindBy(xpath = "//input[@id='CheckOutDate']")
private WebElement checkOutDate;


public HotelBooking(WebDriver driver) {
PageFactory.initElements(driver, this);
}

public void click() {
hotelLink.click();
}

public void setLocality(String locality) {
localityTextBox.sendKeys(locality);
}

public void selectCheckInAndCheckoutDate() {
checkInDate.click();
date.click();
checkOutDate.click();
checkOutDate1.click();
}

public void searchHotelclick() {

searchButton.click();

}


}
47 changes: 9 additions & 38 deletions src/main/java/HotelBookingTest.java
Original file line number Diff line number Diff line change
@@ -1,53 +1,24 @@
import com.sun.javafx.PlatformUtil;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Test;

public class HotelBookingTest {

WebDriver driver = new ChromeDriver();

@FindBy(linkText = "Hotels")
private WebElement hotelLink;

@FindBy(id = "Tags")
private WebElement localityTextBox;

@FindBy(id = "SearchHotelsButton")
private WebElement searchButton;

@FindBy(id = "travellersOnhome")
private WebElement travellerSelection;
public class HotelBookingTest extends TestBase {

@Test
public void shouldBeAbleToSearchForHotels() {
setDriverPath();

HotelBooking hotelBooking = new HotelBooking(driver);

driver.get("https://www.cleartrip.com/");
hotelLink.click();

localityTextBox.sendKeys("Indiranagar, Bangalore");
hotelBooking.click();

new Select(travellerSelection).selectByVisibleText("1 room, 2 adults");
searchButton.click();
hotelBooking.setLocality("Indiranagar, Bangalore");

driver.quit();
hotelBooking.selectCheckInAndCheckoutDate();

hotelBooking.searchHotelclick();

}

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");
}
}


}
37 changes: 12 additions & 25 deletions src/main/java/SignInTest.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,38 @@
import com.sun.javafx.PlatformUtil;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class SignInTest {
public class SignInTest extends TestBase {

WebDriver driver = new ChromeDriver();

@Test
public void shouldThrowAnErrorIfSignInDetailsAreMissing() {
public void shouldThrowAnErrorIfSignInDetailsAreMissing() throws InterruptedException {

setDriverPath();

driver.get("https://www.cleartrip.com/");
waitFor(2000);

driver.findElement(By.linkText("Your trips")).click();
driver.findElement(By.id("SignIn")).click();

driver.findElement(By.id("signInButton")).click();
driver.switchTo().frame("modal_window");

Thread.sleep(10000);
WebElement element = driver.findElement(By.id("signInButton"));

JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);


String errors1 = driver.findElement(By.id("errors1")).getText();
Assert.assertTrue(errors1.contains("There were errors in your submission"));
driver.quit();
}

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 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