|
17 | 17 |
|
18 | 18 | package org.openqa.selenium.opera; |
19 | 19 |
|
20 | | -import org.openqa.selenium.Capabilities; |
| 20 | +import org.openqa.selenium.Beta; |
21 | 21 | import org.openqa.selenium.WebDriver; |
22 | | -import org.openqa.selenium.WebDriverException; |
23 | | -import org.openqa.selenium.html5.LocalStorage; |
24 | | -import org.openqa.selenium.html5.Location; |
25 | | -import org.openqa.selenium.html5.LocationContext; |
26 | | -import org.openqa.selenium.html5.SessionStorage; |
27 | | -import org.openqa.selenium.html5.WebStorage; |
28 | | -import org.openqa.selenium.remote.FileDetector; |
| 22 | +import org.openqa.selenium.chromium.ChromiumDriver; |
| 23 | +import org.openqa.selenium.chromium.ChromiumDriverCommandExecutor; |
| 24 | +import org.openqa.selenium.internal.Require; |
| 25 | +import org.openqa.selenium.remote.CommandInfo; |
29 | 26 | import org.openqa.selenium.remote.RemoteWebDriver; |
30 | | -import org.openqa.selenium.remote.html5.RemoteLocationContext; |
31 | | -import org.openqa.selenium.remote.html5.RemoteWebStorage; |
32 | | -import org.openqa.selenium.remote.service.DriverCommandExecutor; |
| 27 | +import org.openqa.selenium.remote.RemoteWebDriverBuilder; |
| 28 | +import org.openqa.selenium.remote.http.ClientConfig; |
| 29 | +import org.openqa.selenium.remote.service.DriverFinder; |
| 30 | +import org.openqa.selenium.remote.service.DriverService; |
33 | 31 |
|
34 | | -import java.io.File; |
| 32 | +import java.util.Map; |
| 33 | +import java.util.stream.Collectors; |
| 34 | +import java.util.stream.Stream; |
35 | 35 |
|
36 | 36 | /** |
37 | | - * A {@link WebDriver} implementation that controls a Blink-based Opera browser running on the local |
| 37 | + * A {@link WebDriver} implementation that controls a Chromium-based Opera browser running on the local |
38 | 38 | * machine. It requires an <code>operadriver</code> executable to be available in PATH. |
39 | 39 | * |
40 | 40 | * @see <a href="https://github.com/operasoftware/operachromiumdriver">operadriver</a> |
41 | | - * |
42 | | - * Since operadriver does not support w3c, Selenium will remove the support in the next version. |
43 | | - * @deprecated Use {@link org.openqa.selenium.chrome.ChromeDriver} with |
44 | | - * {@link org.openqa.selenium.chrome.ChromeOptions#setBinary(File)} or {@link org.openqa.selenium.chrome.ChromeOptions#setBinary(String)} |
45 | | - * to set the path to the Opera browser. |
46 | | - * |
47 | | - * <p>Example usage: |
48 | | - * <pre><code> |
49 | | - * ChromeOptions options = new ChromeOptions() |
50 | | - * options.setBinary(new File("/path/to/opera")); |
51 | | - * |
52 | | - * // For using Opera browser with ChromeDriver: |
53 | | - * ChromeDriver driver = new ChromeDriver(options); |
54 | | - * |
55 | | - * // For use with RemoteWebDriver: |
56 | | - * ChromeOptions options = new ChromeOptions(); |
57 | | - * options.setBinary(new File("/path/to/opera")); |
58 | | - * RemoteWebDriver driver = new RemoteWebDriver( |
59 | | - * new URL("http://localhost:4444/"), options); |
60 | | - * </code></pre> |
61 | 41 | */ |
62 | | -@Deprecated |
63 | | -public class OperaDriver extends RemoteWebDriver |
64 | | - implements LocationContext, WebStorage { |
65 | | - |
66 | | - private RemoteLocationContext locationContext; |
67 | | - private RemoteWebStorage webStorage; |
| 42 | +public class OperaDriver extends ChromiumDriver { |
68 | 43 |
|
69 | | - /** |
70 | | - * Creates a new OperaDriver using the {@link OperaDriverService#createDefaultService default} |
71 | | - * server configuration. |
72 | | - * |
73 | | - * @see #OperaDriver(OperaDriverService, OperaOptions) |
74 | | - */ |
75 | 44 | public OperaDriver() { |
76 | | - this(OperaDriverService.createDefaultService(), new OperaOptions()); |
77 | | - } |
78 | | - |
79 | | - /** |
80 | | - * Creates a new OperaDriver instance. The {@code service} will be started along with the driver, |
81 | | - * and shutdown upon calling {@link #quit()}. |
82 | | - * |
83 | | - * @param service The service to use. |
84 | | - * @see #OperaDriver(OperaDriverService, OperaOptions) |
85 | | - */ |
86 | | - public OperaDriver(OperaDriverService service) { |
87 | | - this(service, new OperaOptions()); |
| 45 | + this(new OperaOptions()); |
88 | 46 | } |
89 | 47 |
|
90 | | - /** |
91 | | - * Creates a new OperaDriver instance. The {@code capabilities} will be passed to the |
92 | | - * chromedriver service. |
93 | | - * |
94 | | - * @param capabilities The capabilities required from the OperaDriver. |
95 | | - * @see #OperaDriver(OperaDriverService, Capabilities) |
96 | | - * @deprecated Use {@link #OperaDriver(OperaOptions)} instead. |
97 | | - */ |
98 | | - @Deprecated |
99 | | - public OperaDriver(Capabilities capabilities) { |
100 | | - this(OperaDriverService.createDefaultService(), capabilities); |
101 | | - } |
102 | | - |
103 | | - /** |
104 | | - * Creates a new OperaDriver instance with the specified options. |
105 | | - * |
106 | | - * @param options The options to use. |
107 | | - * @see #OperaDriver(OperaDriverService, OperaOptions) |
108 | | - */ |
109 | 48 | public OperaDriver(OperaOptions options) { |
110 | | - this(OperaDriverService.createDefaultService(), options); |
111 | | - } |
112 | | - |
113 | | - /** |
114 | | - * Creates a new OperaDriver instance with the specified options. The {@code service} will be |
115 | | - * started along with the driver, and shutdown upon calling {@link #quit()}. |
116 | | - * |
117 | | - * @param service The service to use. |
118 | | - * @param options The options to use. |
119 | | - */ |
120 | | - public OperaDriver(OperaDriverService service, OperaOptions options) { |
121 | | - this(service, (Capabilities) options); |
| 49 | + this(new OperaDriverService.Builder().build(), options); |
122 | 50 | } |
123 | 51 |
|
124 | | - /** |
125 | | - * Creates a new OperaDriver instance. The {@code service} will be started along with the |
126 | | - * driver, and shutdown upon calling {@link #quit()}. |
127 | | - * |
128 | | - * @param service The service to use. |
129 | | - * @param capabilities The capabilities required from the OperaDriver. |
130 | | - * @deprecated Use {@link #OperaDriver(OperaDriverService, OperaOptions)} instead. |
131 | | - */ |
132 | | - @Deprecated |
133 | | - public OperaDriver(OperaDriverService service, Capabilities capabilities) { |
134 | | - super(new DriverCommandExecutor(service), capabilities); |
135 | | - locationContext = new RemoteLocationContext(getExecuteMethod()); |
136 | | - webStorage = new RemoteWebStorage(getExecuteMethod()); |
| 52 | + public OperaDriver(OperaDriverService service) { |
| 53 | + this(service, new OperaOptions()); |
137 | 54 | } |
138 | 55 |
|
139 | | - @Override |
140 | | - public void setFileDetector(FileDetector detector) { |
141 | | - throw new WebDriverException( |
142 | | - "Setting the file detector only works on remote webdriver instances obtained " + |
143 | | - "via RemoteWebDriver"); |
| 56 | + public OperaDriver(OperaDriverService service, OperaOptions options) { |
| 57 | + this(service, options, ClientConfig.defaultConfig()); |
144 | 58 | } |
145 | 59 |
|
146 | | - @Override |
147 | | - public LocalStorage getLocalStorage() { |
148 | | - return webStorage.getLocalStorage(); |
| 60 | + public OperaDriver(OperaDriverService service, OperaOptions options, ClientConfig clientConfig) { |
| 61 | + super(generateExecutor(service, options, clientConfig), options, OperaOptions.CAPABILITY); |
| 62 | + casting = new AddHasCasting().getImplementation(getCapabilities(), getExecuteMethod()); |
| 63 | + cdp = new AddHasCdp().getImplementation(getCapabilities(), getExecuteMethod()); |
149 | 64 | } |
150 | 65 |
|
151 | | - @Override |
152 | | - public SessionStorage getSessionStorage() { |
153 | | - return webStorage.getSessionStorage(); |
| 66 | + private static OperaDriver.OperaDriverCommandExecutor generateExecutor( |
| 67 | + OperaDriverService service, OperaOptions options, ClientConfig clientConfig) { |
| 68 | + Require.nonNull("Driver service", service); |
| 69 | + Require.nonNull("Driver options", options); |
| 70 | + Require.nonNull("Driver clientConfig", clientConfig); |
| 71 | + DriverFinder finder = new DriverFinder(service, options); |
| 72 | + service.setExecutable(finder.getDriverPath()); |
| 73 | + if (finder.hasBrowserPath()) { |
| 74 | + options.setBinary(finder.getBrowserPath()); |
| 75 | + options.setCapability("browserVersion", (Object) null); |
| 76 | + } |
| 77 | + return new OperaDriver.OperaDriverCommandExecutor(service, clientConfig); |
154 | 78 | } |
155 | 79 |
|
156 | | - @Override |
157 | | - public Location location() { |
158 | | - return locationContext.location(); |
| 80 | + @Beta |
| 81 | + public static RemoteWebDriverBuilder builder() { |
| 82 | + return RemoteWebDriver.builder().oneOf(new OperaOptions()); |
159 | 83 | } |
160 | 84 |
|
161 | | - @Override |
162 | | - public void setLocation(Location location) { |
163 | | - locationContext.setLocation(location); |
| 85 | + private static class OperaDriverCommandExecutor extends ChromiumDriverCommandExecutor { |
| 86 | + public OperaDriverCommandExecutor(DriverService service, ClientConfig clientConfig) { |
| 87 | + super(service, getExtraCommands(), clientConfig); |
| 88 | + } |
| 89 | + |
| 90 | + private static Map<String, CommandInfo> getExtraCommands() { |
| 91 | + return Stream.of( |
| 92 | + new AddHasCasting().getAdditionalCommands(), new AddHasCdp().getAdditionalCommands()) |
| 93 | + .flatMap((m) -> m.entrySet().stream()) |
| 94 | + .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue)); |
| 95 | + } |
164 | 96 | } |
165 | 97 | } |
0 commit comments