Skip to content

Commit

Permalink
Add quiet option to Safari Python binding
Browse files Browse the repository at this point in the history
This makes Popen send all output from the Selenium JAR to os.devnull.

Signed-off-by: Andreas Tolfsen <[email protected]>
  • Loading branch information
charlesthomas authored and andreastt committed Oct 18, 2014
1 parent aa113ee commit ec062ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions py/selenium/webdriver/safari/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from os import devnull
import subprocess
from subprocess import PIPE
import time
Expand All @@ -25,7 +26,7 @@ class Service(object):
Object that manages the starting and stopping of the SafariDriver
"""

def __init__(self, executable_path, port=0):
def __init__(self, executable_path, port=0, quiet=False):
"""
Creates a new instance of the Service
Expand All @@ -37,6 +38,7 @@ def __init__(self, executable_path, port=0):
self.path = executable_path
if self.port == 0:
self.port = utils.free_port()
self.quiet = quiet

def start(self):
"""
Expand All @@ -46,8 +48,14 @@ def start(self):
- WebDriverException : Raised either when it can't start the service
or when it can't connect to the service
"""
kwargs = dict()
if self.quiet:
devnull_out = open(devnull, 'w')
kwargs.update(stdout=devnull_out,
stderr=devnull_out)
try:
self.process = subprocess.Popen(["java", "-jar", self.path, "-port", "%s" % self.port])
self.process = subprocess.Popen(["java", "-jar", self.path, "-port", "%s" % self.port],
**kwargs)
except:
raise WebDriverException(
"SafariDriver executable needs to be available in the path.")
Expand Down
4 changes: 2 additions & 2 deletions py/selenium/webdriver/safari/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class WebDriver(RemoteWebDriver):
"""

def __init__(self, executable_path=None, port=0,
desired_capabilities=DesiredCapabilities.SAFARI):
desired_capabilities=DesiredCapabilities.SAFARI, quiet=False):
"""
Creates a new instance of the Safari driver.
Expand All @@ -51,7 +51,7 @@ def __init__(self, executable_path=None, port=0,
except:
raise Exception("No executable path given, please add one to Environment Variable \
'SELENIUM_SERVER_JAR'")
self.service = Service(executable_path, port=port)
self.service = Service(executable_path, port=port, quiet=quiet)
self.service.start()

RemoteWebDriver.__init__(self,
Expand Down

0 comments on commit ec062ba

Please sign in to comment.