Java Reference
In-Depth Information
[File 2]
@RunWith(value = Parameterized.class)
public class
UnmanagedAllBrowsersTest {
private static
Map<String, Selenium> SeleniumMap;
B
C
D
@Parameters
public static
Collection getBrowsers() {
return
Arrays.asList(new String[][]{{"*iexplore"}, {"*firefox"}});
}
private static
Selenium getSelenium(String key) {
Selenium s = getSeleniumMap().get(key);
if
(s !=
null
) {
return
s;
}
stopDrivers(); // only let one driver run
s =
new
DefaultSelenium("localhost", 4444, key, "
http://
www.google.com/");
getSeleniumMap().put(key, s);
s.start();
return
s;
}
E
F
private static
Map<String, Selenium> getSeleniumMap() {
if
(SeleniumMap ==
null
) {
SeleniumMap =
new
HashMap<String, Selenium>();
}
return SeleniumMap;
}
@AfterClass
public static void
stopDrivers() {
for
(Selenium s : getSeleniumMap().values()) {
s.stop();
}
SeleniumMap = null;
}
G
private
String browserStartCommand;
private
Selenium selenium;
H
public
UnmanagedAllBrowsersTest(String browserStartCommand) {
this
.browserStartCommand = browserStartCommand;
}
I
@Before
public void
setUp()
throws
Exception {
this
.selenium = getSelenium(
this
.browserStartCommand);
}
@Test
public void
testGoogleSearch() {
this
.selenium.open("/");
SeleneseTestCase.assertEquals("Google", this.selenium.getTitle());
this
.selenium.type("q", "Manning Publishing Co.");
this
.selenium.click("btnG");
this
.selenium.waitForPageToLoad("30000");