Skip to content

Commit 24d88d7

Browse files
authored
[py] Update WPEWebKit support code (#13278)
* [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
1 parent 892bf7a commit 24d88d7

File tree

7 files changed

+29
-31
lines changed

7 files changed

+29
-31
lines changed

py/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ py_test_suite(
561561
]),
562562
args = [
563563
"--instafail",
564-
"--driver=WPEWebKit",
564+
"--driver=wpewebkit",
565565
"--browser-binary=MiniBrowser",
566566
"--browser-args=--automation --headless",
567567
],

py/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ def fin():
148148
options = get_options(driver_class, request.config)
149149
if driver_class == "Edge":
150150
options = get_options(driver_class, request.config)
151-
if driver_class == "WPEWebKit":
151+
if driver_class.lower() == "wpewebkit":
152+
driver_class = "WPEWebKit"
152153
options = get_options(driver_class, request.config)
153154
if driver_path is not None:
154155
kwargs["service"] = get_service(driver_class, driver_path)

py/selenium/webdriver/common/desired_capabilities.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,8 @@ class DesiredCapabilities:
9393

9494
WEBKITGTK = {
9595
"browserName": "MiniBrowser",
96-
"version": "",
97-
"platform": "ANY",
9896
}
9997

10098
WPEWEBKIT = {
10199
"browserName": "MiniBrowser",
102-
"version": "",
103-
"platform": "ANY",
104100
}

py/selenium/webdriver/wpewebkit/options.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
import typing
1718

1819
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
1920
from selenium.webdriver.common.options import ArgOptions
@@ -25,7 +26,6 @@ class Options(ArgOptions):
2526
def __init__(self) -> None:
2627
super().__init__()
2728
self._binary_location = ""
28-
self._caps = DesiredCapabilities.WPEWEBKIT.copy()
2929

3030
@property
3131
def binary_location(self) -> str:
@@ -58,3 +58,7 @@ def to_capabilities(self):
5858
caps[Options.KEY] = browser_options
5959

6060
return caps
61+
62+
@property
63+
def default_capabilities(self) -> typing.Dict[str, str]:
64+
return DesiredCapabilities.WPEWEBKIT.copy()

py/selenium/webdriver/wpewebkit/service.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,39 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
import shutil
1718
import typing
1819

1920
from selenium.webdriver.common import service
2021

21-
DEFAULT_EXECUTABLE_PATH = "WPEWebDriver"
22+
DEFAULT_EXECUTABLE_PATH = shutil.which("WPEWebDriver")
2223

2324

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

3536
def __init__(
3637
self,
3738
executable_path: str = DEFAULT_EXECUTABLE_PATH,
3839
port: int = 0,
39-
log_path: typing.Optional[str] = None,
40+
log_output: typing.Optional[str] = None,
4041
service_args: typing.Optional[typing.List[str]] = None,
4142
env: typing.Optional[typing.Mapping[str, str]] = None,
4243
**kwargs,
4344
):
4445
self.service_args = service_args or []
45-
log_file = open(log_path, "wb") if log_path else None
4646
super().__init__(
4747
executable_path=executable_path,
4848
port=port,
49-
log_file=log_file,
49+
log_output=log_output,
5050
env=env,
5151
**kwargs,
5252
) # type: ignore

py/selenium/webdriver/wpewebkit/webdriver.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717

1818
import http.client as http_client
1919

20-
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
2120
from selenium.webdriver.common.driver_finder import DriverFinder
2221
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
2322

2423
from .options import Options
25-
from .service import DEFAULT_EXECUTABLE_PATH
2624
from .service import Service
2725

2826

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

3230
def __init__(
3331
self,
34-
executable_path=DEFAULT_EXECUTABLE_PATH,
35-
port=0,
3632
options=None,
37-
desired_capabilities=DesiredCapabilities.WPEWEBKIT,
38-
service_log_path=None,
33+
service: Service = None,
3934
):
4035
"""Creates a new instance of the WPEWebKit driver.
4136
4237
Starts the service and then creates new instance of WPEWebKit Driver.
4338
4439
:Args:
45-
- executable_path : path to the executable. If the default is used it assumes the executable is in the $PATH.
46-
- port : port you would like the service to run, if left as 0, a free port will be found.
47-
- options : an instance of WPEWebKitOptions
48-
- desired_capabilities : Dictionary object with desired capabilities
49-
- service_log_path : Path to write service stdout and stderr output.
40+
- options : an instance of ``WPEWebKitOptions``
41+
- service : Service object for handling the browser driver if you need to pass extra details
5042
"""
51-
if options:
52-
capabilities = options.to_capabilities()
53-
capabilities.update(desired_capabilities)
54-
desired_capabilities = capabilities
55-
else:
43+
if not options:
5644
options = Options()
5745

58-
self.service = Service(executable_path, port=port, log_path=service_log_path)
46+
self.service = service if service else Service()
5947
self.service.path = DriverFinder.get_path(self.service, options)
6048
self.service.start()
6149

62-
super().__init__(command_executor=self.service.service_url, desired_capabilities=desired_capabilities)
50+
super().__init__(command_executor=self.service.service_url, options=options)
6351
self._is_remote = False
6452

6553
def quit(self):

py/test/unit/selenium/webdriver/wpewebkit/wpewebkit_options_tests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import pytest
1919

20+
from selenium.webdriver.common.options import PageLoadStrategy
2021
from selenium.webdriver.wpewebkit.options import Options
2122

2223

@@ -25,6 +26,14 @@ def options():
2526
return Options()
2627

2728

29+
def test_starts_with_default_capabilities(options):
30+
from selenium.webdriver import DesiredCapabilities
31+
32+
caps = DesiredCapabilities.WPEWEBKIT.copy()
33+
caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
34+
assert options._caps == caps
35+
36+
2837
def test_set_binary_location(options):
2938
options.binary_location = "/foo/bar"
3039
assert options._binary_location == "/foo/bar"

0 commit comments

Comments
 (0)