diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..5008ddfc Binary files /dev/null and b/.DS_Store differ diff --git a/Readme.md b/Readme.md new file mode 100644 index 00000000..39094d40 --- /dev/null +++ b/Readme.md @@ -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. diff --git a/SuiteXml/SanityTest.xml b/SuiteXml/SanityTest.xml new file mode 100644 index 00000000..76e0c7bb --- /dev/null +++ b/SuiteXml/SanityTest.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/chromedriver b/chromedriver index 93c906e2..4ff3bcce 100755 Binary files a/chromedriver and b/chromedriver differ diff --git a/codoingRound.iml b/codoingRound.iml new file mode 100644 index 00000000..e9771281 --- /dev/null +++ b/codoingRound.iml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/FlightBookingTest.java b/src/main/java/FlightBookingTest.java index 19d98ddf..68c9f025 100644 --- a/src/main/java/FlightBookingTest.java +++ b/src/main/java/FlightBookingTest.java @@ -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 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 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 @@ -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"); - } - } + } diff --git a/src/main/java/HotelBooking.java b/src/main/java/HotelBooking.java new file mode 100644 index 00000000..777564f8 --- /dev/null +++ b/src/main/java/HotelBooking.java @@ -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(); + + } + + +} diff --git a/src/main/java/HotelBookingTest.java b/src/main/java/HotelBookingTest.java index 2be026bb..1fb72ed2 100644 --- a/src/main/java/HotelBookingTest.java +++ b/src/main/java/HotelBookingTest.java @@ -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"); - } } + } diff --git a/src/main/java/SignInTest.java b/src/main/java/SignInTest.java index 2c109950..0b7070ee 100644 --- a/src/main/java/SignInTest.java +++ b/src/main/java/SignInTest.java @@ -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"); - } - } - } diff --git a/src/main/java/TestBase.java b/src/main/java/TestBase.java new file mode 100644 index 00000000..cfab181d --- /dev/null +++ b/src/main/java/TestBase.java @@ -0,0 +1,61 @@ +import com.sun.javafx.PlatformUtil; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeOptions; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterSuite; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.BeforeTest; + +import java.util.concurrent.TimeUnit; + +public class TestBase { + public WebDriver driver; + + + public void setUpDriver() { + ChromeOptions options = new ChromeOptions(); + options.addArguments("--disable-notifications"); + driver = new ChromeDriver(options); + setDriverPath(); + driver.manage().window().maximize(); + driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + } + + + protected 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"); + } + } + + + protected void explicitWait(By by) { + WebDriverWait wait = new WebDriverWait(driver, 15); + wait.until(ExpectedConditions.visibilityOfElementLocated(by)); + + } + + + @BeforeClass + public void initDriver() { + setUpDriver(); + } + + @AfterClass + public void closeBrowser() { + driver.quit(); + } + +} diff --git a/target/classes/FlightBookingTest.class b/target/classes/FlightBookingTest.class new file mode 100644 index 00000000..957838e7 Binary files /dev/null and b/target/classes/FlightBookingTest.class differ diff --git a/target/classes/HotelBooking.class b/target/classes/HotelBooking.class new file mode 100644 index 00000000..c93d41ae Binary files /dev/null and b/target/classes/HotelBooking.class differ diff --git a/target/classes/HotelBookingTest.class b/target/classes/HotelBookingTest.class new file mode 100644 index 00000000..76b209e7 Binary files /dev/null and b/target/classes/HotelBookingTest.class differ diff --git a/target/classes/SignInTest.class b/target/classes/SignInTest.class new file mode 100644 index 00000000..b274b506 Binary files /dev/null and b/target/classes/SignInTest.class differ diff --git a/target/classes/TestBase.class b/target/classes/TestBase.class new file mode 100644 index 00000000..ea60ab01 Binary files /dev/null and b/target/classes/TestBase.class differ