Quick Search:

View

Revision:

Diff

Diff from 1185 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/jdave/branches/1.1.0/jdave-wicket-webdriver/src/java/jdave/webdriver/Browser.java

Annotated File View

karemo
1174
1 /*
2  * Copyright 2008 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
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  * @author Juha Karemo
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 }