14
14
# KIND, either express or implied. See the License for the
15
15
# specific language governing permissions and limitations
16
16
# under the License.
17
+ import json
17
18
import logging
18
19
import subprocess
19
20
import sys
@@ -70,14 +71,20 @@ def driver_location(self, browser: str) -> str:
70
71
if browser == "ie" :
71
72
browser = "iexplorer"
72
73
73
- binary , flag , browser = str (self .get_binary ()), "--browser" , browser
74
- result = self .run ((binary , flag , browser ))
74
+ binary , browser_flag , browser , output_flag , output = (
75
+ str (self .get_binary ()),
76
+ "--browser" ,
77
+ browser ,
78
+ "--output" ,
79
+ "json" ,
80
+ )
81
+ result = self .run ((binary , browser_flag , browser , output_flag , output ))
75
82
executable = result .split ("\t " )[- 1 ].strip ()
76
83
logger .debug (f"Using driver at: { executable } " )
77
84
return executable
78
85
79
86
@staticmethod
80
- def run (args : Tuple [str , str , str ]) -> str :
87
+ def run (args : Tuple [str , str , str , str , str ]) -> str :
81
88
"""
82
89
Executes the Selenium Manager Binary.
83
90
:Args:
@@ -89,8 +96,13 @@ def run(args: Tuple[str, str, str]) -> str:
89
96
completed_proc = subprocess .run (args , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
90
97
stdout = completed_proc .stdout .decode ("utf-8" ).rstrip ("\n " )
91
98
stderr = completed_proc .stderr .decode ("utf-8" ).rstrip ("\n " )
99
+ output = json .loads (stdout )
100
+ result = output ["result" ]["message" ]
92
101
if completed_proc .returncode :
93
- raise SeleniumManagerException (f"Selenium manager failed for: { command } .\n { stdout } { stderr } " )
102
+ raise SeleniumManagerException (f"Selenium manager failed for: { command } .\n { result } { stderr } " )
94
103
else :
95
- # selenium manager exited 0 successfully, parse the executable path from stdout.
96
- return stdout .split ("\t " )[- 1 ].strip ()
104
+ # Selenium Manager exited 0 successfully, return executable path and print warnings (if any)
105
+ for item in output ["logs" ]:
106
+ if item ["level" ] == "WARN" :
107
+ logger .warning (item ["message" ])
108
+ return result
0 commit comments