Skip to content

Commit 7dbd3a3

Browse files
committed
[py]: start of bringing firefox.service inline with other services
1 parent f442a7e commit 7dbd3a3

File tree

1 file changed

+19
-34
lines changed

1 file changed

+19
-34
lines changed

py/selenium/webdriver/firefox/service.py

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +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-
17+
import typing
1818
from typing import List
1919

2020
from selenium.webdriver.common import service
@@ -24,50 +24,35 @@
2424

2525

2626
class Service(service.Service):
27-
"""Object that manages the starting and stopping of the
28-
GeckoDriver."""
27+
"""A Service class that is responsible for the starting and stopping
28+
of `geckodriver`.
29+
30+
:param executable_path: install path of the geckodriver executable, defaults to `geckodriver`.
31+
:param port: Port for the service to run on, defaults to 0 where the operating system will decide.
32+
:param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable.
33+
:param log_path: (Optional) File path for the file to be opened and passed as the subprocess stdout/stderr handler,
34+
defaults to `geckodriver.log`.
35+
:param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.
36+
"""
2937

3038
def __init__(
3139
self,
3240
executable_path: str = DEFAULT_EXECUTABLE_PATH,
3341
port: int = 0,
34-
service_args: List[str] = None,
35-
log_path: str = "geckodriver.log",
36-
env: dict = None,
42+
service_args: typing.Optional[typing.List[str]] = None,
43+
log_path: typing.Optional[str] = None,
44+
env: typing.Optional[typing.Mapping[str, str]] = None,
3745
):
38-
"""Creates a new instance of the GeckoDriver remote service proxy.
39-
40-
GeckoDriver provides a HTTP interface speaking the W3C WebDriver
41-
protocol to Marionette.
42-
43-
:param executable_path: Path to the GeckoDriver binary.
44-
:param port: Run the remote service on a specified port.
45-
Defaults to 0, which binds to a random open port of the
46-
system's choosing.
47-
:param service_args: Optional list of arguments to pass to the
48-
GeckoDriver binary.
49-
:param log_path: Optional path for the GeckoDriver to log to.
50-
Defaults to _geckodriver.log_ in the current working directory.
51-
:param env: Optional dictionary of output variables to expose
52-
in the services' environment.
53-
54-
"""
55-
log_file = open(log_path, "a+", encoding="utf-8") if log_path else None
56-
57-
super().__init__(executable_path, port=port, log_file=log_file, env=env)
46+
# Todo: This is vastly inconsistent, requires a follow up to standardise.
47+
file = log_path or "geckodriver.log"
48+
log_file = open(file, "a+", encoding="utf-8")
5849
self.service_args = service_args or []
50+
super().__init__(executable_path, port=port, log_file=log_file, env=env)
5951

6052
# Set a port for CDP
6153
if "--connect-existing" not in self.service_args:
6254
self.service_args.append("--websocket-port")
6355
self.service_args.append(f"{utils.free_port()}")
6456

65-
# Set the webdriver port
66-
self.service_args.append("--port")
67-
self.service_args.append(f"{self.port}")
68-
6957
def command_line_args(self) -> List[str]:
70-
return self.service_args
71-
72-
def send_remote_shutdown_command(self):
73-
pass
58+
return ["--port", f"{self.port}"] + self.service_args

0 commit comments

Comments
 (0)