Skip to content

Commit

Permalink
[py] Update WPEWebKit support code (SeleniumHQ#13278)
Browse files Browse the repository at this point in the history
* [py] Fix WPEWebKit python support code

- Naming conventions, as WPEWebKit does not follow the Simple
  capitalized name scheme
- (TODO): Driver location finding

* [py] Update WPEWebKit capabilities forwarding

- Remove non-standard default capabilities, like in 497cde3
- Add legacy desired_capabilities to new style Options, like in 9f5801c

* [py] Update WPEWebKit service parameter

- To match parent Service class

Amend into Update WPEWebKit service parameter

* [py] WPEWebKit options: avoid re-initializing self._caps

* [py] Align wpewebkit.WebDriver constructor signature

Receiving a Service instance instead of service details spread out
  • Loading branch information
lauromoura authored Jan 21, 2024
1 parent 892bf7a commit 24d88d7
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion py/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ py_test_suite(
]),
args = [
"--instafail",
"--driver=WPEWebKit",
"--driver=wpewebkit",
"--browser-binary=MiniBrowser",
"--browser-args=--automation --headless",
],
Expand Down
3 changes: 2 additions & 1 deletion py/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ def fin():
options = get_options(driver_class, request.config)
if driver_class == "Edge":
options = get_options(driver_class, request.config)
if driver_class == "WPEWebKit":
if driver_class.lower() == "wpewebkit":
driver_class = "WPEWebKit"
options = get_options(driver_class, request.config)
if driver_path is not None:
kwargs["service"] = get_service(driver_class, driver_path)
Expand Down
4 changes: 0 additions & 4 deletions py/selenium/webdriver/common/desired_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,8 @@ class DesiredCapabilities:

WEBKITGTK = {
"browserName": "MiniBrowser",
"version": "",
"platform": "ANY",
}

WPEWEBKIT = {
"browserName": "MiniBrowser",
"version": "",
"platform": "ANY",
}
6 changes: 5 additions & 1 deletion py/selenium/webdriver/wpewebkit/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import typing

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.options import ArgOptions
Expand All @@ -25,7 +26,6 @@ class Options(ArgOptions):
def __init__(self) -> None:
super().__init__()
self._binary_location = ""
self._caps = DesiredCapabilities.WPEWEBKIT.copy()

@property
def binary_location(self) -> str:
Expand Down Expand Up @@ -58,3 +58,7 @@ def to_capabilities(self):
caps[Options.KEY] = browser_options

return caps

@property
def default_capabilities(self) -> typing.Dict[str, str]:
return DesiredCapabilities.WPEWEBKIT.copy()
12 changes: 6 additions & 6 deletions py/selenium/webdriver/wpewebkit/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,39 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import shutil
import typing

from selenium.webdriver.common import service

DEFAULT_EXECUTABLE_PATH = "WPEWebDriver"
DEFAULT_EXECUTABLE_PATH = shutil.which("WPEWebDriver")


class Service(service.Service):
"""A Service class that is responsible for the starting and stopping of
`WPEWebDriver`.
:param executable_path: install path of the WPEWebDriver executable, defaults to `WPEWebDriver`.
:param executable_path: install path of the WPEWebDriver executable, defaults to the first `WPEWebDriver` in `$PATH`.
:param port: Port for the service to run on, defaults to 0 where the operating system will decide.
:param service_args: (Optional) List of args to be passed to the subprocess when launching the executable.
:param log_path: (Optional) File path for the file to be opened and passed as the subprocess stdout/stderr handler.
:param log_output: (Optional) File path for the file to be opened and passed as the subprocess stdout/stderr handler.
:param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.
"""

def __init__(
self,
executable_path: str = DEFAULT_EXECUTABLE_PATH,
port: int = 0,
log_path: typing.Optional[str] = None,
log_output: typing.Optional[str] = None,
service_args: typing.Optional[typing.List[str]] = None,
env: typing.Optional[typing.Mapping[str, str]] = None,
**kwargs,
):
self.service_args = service_args or []
log_file = open(log_path, "wb") if log_path else None
super().__init__(
executable_path=executable_path,
port=port,
log_file=log_file,
log_output=log_output,
env=env,
**kwargs,
) # type: ignore
Expand Down
24 changes: 6 additions & 18 deletions py/selenium/webdriver/wpewebkit/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@

import http.client as http_client

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.driver_finder import DriverFinder
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver

from .options import Options
from .service import DEFAULT_EXECUTABLE_PATH
from .service import Service


Expand All @@ -31,35 +29,25 @@ class WebDriver(RemoteWebDriver):

def __init__(
self,
executable_path=DEFAULT_EXECUTABLE_PATH,
port=0,
options=None,
desired_capabilities=DesiredCapabilities.WPEWEBKIT,
service_log_path=None,
service: Service = None,
):
"""Creates a new instance of the WPEWebKit driver.
Starts the service and then creates new instance of WPEWebKit Driver.
:Args:
- executable_path : path to the executable. If the default is used it assumes the executable is in the $PATH.
- port : port you would like the service to run, if left as 0, a free port will be found.
- options : an instance of WPEWebKitOptions
- desired_capabilities : Dictionary object with desired capabilities
- service_log_path : Path to write service stdout and stderr output.
- options : an instance of ``WPEWebKitOptions``
- service : Service object for handling the browser driver if you need to pass extra details
"""
if options:
capabilities = options.to_capabilities()
capabilities.update(desired_capabilities)
desired_capabilities = capabilities
else:
if not options:
options = Options()

self.service = Service(executable_path, port=port, log_path=service_log_path)
self.service = service if service else Service()
self.service.path = DriverFinder.get_path(self.service, options)
self.service.start()

super().__init__(command_executor=self.service.service_url, desired_capabilities=desired_capabilities)
super().__init__(command_executor=self.service.service_url, options=options)
self._is_remote = False

def quit(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import pytest

from selenium.webdriver.common.options import PageLoadStrategy
from selenium.webdriver.wpewebkit.options import Options


Expand All @@ -25,6 +26,14 @@ def options():
return Options()


def test_starts_with_default_capabilities(options):
from selenium.webdriver import DesiredCapabilities

caps = DesiredCapabilities.WPEWEBKIT.copy()
caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
assert options._caps == caps


def test_set_binary_location(options):
options.binary_location = "/foo/bar"
assert options._binary_location == "/foo/bar"
Expand Down

0 comments on commit 24d88d7

Please sign in to comment.