14
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
15
# See the License for the specific language governing permissions and
16
16
# limitations under the License.
17
+ from os import devnull
17
18
import subprocess
18
19
from subprocess import PIPE
19
20
import time
@@ -25,7 +26,7 @@ class Service(object):
25
26
Object that manages the starting and stopping of the SafariDriver
26
27
"""
27
28
28
- def __init__ (self , executable_path , port = 0 ):
29
+ def __init__ (self , executable_path , port = 0 , quiet = False ):
29
30
"""
30
31
Creates a new instance of the Service
31
32
@@ -37,6 +38,7 @@ def __init__(self, executable_path, port=0):
37
38
self .path = executable_path
38
39
if self .port == 0 :
39
40
self .port = utils .free_port ()
41
+ self .quiet = quiet
40
42
41
43
def start (self ):
42
44
"""
@@ -46,8 +48,14 @@ def start(self):
46
48
- WebDriverException : Raised either when it can't start the service
47
49
or when it can't connect to the service
48
50
"""
51
+ kwargs = dict ()
52
+ if self .quiet :
53
+ devnull_out = open (devnull , 'w' )
54
+ kwargs .update (stdout = devnull_out ,
55
+ stderr = devnull_out )
49
56
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 )
51
59
except :
52
60
raise WebDriverException (
53
61
"SafariDriver executable needs to be available in the path." )
0 commit comments