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
17 changes: 16 additions & 1 deletion DemoApp/src/test/java/com/demo/tests/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
Expand All @@ -32,6 +34,7 @@ public WebDriver launchBrowser() {
capabilities.setPlatform(Platform.WINDOWS);
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver(capabilities);
driver.manage().deleteAllCookies();
driver.get(Url);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
Expand Down Expand Up @@ -68,7 +71,7 @@ public void elementPresence(By by, long seconds) {
}

// this method will quite the browser instance after executing the script.
//@AfterTest
@AfterTest
public void tearDown() {
getDriver().quit();
}
Expand Down Expand Up @@ -102,5 +105,17 @@ public String getCurrentDate(){

}

public void scrollIntoElement(By id){

WebElement element = driver.findElement(id);
JavascriptExecutor js = (JavascriptExecutor) getDriver();
js.executeScript("arguments[0].scrollIntoView(true);",element);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
46 changes: 28 additions & 18 deletions DemoApp/src/test/java/com/demo/tests/DemoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import java.util.ArrayList;
import java.util.Collections;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
Expand All @@ -14,56 +12,68 @@
public class DemoTest extends BaseTest{

HomePage homePage;


//launching the browser with emirates url
@BeforeClass
public void setUp(){
launchBrowser();
homePage = new HomePage(getDriver());
}


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

// waiting for the emirates home page should display and entering the departure airport
elementPresence(homePage.departureAirportTxt,40);
safeType(homePage.departureAirportTxt,"DXB");
safeClick(homePage.departureAirportList);


// Entering the arrival airport
elementPresence(homePage.arrivalAirportTxt,40);
safeType(homePage.arrivalAirportTxt,"LHR");
safeClick(homePage.arrivalAirportList);

// clicking on the data picker text box for selecting the particular travel date
safeClick(homePage.datePicker);

//safeClick(homePage.continueBtn);
// clicking on the particular travel date from the calender and its parameterized enter any date which one needs to travel
scrollIntoElement(homePage.selectTravelDate("13 May 18"));
safeClick(homePage.selectTravelDate("13 May 18"));
Thread.sleep(1000);

safeClick(homePage.datePicker);
//clicking on the particular retunr travel date from the calender and its parameterized enter any date which one needs to travel
scrollIntoElement(homePage.selectReturnDate("20 May 18"));
safeClick(homePage.selectReturnDate("20 May 18"));
Thread.sleep(1000);

getActions().moveToElement(getDriver().findElement(homePage.selectTravelDate)).click().build().perform();
// clicking on into the Search button
scrollIntoElement(homePage.searchFlightsBtn);
safeClick(homePage.searchFlightsBtn);

getActions().moveToElement(getDriver().findElement(homePage.selectReturnDate)).click().build().perform();

getActions().moveToElement(getDriver().findElement(homePage.searchFlightsBtn)).click().build().perform();
// waiting for the flights searcg results should display
elementPresence(homePage.searchResultList,40);
scrollIntoElement(homePage.searchResultList);

ArrayList<WebElement> price = (ArrayList<WebElement>) getDriver().findElements(By.xpath("//div[@class='ts-fbr-option__price-detail']/strong[@class='ts-fbr-option__price']"));
// getting all the price into the Array list
ArrayList<WebElement> price = (ArrayList<WebElement>) getDriver().findElements(homePage.searchResultList);

System.out.println("the web elements are ::"+price);

// getting the price from the search result page and adding into the array list
ArrayList<String> priceLst = new ArrayList<String>();
for(int i=0;i<price.size()-1;i++){
String price1 = price.get(i).getText();
priceLst.add(price1);
}


// sorting the array list with captured price from the search result page
Collections.sort(priceLst);

System.out.println("After Sorting the price:");
for(String counter: priceLst){
System.out.println(counter);
}
}






}
21 changes: 17 additions & 4 deletions DemoApp/src/test/java/com/pages/HomePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public HomePage(WebDriver driver){

public By departureAirportTxt = By.name("Departure airport");


public By searchResultList = By.xpath("//div[@class='ts-fbr-option__price-detail']//strong[@class='ts-fbr-option__price']");


public By departureAirportList = By.xpath("//a[contains(@aria-label,'Dubai International Airport (DXB), Dubai, United Arab Emirates')]");


Expand All @@ -24,13 +28,22 @@ public HomePage(WebDriver driver){
public By continueBtn = By.xpath("//a[contains(@class,'cta cta--large cta--primary js-continue-search-flight search-flight__continue--cta')]");


public By datePicker = By.name("search-flight-date-picker--depart");
public By datePicker = By.id("search-flight-date-picker--depart");



public By selectTravelDate = By.xpath("//a[@data-string='13 May 18']");
public By selectTravelDate(String date){
By selectTravelDate = By.xpath("//a[@aria-label="+"'"+date+"'"+"]");
return selectTravelDate;
}

public By selectReturnDate(String date){
By selectReturnDate = By.xpath("//a[@aria-label="+"'"+date+"'"+"]");
return selectReturnDate;
}

public By selectReturnDate = By.xpath("//a[@data-string='20 May 18']");

public By searchFlightsBtn = By.xpath("//span[text()='Search flights']");
public By searchFlightsBtn = By.xpath("//button/span[text()='Search flights']");


}
Binary file modified DemoApp/target/test-classes/com/demo/tests/BaseTest.class
Binary file not shown.
Binary file modified DemoApp/target/test-classes/com/demo/tests/DemoTest.class
Binary file not shown.
Binary file modified DemoApp/target/test-classes/com/pages/HomePage.class
Binary file not shown.
101 changes: 7 additions & 94 deletions DemoApp/test-output/Default suite/Default test.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,116 +55,29 @@
<body>
<h2 align='center'>Default test</h2><table border='1' align="center">
<tr>
<td>Tests passed/Failed/Skipped:</td><td>0/1/0</td>
<td>Tests passed/Failed/Skipped:</td><td>1/0/0</td>
</tr><tr>
<td>Started on:</td><td>Sun May 06 16:36:06 IST 2018</td>
<td>Started on:</td><td>Sun May 06 18:54:06 IST 2018</td>
</tr>
<tr><td>Total time:</td><td>67 seconds (67293 ms)</td>
<tr><td>Total time:</td><td>46 seconds (46792 ms)</td>
</tr><tr>
<td>Included groups:</td><td></td>
</tr><tr>
<td>Excluded groups:</td><td></td>
</tr>
</table><p/>
<small><i>(Hover the method name to see the test class name)</i></small><p/>
<table width='100%' border='1' class='invocation-failed'>
<tr><td colspan='4' align='center'><b>FAILED TESTS</b></td></tr>
<table width='100%' border='1' class='invocation-passed'>
<tr><td colspan='4' align='center'><b>PASSED TESTS</b></td></tr>
<tr><td><b>Test method</b></td>
<td width="30%"><b>Exception</b></td>
<td width="10%"><b>Time (seconds)</b></td>
<td><b>Instance</b></td>
</tr>
<tr>
<td title='com.demo.tests.DemoTest.test()'><b>test</b><br>Test class: com.demo.tests.DemoTest</td>
<td><div><pre>org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.name: search-flight-date-picker--depart (tried for 30 second(s) with 500 milliseconds interval)
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:81)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:271)
at com.demo.tests.BaseTest.safeClick(BaseTest.java:85)
at com.demo.tests.DemoTest.test(DemoTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
Caused by: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.name: search-flight-date-picker--depart
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: &apos;3.11.0&apos;, revision: &apos;e59cfb3&apos;, time: &apos;2018-03-11T20:26:55.152Z&apos;
System info: host: &apos;DELL&apos;, ip: &apos;192.168.56.1&apos;, os.name: &apos;Windows 8.1&apos;, os.arch: &apos;amd64&apos;, os.version: &apos;6.3&apos;, java.version: &apos;1.8.0_121&apos;
Driver info: driver.version: unknown
at org.openqa.selenium.support.ui.ExpectedConditions.lambda$findElement$0(ExpectedConditions.java:896)
at java.util.Optional.orElseThrow(Unknown Source)
at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:895)
at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:44)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:206)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:202)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:248)
... 27 more
</pre></div><a href='#' onClick='toggleBox("stack-trace1277933280", this, "Click to show all stack frames", "Click to hide stack frames")'>Click to show all stack frames</a>
<div class='stack-trace' id='stack-trace1277933280'><pre>org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.name: search-flight-date-picker--depart (tried for 30 second(s) with 500 milliseconds interval)
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:81)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:271)
at com.demo.tests.BaseTest.safeClick(BaseTest.java:85)
at com.demo.tests.DemoTest.test(DemoTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
Caused by: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.name: search-flight-date-picker--depart
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: &apos;3.11.0&apos;, revision: &apos;e59cfb3&apos;, time: &apos;2018-03-11T20:26:55.152Z&apos;
System info: host: &apos;DELL&apos;, ip: &apos;192.168.56.1&apos;, os.name: &apos;Windows 8.1&apos;, os.arch: &apos;amd64&apos;, os.version: &apos;6.3&apos;, java.version: &apos;1.8.0_121&apos;
Driver info: driver.version: unknown
at org.openqa.selenium.support.ui.ExpectedConditions.lambda$findElement$0(ExpectedConditions.java:896)
at java.util.Optional.orElseThrow(Unknown Source)
at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:895)
at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:44)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:206)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:202)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:248)
... 27 more
</pre></div></td>
<td>44</td>
<td></td>
<td>24</td>
<td>com.demo.tests.DemoTest@66d1af89</td></tr>
</table><p>
</body>
Expand Down
51 changes: 2 additions & 49 deletions DemoApp/test-output/Default suite/Default test.xml
Original file line number Diff line number Diff line change
@@ -1,52 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by org.testng.reporters.JUnitXMLReporter -->
<testsuite hostname="Dell" ignored="0" name="Default test" tests="1" failures="1" timestamp="06 May 2018 11:07:13 GMT" time="67.293" errors="0">
<testcase name="test" time="44.541" classname="com.demo.tests.DemoTest">
<failure type="org.openqa.selenium.TimeoutException" message="Expected condition failed: waiting for visibility of element located by By.name: search-flight-date-picker--depart (tried for 30 second(s) with 500 milliseconds interval)">
<![CDATA[org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.name: search-flight-date-picker--depart (tried for 30 second(s) with 500 milliseconds interval)
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:81)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:271)
at com.demo.tests.BaseTest.safeClick(BaseTest.java:85)
at com.demo.tests.DemoTest.test(DemoTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
Caused by: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.name: search-flight-date-picker--depart
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'DELL', ip: '192.168.56.1', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_121'
Driver info: driver.version: unknown
at org.openqa.selenium.support.ui.ExpectedConditions.lambda$findElement$0(ExpectedConditions.java:896)
at java.util.Optional.orElseThrow(Unknown Source)
at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:895)
at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:44)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:206)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:202)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:248)
... 27 more
]]>
</failure>
</testcase> <!-- test -->
<testsuite hostname="Dell" ignored="0" name="Default test" tests="1" failures="0" timestamp="06 May 2018 13:24:54 GMT" time="46.792" errors="0">
<testcase name="test" time="24.588" classname="com.demo.tests.DemoTest"/>
</testsuite> <!-- Default test -->
Loading