Skip to content

Commit

Permalink
Revert "[java] Remove Opera related classes (#10950)"
Browse files Browse the repository at this point in the history
This reverts commit 9955c13.
  • Loading branch information
sbabcoc committed Jan 25, 2025
1 parent 77796f4 commit 5983db3
Show file tree
Hide file tree
Showing 13 changed files with 850 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ task tests: [
'//java/test/org/openqa/selenium/ie:ie',
'//java/test/org/openqa/selenium/chrome:chrome',
'//java/test/org/openqa/selenium/edge:edge',
'//java/test/org/openqa/selenium/opera:opera',
'//java/test/org/openqa/selenium/support:small-tests',
'//java/test/org/openqa/selenium/support:large-tests',
'//java/test/org/openqa/selenium/remote:small-tests',
Expand Down Expand Up @@ -184,6 +185,7 @@ task test_ie: [
]
task test_jobbie: [:test_ie]
task test_firefox: ['//java/test/org/openqa/selenium/firefox:marionette:run']
task test_opera: ['//java/test/org/openqa/selenium/opera:opera:run']
task test_remote_server: [
'//java/test/org/openqa/selenium/remote/server:small-tests:run',
'//java/test/org/openqa/selenium/remote/server/log:test:run'
Expand All @@ -208,6 +210,8 @@ task :test_java_webdriver do
Rake::Task['test_chrome'].invoke
elsif SeleniumRake::Checks.edge?
Rake::Task['test_edge'].invoke
elsif SeleniumRake::Checks.opera?
Rake::Task['test_opera'].invoke
else
Rake::Task['test_htmlunit'].invoke
Rake::Task['test_firefox'].invoke
Expand Down
1 change: 1 addition & 0 deletions java/src/org/openqa/selenium/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ java_export(
"//java/src/org/openqa/selenium/edge",
"//java/src/org/openqa/selenium/firefox",
"//java/src/org/openqa/selenium/ie",
"//java/src/org/openqa/selenium/opera",
"//java/src/org/openqa/selenium/remote",
"//java/src/org/openqa/selenium/safari",
"//java/src/org/openqa/selenium/support",
Expand Down
1 change: 1 addition & 0 deletions java/src/org/openqa/selenium/grid/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ java_export(
"//java/src/org/openqa/selenium/grid/sessionmap/httpd",
"//java/src/org/openqa/selenium/grid/sessionqueue/httpd",
"//java/src/org/openqa/selenium/ie",
"//java/src/org/openqa/selenium/opera",
"//java/src/org/openqa/selenium/remote",
"//java/src/org/openqa/selenium/safari",
"//javascript/grid-ui:react_jar",
Expand Down
15 changes: 15 additions & 0 deletions java/src/org/openqa/selenium/opera/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("//java:defs.bzl", "java_export")
load("//java:version.bzl", "SE_VERSION")

java_export(
name = "opera",
srcs = glob(["*.java"]),
maven_coordinates = "org.seleniumhq.selenium:selenium-opera-driver:%s" % SE_VERSION,
pom_template = "//java/src/org/openqa/selenium:template-pom",
visibility = ["//visibility:public"],
deps = [
"//java:auto-service",
"//java/src/org/openqa/selenium:core",
"//java/src/org/openqa/selenium/remote",
],
)
165 changes: 165 additions & 0 deletions java/src/org/openqa/selenium/opera/OperaDriver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.opera;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.html5.LocalStorage;
import org.openqa.selenium.html5.Location;
import org.openqa.selenium.html5.LocationContext;
import org.openqa.selenium.html5.SessionStorage;
import org.openqa.selenium.html5.WebStorage;
import org.openqa.selenium.remote.FileDetector;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.html5.RemoteLocationContext;
import org.openqa.selenium.remote.html5.RemoteWebStorage;
import org.openqa.selenium.remote.service.DriverCommandExecutor;

import java.io.File;

/**
* A {@link WebDriver} implementation that controls a Blink-based Opera browser running on the local
* machine. It requires an <code>operadriver</code> executable to be available in PATH.
*
* @see <a href="https://github.com/operasoftware/operachromiumdriver">operadriver</a>
*
* Since operadriver does not support w3c, Selenium will remove the support in the next version.
* @deprecated Use {@link org.openqa.selenium.chrome.ChromeDriver} with
* {@link org.openqa.selenium.chrome.ChromeOptions#setBinary(File)} or {@link org.openqa.selenium.chrome.ChromeOptions#setBinary(String)}
* to set the path to the Opera browser.
*
* <p>Example usage:
* <pre><code>
* ChromeOptions options = new ChromeOptions()
* options.setBinary(new File("/path/to/opera"));
*
* // For using Opera browser with ChromeDriver:
* ChromeDriver driver = new ChromeDriver(options);
*
* // For use with RemoteWebDriver:
* ChromeOptions options = new ChromeOptions();
* options.setBinary(new File("/path/to/opera"));
* RemoteWebDriver driver = new RemoteWebDriver(
* new URL("http://localhost:4444/"), options);
* </code></pre>
*/
@Deprecated
public class OperaDriver extends RemoteWebDriver
implements LocationContext, WebStorage {

private RemoteLocationContext locationContext;
private RemoteWebStorage webStorage;

/**
* Creates a new OperaDriver using the {@link OperaDriverService#createDefaultService default}
* server configuration.
*
* @see #OperaDriver(OperaDriverService, OperaOptions)
*/
public OperaDriver() {
this(OperaDriverService.createDefaultService(), new OperaOptions());
}

/**
* Creates a new OperaDriver instance. The {@code service} will be started along with the driver,
* and shutdown upon calling {@link #quit()}.
*
* @param service The service to use.
* @see #OperaDriver(OperaDriverService, OperaOptions)
*/
public OperaDriver(OperaDriverService service) {
this(service, new OperaOptions());
}

/**
* Creates a new OperaDriver instance. The {@code capabilities} will be passed to the
* chromedriver service.
*
* @param capabilities The capabilities required from the OperaDriver.
* @see #OperaDriver(OperaDriverService, Capabilities)
* @deprecated Use {@link #OperaDriver(OperaOptions)} instead.
*/
@Deprecated
public OperaDriver(Capabilities capabilities) {
this(OperaDriverService.createDefaultService(), capabilities);
}

/**
* Creates a new OperaDriver instance with the specified options.
*
* @param options The options to use.
* @see #OperaDriver(OperaDriverService, OperaOptions)
*/
public OperaDriver(OperaOptions options) {
this(OperaDriverService.createDefaultService(), options);
}

/**
* Creates a new OperaDriver instance with the specified options. The {@code service} will be
* started along with the driver, and shutdown upon calling {@link #quit()}.
*
* @param service The service to use.
* @param options The options to use.
*/
public OperaDriver(OperaDriverService service, OperaOptions options) {
this(service, (Capabilities) options);
}

/**
* Creates a new OperaDriver instance. The {@code service} will be started along with the
* driver, and shutdown upon calling {@link #quit()}.
*
* @param service The service to use.
* @param capabilities The capabilities required from the OperaDriver.
* @deprecated Use {@link #OperaDriver(OperaDriverService, OperaOptions)} instead.
*/
@Deprecated
public OperaDriver(OperaDriverService service, Capabilities capabilities) {
super(new DriverCommandExecutor(service), capabilities);
locationContext = new RemoteLocationContext(getExecuteMethod());
webStorage = new RemoteWebStorage(getExecuteMethod());
}

@Override
public void setFileDetector(FileDetector detector) {
throw new WebDriverException(
"Setting the file detector only works on remote webdriver instances obtained " +
"via RemoteWebDriver");
}

@Override
public LocalStorage getLocalStorage() {
return webStorage.getLocalStorage();
}

@Override
public SessionStorage getSessionStorage() {
return webStorage.getSessionStorage();
}

@Override
public Location location() {
return locationContext.location();
}

@Override
public void setLocation(Location location) {
locationContext.setLocation(location);
}
}
81 changes: 81 additions & 0 deletions java/src/org/openqa/selenium/opera/OperaDriverInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.opera;

import com.google.auto.service.AutoService;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.SessionNotCreatedException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebDriverInfo;

import java.util.Optional;

import static org.openqa.selenium.remote.Browser.OPERA;
import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;

@AutoService(WebDriverInfo.class)
public class OperaDriverInfo implements WebDriverInfo {

@Override
public String getDisplayName() {
return "Opera";
}

@Override
public Capabilities getCanonicalCapabilities() {
return new ImmutableCapabilities(BROWSER_NAME, OPERA.browserName());
}

@Override
public boolean isSupporting(Capabilities capabilities) {
return OPERA.is(capabilities.getBrowserName());
}

@Override
public boolean isSupportingCdp() {
return false;
}

@Override
public boolean isAvailable() {
try {
OperaDriverService.createDefaultService();
return true;
} catch (IllegalStateException | WebDriverException e) {
return false;
}
}

@Override
public int getMaximumSimultaneousSessions() {
return Runtime.getRuntime().availableProcessors();
}

@Override
public Optional<WebDriver> createDriver(Capabilities capabilities)
throws SessionNotCreatedException {
if (!isAvailable()) {
return Optional.empty();
}

return Optional.of(new OperaDriver(capabilities));
}
}
Loading

0 comments on commit 5983db3

Please sign in to comment.