-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathJUnitedWeb.java
More file actions
94 lines (71 loc) · 3.33 KB
/
JUnitedWeb.java
File metadata and controls
94 lines (71 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.InputStream;
import java.util.concurrent.TimeUnit;
import junit.framework.Assert;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import com.perfectomobile.httpclient.MediaType;
import com.perfectomobile.httpclient.utils.FileUtils;
import com.perfectomobile.selenium.MobileDriver;
import com.perfectomobile.selenium.api.IMobileDevice;
import com.perfectomobile.selenium.api.IMobileDriver;
public class JUnitedWeb {
static MobileDriver driver;
//Before the test, I create Perfecto Mobile driver in order to connect the the cloud.
//The driver Paramaters are cloud_name, user and Password
// to create your account please visit http://www.perfectomobile.com/
@BeforeClass
public static void testSetup() {
String host = Constants.PM_CLOUD;
String user = Constants.PM_USER;
String password = Constants.PM_PASSWORD;
driver = new MobileDriver(host, user, password);
}
@AfterClass
// After the test I close the driver and get the Perfecto Mobile report into the local machine
public static void testCleanup() {
driver.quit();
InputStream reportStream = ((IMobileDriver) driver).downloadReport(MediaType.HTML);
if (reportStream != null) {
File reportFile = new File(Constants.REPORT_LIB+"JUnitTest.HTML");
FileUtils.write(reportStream, reportFile);
}
}
// The test work on the specific device ID
// This testcase go to united.com , look for specific flight and validate we go
@Test
public void CheckFlight() {
// IMobileDevice device = ((IMobileDriver) driver).getDevice("4DF1F4C107319F79");
IMobileDevice device = ((IMobileDriver) driver).getDevice("3230D2D238BECF6D");
// Getting the device form Perfecto mobile system, open it and take it to the ready mode (HOME)
device.open();
device.home();
// Define two types of web driver
// 1. DOM - standard web webdriver works with the DOM objects
// 2. Visual Driver - allows to validate that text appear on the screen using visual analysis (OCR).
// This validation is very important and simulate the real user experience.
WebDriver webDriver = device.getDOMDriver ("www.united.com");
WebDriver visualDriver = device.getVisualDriver();
webDriver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
webDriver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
// press on the button "flight status"
WebElement webElement = webDriver.findElement(By.xpath("(//#text)[53]"));
webElement.click();
// press on the button "flight number"
webElement = webDriver.findElement(By.xpath("(//@id=\"FlightNumber\")[1]"));
webElement.sendKeys("84");
// press on the button "Search"
webDriver.findElement(By.xpath("(//INPUT)[5]")).click();
// visual based validation - validate the text appear on the screen and can be seen by users.
visualDriver.manage().timeouts().implicitlyWait(25,TimeUnit.SECONDS);
visualDriver.findElement(By.linkText("New York/Newark"));
// object based validation - validate the text appear in the as part of the DOM structure
String text = webDriver.findElement(By.xpath("(//#text)[177]")).getAttribute("text");
assertEquals("New York/Newark, NJ (EWR)",text);
}
}