Skip to content

Commit ec062ba

Browse files
charlesthomasandreastt
authored andcommitted
Add quiet option to Safari Python binding
This makes Popen send all output from the Selenium JAR to os.devnull. Signed-off-by: Andreas Tolfsen <[email protected]>
1 parent aa113ee commit ec062ba

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

py/selenium/webdriver/safari/service.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
17+
from os import devnull
1718
import subprocess
1819
from subprocess import PIPE
1920
import time
@@ -25,7 +26,7 @@ class Service(object):
2526
Object that manages the starting and stopping of the SafariDriver
2627
"""
2728

28-
def __init__(self, executable_path, port=0):
29+
def __init__(self, executable_path, port=0, quiet=False):
2930
"""
3031
Creates a new instance of the Service
3132
@@ -37,6 +38,7 @@ def __init__(self, executable_path, port=0):
3738
self.path = executable_path
3839
if self.port == 0:
3940
self.port = utils.free_port()
41+
self.quiet = quiet
4042

4143
def start(self):
4244
"""
@@ -46,8 +48,14 @@ def start(self):
4648
- WebDriverException : Raised either when it can't start the service
4749
or when it can't connect to the service
4850
"""
51+
kwargs = dict()
52+
if self.quiet:
53+
devnull_out = open(devnull, 'w')
54+
kwargs.update(stdout=devnull_out,
55+
stderr=devnull_out)
4956
try:
50-
self.process = subprocess.Popen(["java", "-jar", self.path, "-port", "%s" % self.port])
57+
self.process = subprocess.Popen(["java", "-jar", self.path, "-port", "%s" % self.port],
58+
**kwargs)
5159
except:
5260
raise WebDriverException(
5361
"SafariDriver executable needs to be available in the path.")

py/selenium/webdriver/safari/webdriver.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class WebDriver(RemoteWebDriver):
3333
"""
3434

3535
def __init__(self, executable_path=None, port=0,
36-
desired_capabilities=DesiredCapabilities.SAFARI):
36+
desired_capabilities=DesiredCapabilities.SAFARI, quiet=False):
3737
"""
3838
Creates a new instance of the Safari driver.
3939
@@ -51,7 +51,7 @@ def __init__(self, executable_path=None, port=0,
5151
except:
5252
raise Exception("No executable path given, please add one to Environment Variable \
5353
'SELENIUM_SERVER_JAR'")
54-
self.service = Service(executable_path, port=port)
54+
self.service = Service(executable_path, port=port, quiet=quiet)
5555
self.service.start()
5656

5757
RemoteWebDriver.__init__(self,

0 commit comments

Comments
 (0)