forked from aimmac23/selenium-video-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExampleSeleniumTests.java
75 lines (55 loc) · 2.19 KB
/
ExampleSeleniumTests.java
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
package com.aimmac23.hub.examples;
import java.net.MalformedURLException;
import java.net.URL;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
/**
* Example Selenium tests for the video grid. A lot of the interesting functionality
* is in {@link AbstractVideoSeleniumTest}
*
* @author Alasdair Macmillan
*
*/
public class ExampleSeleniumTests extends AbstractVideoSeleniumTest {
// change this to point to your own grid hub
private static String HUB_URL = "http://127.0.0.1:4444/wd/hub";
private static String LINK_TEXT = "Selenium - Web Browser Automation";
@Override
protected RemoteWebDriver createWebDriver() {
URL hubUrl;
try {
hubUrl = new URL(HUB_URL);
return new RemoteWebDriver(hubUrl, DesiredCapabilities.firefox());
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Could not construct Hub URL", e);
}
}
@Test
public void successfulTest() throws Exception {
driver.manage().window().maximize();
driver.get("http://www.google.com");
// Google seem to like obscure element IDs
driver.findElementById("gbqfq").sendKeys("selenium");
driver.findElementById("gbqfb").click();
// we need to wait for the search results to appear
new WebDriverWait(driver, 5).until(ExpectedConditions.presenceOfElementLocated(By.linkText(LINK_TEXT)));
driver.findElementByLinkText(LINK_TEXT).click();
// the text so happens to be the same as the window title
assertEquals(LINK_TEXT, driver.getTitle());
}
@Test
public void failingTest() throws Exception {
driver.manage().window().maximize();
driver.get("http://www.google.com");
// Google seem to like obscure element IDs
driver.findElementById("gbqfq").sendKeys("news");
driver.findElementById("gbqfb").click();
// we need to wait for the search results to appear
new WebDriverWait(driver, 5).until(ExpectedConditions.presenceOfElementLocated(By.linkText(LINK_TEXT)));
// BOOM! We will not find the above, unless today's news is quite strange.
}
}