17
17
18
18
19
19
import os
20
- import platform
20
+ from platform import system
21
21
from subprocess import Popen , STDOUT
22
22
from selenium .common .exceptions import WebDriverException
23
23
from selenium .webdriver .common import utils
@@ -43,7 +43,7 @@ def __init__(self, firefox_path=None, log_file=None):
43
43
# a while the pipe would fill up and Firefox would freeze.
44
44
self ._log_file = log_file or open (os .devnull , "wb" )
45
45
self .command_line = None
46
- if self ._start_cmd is None :
46
+ if not self ._start_cmd :
47
47
self ._start_cmd = self ._get_firefox_start_cmd ()
48
48
if not self ._start_cmd .strip ():
49
49
raise WebDriverException (
@@ -59,6 +59,7 @@ def __init__(self, firefox_path=None, log_file=None):
59
59
self ._firefox_env ["MOZ_CRASHREPORTER_DISABLE" ] = "1"
60
60
self ._firefox_env ["MOZ_NO_REMOTE" ] = "1"
61
61
self ._firefox_env ["NO_EM_RESTART" ] = "1"
62
+ self .platform = system ().lower ()
62
63
63
64
def add_command_line_options (self , * args ):
64
65
self .command_line = args
@@ -84,10 +85,10 @@ def kill(self):
84
85
def _start_from_profile_path (self , path ):
85
86
self ._firefox_env ["XRE_PROFILE_PATH" ] = path
86
87
87
- if platform . system (). lower () == 'linux' :
88
+ if platform == 'linux' :
88
89
self ._modify_link_library_path ()
89
90
command = [self ._start_cmd , "-foreground" ]
90
- if self .command_line is not None :
91
+ if self .command_line :
91
92
for cli in self .command_line :
92
93
command .append (cli )
93
94
self .process = Popen (
@@ -98,7 +99,7 @@ def _wait_until_connectable(self, timeout=30):
98
99
"""Blocks until the extension is connectable in the firefox."""
99
100
count = 0
100
101
while not utils .is_connectable (self .profile .port ):
101
- if self .process .poll () is not None :
102
+ if self .process .poll ():
102
103
# Browser has exited
103
104
raise WebDriverException (
104
105
"The browser appears to have exited "
@@ -148,19 +149,19 @@ def _find_exe_in_registry(self):
148
149
def _get_firefox_start_cmd (self ):
149
150
"""Return the command to start firefox."""
150
151
start_cmd = ""
151
- if platform . system () == "Darwin" :
152
+ if self . platform == "darwin" : #small darwin due to lower() in self.platform
152
153
start_cmd = "/Applications/Firefox.app/Contents/MacOS/firefox-bin"
153
154
# fallback to homebrew installation for mac users
154
155
if not os .path .exists (start_cmd ):
155
156
start_cmd = os .path .expanduser ("~" ) + start_cmd
156
- elif platform . system () == "Windows" :
157
+ elif self . platform == "windows" : #same
157
158
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' :
159
160
start_cmd = self ._default_windows_location ()
160
161
else :
161
162
for ffname in ["firefox" , "iceweasel" ]:
162
163
start_cmd = self .which (ffname )
163
- if start_cmd is not None :
164
+ if start_cmd :
164
165
break
165
166
else :
166
167
# couldn't find firefox on the system path
0 commit comments