Skip to content

Commit 85b465e

Browse files
committed
Revert "[java] Remove Opera related classes (#10950)"
This reverts commit 9955c13.
1 parent 445ba70 commit 85b465e

File tree

13 files changed

+850
-0
lines changed

13 files changed

+850
-0
lines changed

Rakefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ task tests: [
135135
'//java/test/org/openqa/selenium/ie:ie',
136136
'//java/test/org/openqa/selenium/chrome:chrome',
137137
'//java/test/org/openqa/selenium/edge:edge',
138+
'//java/test/org/openqa/selenium/opera:opera',
138139
'//java/test/org/openqa/selenium/support:small-tests',
139140
'//java/test/org/openqa/selenium/support:large-tests',
140141
'//java/test/org/openqa/selenium/remote:small-tests',
@@ -184,6 +185,7 @@ task test_ie: [
184185
]
185186
task test_jobbie: [:test_ie]
186187
task test_firefox: ['//java/test/org/openqa/selenium/firefox:marionette:run']
188+
task test_opera: ['//java/test/org/openqa/selenium/opera:opera:run']
187189
task test_remote_server: [
188190
'//java/test/org/openqa/selenium/remote/server:small-tests:run',
189191
'//java/test/org/openqa/selenium/remote/server/log:test:run'
@@ -208,6 +210,8 @@ task :test_java_webdriver do
208210
Rake::Task['test_chrome'].invoke
209211
elsif SeleniumRake::Checks.edge?
210212
Rake::Task['test_edge'].invoke
213+
elsif SeleniumRake::Checks.opera?
214+
Rake::Task['test_opera'].invoke
211215
else
212216
Rake::Task['test_htmlunit'].invoke
213217
Rake::Task['test_firefox'].invoke

java/src/org/openqa/selenium/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ java_export(
5656
"//java/src/org/openqa/selenium/edge",
5757
"//java/src/org/openqa/selenium/firefox",
5858
"//java/src/org/openqa/selenium/ie",
59+
"//java/src/org/openqa/selenium/opera",
5960
"//java/src/org/openqa/selenium/remote",
6061
"//java/src/org/openqa/selenium/safari",
6162
"//java/src/org/openqa/selenium/support",

java/src/org/openqa/selenium/grid/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ java_export(
160160
"//java/src/org/openqa/selenium/grid/sessionmap/httpd",
161161
"//java/src/org/openqa/selenium/grid/sessionqueue/httpd",
162162
"//java/src/org/openqa/selenium/ie",
163+
"//java/src/org/openqa/selenium/opera",
163164
"//java/src/org/openqa/selenium/remote",
164165
"//java/src/org/openqa/selenium/safari",
165166
"//javascript/grid-ui:react_jar",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load("//java:defs.bzl", "java_export")
2+
load("//java:version.bzl", "SE_VERSION")
3+
4+
java_export(
5+
name = "opera",
6+
srcs = glob(["*.java"]),
7+
maven_coordinates = "org.seleniumhq.selenium:selenium-opera-driver:%s" % SE_VERSION,
8+
pom_template = "//java/src/org/openqa/selenium:template-pom",
9+
visibility = ["//visibility:public"],
10+
deps = [
11+
"//java:auto-service",
12+
"//java/src/org/openqa/selenium:core",
13+
"//java/src/org/openqa/selenium/remote",
14+
],
15+
)
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 com.google.auto.service.AutoService;
21+
22+
import org.openqa.selenium.Capabilities;
23+
import org.openqa.selenium.ImmutableCapabilities;
24+
import org.openqa.selenium.SessionNotCreatedException;
25+
import org.openqa.selenium.WebDriver;
26+
import org.openqa.selenium.WebDriverException;
27+
import org.openqa.selenium.WebDriverInfo;
28+
29+
import java.util.Optional;
30+
31+
import static org.openqa.selenium.remote.Browser.OPERA;
32+
import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;
33+
34+
@AutoService(WebDriverInfo.class)
35+
public class OperaDriverInfo implements WebDriverInfo {
36+
37+
@Override
38+
public String getDisplayName() {
39+
return "Opera";
40+
}
41+
42+
@Override
43+
public Capabilities getCanonicalCapabilities() {
44+
return new ImmutableCapabilities(BROWSER_NAME, OPERA.browserName());
45+
}
46+
47+
@Override
48+
public boolean isSupporting(Capabilities capabilities) {
49+
return OPERA.is(capabilities.getBrowserName());
50+
}
51+
52+
@Override
53+
public boolean isSupportingCdp() {
54+
return false;
55+
}
56+
57+
@Override
58+
public boolean isAvailable() {
59+
try {
60+
OperaDriverService.createDefaultService();
61+
return true;
62+
} catch (IllegalStateException | WebDriverException e) {
63+
return false;
64+
}
65+
}
66+
67+
@Override
68+
public int getMaximumSimultaneousSessions() {
69+
return Runtime.getRuntime().availableProcessors();
70+
}
71+
72+
@Override
73+
public Optional<WebDriver> createDriver(Capabilities capabilities)
74+
throws SessionNotCreatedException {
75+
if (!isAvailable()) {
76+
return Optional.empty();
77+
}
78+
79+
return Optional.of(new OperaDriver(capabilities));
80+
}
81+
}

0 commit comments

Comments
 (0)