Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
57 changes: 57 additions & 0 deletions java/src/org/openqa/selenium/opera/AddHasCasting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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.remote.AdditionalHttpCommands;
import org.openqa.selenium.remote.AugmenterProvider;
import org.openqa.selenium.remote.CommandInfo;
import org.openqa.selenium.remote.http.HttpMethod;

import java.util.Map;
import java.util.function.Predicate;

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

@SuppressWarnings({"rawtypes", "RedundantSuppression"})
@AutoService({AdditionalHttpCommands.class, AugmenterProvider.class})
public class AddHasCasting extends org.openqa.selenium.chromium.AddHasCasting {

private static final Map<String, CommandInfo> COMMANDS =
Map.of(
GET_CAST_SINKS, new CommandInfo("session/:sessionId/ms/cast/get_sinks", HttpMethod.GET),
SET_CAST_SINK_TO_USE,
new CommandInfo("session/:sessionId/ms/cast/set_sink_to_use", HttpMethod.POST),
START_CAST_TAB_MIRRORING,
new CommandInfo("session/:sessionId/ms/cast/start_tab_mirroring", HttpMethod.POST),
GET_CAST_ISSUE_MESSAGE,
new CommandInfo("session/:sessionId/ms/cast/get_issue_message", HttpMethod.GET),
STOP_CASTING,
new CommandInfo("session/:sessionId/ms/cast/stop_casting", HttpMethod.POST));

@Override
public Map<String, CommandInfo> getAdditionalCommands() {
return COMMANDS;
}

@Override
public Predicate<Capabilities> isApplicable() {
return OPERA::is;
}
}
48 changes: 48 additions & 0 deletions java/src/org/openqa/selenium/opera/AddHasCdp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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.remote.AdditionalHttpCommands;
import org.openqa.selenium.remote.AugmenterProvider;
import org.openqa.selenium.remote.CommandInfo;
import org.openqa.selenium.remote.http.HttpMethod;

import java.util.Map;
import java.util.function.Predicate;

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

@SuppressWarnings({"rawtypes", "RedundantSuppression"})
@AutoService({AdditionalHttpCommands.class, AugmenterProvider.class})
public class AddHasCdp extends org.openqa.selenium.chromium.AddHasCdp {

private static final Map<String, CommandInfo> COMMANDS =
Map.of(EXECUTE_CDP, new CommandInfo("session/:sessionId/ms/cdp/execute", HttpMethod.POST));

@Override
public Map<String, CommandInfo> getAdditionalCommands() {
return COMMANDS;
}

@Override
public Predicate<Capabilities> isApplicable() {
return OPERA::is;
}
}
25 changes: 25 additions & 0 deletions java/src/org/openqa/selenium/opera/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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",
tags = [
"release-artifact",
],
visibility = [
"//visibility:public",
],
exports = [
"//java/src/org/openqa/selenium/chromium",
],
deps = [
"//java:auto-service",
"//java/src/org/openqa/selenium:core",
"//java/src/org/openqa/selenium/chromium",
"//java/src/org/openqa/selenium/manager",
"//java/src/org/openqa/selenium/remote",
],
)
97 changes: 97 additions & 0 deletions java/src/org/openqa/selenium/opera/OperaDriver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// 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.Beta;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chromium.ChromiumDriver;
import org.openqa.selenium.chromium.ChromiumDriverCommandExecutor;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.CommandInfo;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.RemoteWebDriverBuilder;
import org.openqa.selenium.remote.http.ClientConfig;
import org.openqa.selenium.remote.service.DriverFinder;
import org.openqa.selenium.remote.service.DriverService;

import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* A {@link WebDriver} implementation that controls a Chromium-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>
*/
public class OperaDriver extends ChromiumDriver {

public OperaDriver() {
this(new OperaOptions());
}

public OperaDriver(OperaOptions options) {
this(new OperaDriverService.Builder().build(), options);
}

public OperaDriver(OperaDriverService service) {
this(service, new OperaOptions());
}

public OperaDriver(OperaDriverService service, OperaOptions options) {
this(service, options, ClientConfig.defaultConfig());
}

public OperaDriver(OperaDriverService service, OperaOptions options, ClientConfig clientConfig) {
super(generateExecutor(service, options, clientConfig), options, OperaOptions.CAPABILITY);
casting = new AddHasCasting().getImplementation(getCapabilities(), getExecuteMethod());
cdp = new AddHasCdp().getImplementation(getCapabilities(), getExecuteMethod());
}

private static OperaDriver.OperaDriverCommandExecutor generateExecutor(
OperaDriverService service, OperaOptions options, ClientConfig clientConfig) {
Require.nonNull("Driver service", service);
Require.nonNull("Driver options", options);
Require.nonNull("Driver clientConfig", clientConfig);
DriverFinder finder = new DriverFinder(service, options);
service.setExecutable(finder.getDriverPath());
if (finder.hasBrowserPath()) {
options.setBinary(finder.getBrowserPath());
options.setCapability("browserVersion", (Object) null);
}
return new OperaDriver.OperaDriverCommandExecutor(service, clientConfig);
}

@Beta
public static RemoteWebDriverBuilder builder() {
return RemoteWebDriver.builder().oneOf(new OperaOptions());
}

private static class OperaDriverCommandExecutor extends ChromiumDriverCommandExecutor {
public OperaDriverCommandExecutor(DriverService service, ClientConfig clientConfig) {
super(service, getExtraCommands(), clientConfig);
}

private static Map<String, CommandInfo> getExtraCommands() {
return Stream.of(
new AddHasCasting().getAdditionalCommands(), new AddHasCdp().getAdditionalCommands())
.flatMap((m) -> m.entrySet().stream())
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue));
}
}
}
84 changes: 84 additions & 0 deletions java/src/org/openqa/selenium/opera/OperaDriverInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// 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.WebDriverInfo;
import org.openqa.selenium.chromium.ChromiumDriverInfo;
import org.openqa.selenium.remote.service.DriverFinder;

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 extends ChromiumDriverInfo {

@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 true;
}

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

@Override
public boolean isAvailable() {
return new DriverFinder(OperaDriverService.createDefaultService(), getCanonicalCapabilities())
.isAvailable();
}

@Override
public boolean isPresent() {
return new DriverFinder(OperaDriverService.createDefaultService(), getCanonicalCapabilities())
.isPresent();
}

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

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