Skip to content

Commit 6970082

Browse files
committed
Add YAML option for parsing capabilities
1 parent 2036a7b commit 6970082

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

seleniumbase/core/capabilities_parser.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22
import ast
33
import json
4+
import yaml # Requires pyyaml
45

56

67
def _analyze_ast(contents):
@@ -183,28 +184,33 @@ def _read_file(file):
183184
def _parse_py_file(cap_file):
184185
all_code = _read_file(cap_file)
185186
capabilities = _analyze_ast(all_code)
186-
187187
if not capabilities:
188188
capabilities = _analyze_manual(all_code)
189-
190189
return capabilities
191190

192191

193192
def _parse_json_file(cap_file):
194193
all_code = _read_file(cap_file)
195-
196194
return json.loads(all_code)
197195

198196

197+
def _parse_yaml_file(cap_file):
198+
all_code = _read_file(cap_file)
199+
return yaml.safe_load(all_code)
200+
201+
199202
def get_desired_capabilities(cap_file):
200203
if cap_file.endswith(".py"):
201204
capabilities = _parse_py_file(cap_file)
202205
elif cap_file.endswith(".json"):
203206
capabilities = _parse_json_file(cap_file)
207+
elif (cap_file.endswith(".yml") or cap_file.endswith(".yaml")):
208+
capabilities = _parse_yaml_file(cap_file)
204209
else:
205-
raise Exception("\n\n`%s` is not a Python or JSON file!\n" % cap_file)
206-
210+
raise Exception(
211+
'\n\n`%s` must end in ".py", ".json", ".yml", or ".yaml"!\n'
212+
% cap_file
213+
)
207214
if len(capabilities.keys()) == 0:
208215
raise Exception("Unable to parse desired capabilities file!")
209-
210216
return capabilities

0 commit comments

Comments
 (0)