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;
|
karemo
|
1185
|
21
|
import org.openqa.selenium.WebDriver.Options;
|
karemo
|
1174
|
22
|
import org.openqa.selenium.firefox.FirefoxBinary;
|
|
23
|
import org.openqa.selenium.firefox.FirefoxLauncher;
|
|
24
|
import org.openqa.selenium.firefox.internal.ProfilesIni;
|
|
25
|
|
|
26
|
|
|
27
|
|
|
28
|
|
|
29
|
public class Browser {
|
|
30
|
private static final String FIREFOX_PROFILE_NAME = "WebDriver";
|
karemo
|
1175
|
31
|
|
|
32
|
public void open() {
|
karemo
|
1174
|
33
|
initFirefoxProfile();
|
|
34
|
}
|
|
35
|
|
|
36
|
public void close() {
|
|
37
|
WebDriver webDriver = WebDriverHolder.get();
|
karemo
|
1185
|
38
|
Options options = webDriver.manage();
|
|
39
|
if (options != null) {
|
|
40
|
options.deleteAllCookies();
|
|
41
|
}
|
karemo
|
1174
|
42
|
webDriver.quit();
|
|
43
|
}
|
|
44
|
|
|
45
|
private void initFirefoxProfile() {
|
|
46
|
FirefoxBinary binary = new FirefoxBinary();
|
|
47
|
FirefoxLauncher launcher = new FirefoxLauncher(binary);
|
|
48
|
ProfilesIni profiles = new ProfilesIni();
|
|
49
|
if (profiles.getProfile(FIREFOX_PROFILE_NAME) == null) {
|
|
50
|
try {
|
|
51
|
launcher.createBaseWebDriverProfile(FIREFOX_PROFILE_NAME);
|
|
52
|
} catch (IOException e) {
|
|
53
|
throw new RuntimeException(e);
|
|
54
|
}
|
|
55
|
}
|
|
56
|
}
|
|
57
|
}
|