Skip to content

Commit a9d37d0

Browse files
author
Machinexa2
authored
[py] Cache platform calls when starting the session(#8953)
1 parent 53280c7 commit a9d37d0

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

py/selenium/webdriver/firefox/firefox_binary.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
import os
20-
import platform
20+
from platform import system
2121
from subprocess import Popen, STDOUT
2222
from selenium.common.exceptions import WebDriverException
2323
from selenium.webdriver.common import utils
@@ -43,7 +43,7 @@ def __init__(self, firefox_path=None, log_file=None):
4343
# a while the pipe would fill up and Firefox would freeze.
4444
self._log_file = log_file or open(os.devnull, "wb")
4545
self.command_line = None
46-
if self._start_cmd is None:
46+
if not self._start_cmd:
4747
self._start_cmd = self._get_firefox_start_cmd()
4848
if not self._start_cmd.strip():
4949
raise WebDriverException(
@@ -59,6 +59,7 @@ def __init__(self, firefox_path=None, log_file=None):
5959
self._firefox_env["MOZ_CRASHREPORTER_DISABLE"] = "1"
6060
self._firefox_env["MOZ_NO_REMOTE"] = "1"
6161
self._firefox_env["NO_EM_RESTART"] = "1"
62+
self.platform = system().lower()
6263

6364
def add_command_line_options(self, *args):
6465
self.command_line = args
@@ -84,10 +85,10 @@ def kill(self):
8485
def _start_from_profile_path(self, path):
8586
self._firefox_env["XRE_PROFILE_PATH"] = path
8687

87-
if platform.system().lower() == 'linux':
88+
if platform == 'linux':
8889
self._modify_link_library_path()
8990
command = [self._start_cmd, "-foreground"]
90-
if self.command_line is not None:
91+
if self.command_line:
9192
for cli in self.command_line:
9293
command.append(cli)
9394
self.process = Popen(
@@ -98,7 +99,7 @@ def _wait_until_connectable(self, timeout=30):
9899
"""Blocks until the extension is connectable in the firefox."""
99100
count = 0
100101
while not utils.is_connectable(self.profile.port):
101-
if self.process.poll() is not None:
102+
if self.process.poll():
102103
# Browser has exited
103104
raise WebDriverException(
104105
"The browser appears to have exited "
@@ -148,19 +149,19 @@ def _find_exe_in_registry(self):
148149
def _get_firefox_start_cmd(self):
149150
"""Return the command to start firefox."""
150151
start_cmd = ""
151-
if platform.system() == "Darwin":
152+
if self.platform == "darwin": #small darwin due to lower() in self.platform
152153
start_cmd = "/Applications/Firefox.app/Contents/MacOS/firefox-bin"
153154
# fallback to homebrew installation for mac users
154155
if not os.path.exists(start_cmd):
155156
start_cmd = os.path.expanduser("~") + start_cmd
156-
elif platform.system() == "Windows":
157+
elif self.platform == "windows": #same
157158
start_cmd = (self._find_exe_in_registry() or self._default_windows_location())
158-
elif platform.system() == 'Java' and os._name == 'nt':
159+
elif self.platform == 'java' and os._name == 'nt':
159160
start_cmd = self._default_windows_location()
160161
else:
161162
for ffname in ["firefox", "iceweasel"]:
162163
start_cmd = self.which(ffname)
163-
if start_cmd is not None:
164+
if start_cmd:
164165
break
165166
else:
166167
# couldn't find firefox on the system path

0 commit comments

Comments
 (0)