|
| 1 | +// Licensed to the Software Freedom Conservancy (SFC) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The SFC licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.openqa.selenium.opera; |
| 19 | + |
| 20 | +import org.openqa.selenium.Capabilities; |
| 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; |
| 29 | +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; |
| 33 | + |
| 34 | +import java.io.File; |
| 35 | + |
| 36 | +/** |
| 37 | + * A {@link WebDriver} implementation that controls a Blink-based Opera browser running on the local |
| 38 | + * machine. It requires an <code>operadriver</code> executable to be available in PATH. |
| 39 | + * |
| 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 | + */ |
| 62 | +@Deprecated |
| 63 | +public class OperaDriver extends RemoteWebDriver |
| 64 | + implements LocationContext, WebStorage { |
| 65 | + |
| 66 | + private RemoteLocationContext locationContext; |
| 67 | + private RemoteWebStorage webStorage; |
| 68 | + |
| 69 | + /** |
| 70 | + * Creates a new OperaDriver using the {@link OperaDriverService#createDefaultService default} |
| 71 | + * server configuration. |
| 72 | + * |
| 73 | + * @see #OperaDriver(OperaDriverService, OperaOptions) |
| 74 | + */ |
| 75 | + 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()); |
| 88 | + } |
| 89 | + |
| 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 | + 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); |
| 122 | + } |
| 123 | + |
| 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()); |
| 137 | + } |
| 138 | + |
| 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"); |
| 144 | + } |
| 145 | + |
| 146 | + @Override |
| 147 | + public LocalStorage getLocalStorage() { |
| 148 | + return webStorage.getLocalStorage(); |
| 149 | + } |
| 150 | + |
| 151 | + @Override |
| 152 | + public SessionStorage getSessionStorage() { |
| 153 | + return webStorage.getSessionStorage(); |
| 154 | + } |
| 155 | + |
| 156 | + @Override |
| 157 | + public Location location() { |
| 158 | + return locationContext.location(); |
| 159 | + } |
| 160 | + |
| 161 | + @Override |
| 162 | + public void setLocation(Location location) { |
| 163 | + locationContext.setLocation(location); |
| 164 | + } |
| 165 | +} |
0 commit comments