karemo
|
1174
|
1
|
|
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
package jdave.webdriver;
|
|
17
|
|
|
18
|
import java.io.IOException;
|
|
19
|
|
|
20
|
import org.openqa.selenium.WebDriver;
|
|
21
|
import org.openqa.selenium.firefox.FirefoxBinary;
|
|
22
|
import org.openqa.selenium.firefox.FirefoxLauncher;
|
|
23
|
import org.openqa.selenium.firefox.internal.ProfilesIni;
|
|
24
|
|
|
25
|
|
|
26
|
|
|
27
|
|
|
28
|
public class Browser {
|
|
29
|
private static final String FIREFOX_PROFILE_NAME = "WebDriver";
|
karemo
|
1175
|
30
|
|
|
31
|
public void open() {
|
karemo
|
1174
|
32
|
initFirefoxProfile();
|
|
33
|
}
|
|
34
|
|
|
35
|
public void close() {
|
|
36
|
WebDriver webDriver = WebDriverHolder.get();
|
|
37
|
webDriver.manage().deleteAllCookies();
|
|
38
|
webDriver.quit();
|
|
39
|
}
|
|
40
|
|
|
41
|
private void initFirefoxProfile() {
|
|
42
|
FirefoxBinary binary = new FirefoxBinary();
|
|
43
|
FirefoxLauncher launcher = new FirefoxLauncher(binary);
|
|
44
|
ProfilesIni profiles = new ProfilesIni();
|
|
45
|
if (profiles.getProfile(FIREFOX_PROFILE_NAME) == null) {
|
|
46
|
try {
|
|
47
|
launcher.createBaseWebDriverProfile(FIREFOX_PROFILE_NAME);
|
|
48
|
} catch (IOException e) {
|
|
49
|
throw new RuntimeException(e);
|
|
50
|
}
|
|
51
|
}
|
|
52
|
}
|
|
53
|
}
|